Source
_('Your database is not working properly. Please wait a few minutes and try to repeat this action. If the problem still persists, please contact system administrator. The problem might be caused by long running transaction or row level lock accomplished by your database management system.')
<?php
/*
** 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 Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
class DB {
const SCHEMA_FILE = 'schema.inc.php';
const DBEXECUTE_ERROR = 1;
const RESERVEIDS_ERROR = 2;
const SCHEMA_ERROR = 3;
const INPUT_ERROR = 4;
const INIT_ERROR = 5;
const TABLE_TYPE_CONFIG = 1;
const TABLE_TYPE_HISTORY = 2;
const FIELD_TYPE_INT = 0x0001;
const FIELD_TYPE_CHAR = 0x0002;
const FIELD_TYPE_ID = 0x0004;
const FIELD_TYPE_FLOAT = 0x0008;
const FIELD_TYPE_UINT = 0x0010;
const FIELD_TYPE_BLOB = 0x0020;
const FIELD_TYPE_TEXT = 0x0040;
const FIELD_TYPE_CUID = 0x0080;
const FIELD_TYPE_NCLOB = 0x0100;
const SUPPORTED_FILTER_TYPES = self::FIELD_TYPE_INT | self::FIELD_TYPE_CHAR | self::FIELD_TYPE_ID |
self::FIELD_TYPE_FLOAT | self::FIELD_TYPE_UINT | self::FIELD_TYPE_CUID;
const SUPPORTED_SEARCH_TYPES = self::FIELD_TYPE_CHAR | self::FIELD_TYPE_TEXT | self::FIELD_TYPE_CUID |
self::FIELD_TYPE_NCLOB;
private static $schema = null;
/**
* @var DbBackend
*/
private static $dbBackend;
/**
* Get necessary DB class.
*
* @return DbBackend
*/
public static function getDbBackend() {
global $DB;
if (!self::$dbBackend) {
switch ($DB['TYPE']) {
case ZBX_DB_MYSQL:
self::$dbBackend = new MysqlDbBackend();
break;
case ZBX_DB_POSTGRESQL:
self::$dbBackend = new PostgresqlDbBackend();
break;
case ZBX_DB_ORACLE:
self::$dbBackend = new OracleDbBackend();
break;
}
}
return self::$dbBackend;
}
private static function exception($code, $error) {
throw new DBException($error, $code);
}
/**
* Reserve IDs for primary key of passed table.
* If record for table does not exist or value is out of range, ids record is created using maximum ID from table
* or minimum allowed value.
*
* @param string $table table name
* @param int $count number of IDs to reserve
*
* @throws APIException
*
* @return string