Source
xxxxxxxxxx
<?php
/*
** Zabbix
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
define('DEFAULT_SRC_FILE', dirname(__FILE__).'/../src/schema.tmpl');
define('DEFAULT_DEST_FILE', dirname(__FILE__).'/../src/schema.inc.php');
function parse_schema($path) {
$schema = [];
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
$str = explode('|', $line, 2);
$part = trim($str[0]);
$rest_line = isset($str[1]) ? $str[1] : '';
switch (trim($part)) {
case 'TABLE':
$str = explode('|', $rest_line);
$table = trim($str[0]);
$key = trim($str[1]);
$schema[$table] = ['key' => $key, 'fields' => []];
break;
case 'FIELD':
$str = explode('|', $rest_line);
$field = trim($str[0]);
$type = trim($str[1]);
$default = trim($str[2]);
$null = trim($str[3]);
$ref_table = isset($str[6]) ? trim($str[6]) : null;
$ref_field = isset($str[7]) ? trim($str[7]) : null;
preg_match('/(?<type>[a-z_]+)(?:\((?<length>[0-9]+)\))?/', $type, $type_data);
switch ($type_data['type']) {
case 't_integer':
case 't_nanosec':
case 't_time':
$type = 'DB::FIELD_TYPE_INT';
$length = 10;
break;
case 't_id':
$type = 'DB::FIELD_TYPE_ID';
$length = 20;
break;
case 't_bigint':