mirror of
https://github.com/vrana/adminer.git
synced 2025-08-07 23:27:17 +02:00
Replace ereg*() by preg_*()
ereg() triggers deprecated error which is sent to custom error handlers. It is also faster. There are no more deprecated functions except mysql_connect().
This commit is contained in:
@@ -7,16 +7,16 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
define("DRIVER", (isset($_GET["sqlite"]) ? "sqlite" : "sqlite2"));
|
||||
if (class_exists(isset($_GET["sqlite"]) ? "SQLite3" : "SQLiteDatabase")) {
|
||||
if (isset($_GET["sqlite"])) {
|
||||
|
||||
|
||||
class Min_SQLite {
|
||||
var $extension = "SQLite3", $server_info, $affected_rows, $errno, $error, $_link;
|
||||
|
||||
|
||||
function Min_SQLite($filename) {
|
||||
$this->_link = new SQLite3($filename);
|
||||
$version = $this->_link->version();
|
||||
$this->server_info = $version["versionString"];
|
||||
}
|
||||
|
||||
|
||||
function query($query) {
|
||||
$result = @$this->_link->query($query);
|
||||
$this->error = "";
|
||||
@@ -30,18 +30,18 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
$this->affected_rows = $this->_link->changes();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function quote($string) {
|
||||
return (is_utf8($string)
|
||||
? "'" . $this->_link->escapeString($string) . "'"
|
||||
: "x'" . reset(unpack('H*', $string)) . "'"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function store_result() {
|
||||
return $this->_result;
|
||||
}
|
||||
|
||||
|
||||
function result($query, $field = 0) {
|
||||
$result = $this->query($query);
|
||||
if (!is_object($result)) {
|
||||
@@ -51,22 +51,22 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
return $row[$field];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Min_Result {
|
||||
var $_result, $_offset = 0, $num_rows;
|
||||
|
||||
|
||||
function Min_Result($result) {
|
||||
$this->_result = $result;
|
||||
}
|
||||
|
||||
|
||||
function fetch_assoc() {
|
||||
return $this->_result->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
|
||||
function fetch_row() {
|
||||
return $this->_result->fetchArray(SQLITE3_NUM);
|
||||
}
|
||||
|
||||
|
||||
function fetch_field() {
|
||||
$column = $this->_offset++;
|
||||
$type = $this->_result->columnType($column);
|
||||
@@ -76,22 +76,22 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
"charsetnr" => ($type == SQLITE3_BLOB ? 63 : 0), // 63 - binary
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function __desctruct() {
|
||||
return $this->_result->finalize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
class Min_SQLite {
|
||||
var $extension = "SQLite", $server_info, $affected_rows, $error, $_link;
|
||||
|
||||
|
||||
function Min_SQLite($filename) {
|
||||
$this->server_info = sqlite_libversion();
|
||||
$this->_link = new SQLiteDatabase($filename);
|
||||
}
|
||||
|
||||
|
||||
function query($query, $unbuffered = false) {
|
||||
$method = ($unbuffered ? "unbufferedQuery" : "query");
|
||||
$result = @$this->_link->$method($query, SQLITE_BOTH, $error);
|
||||
@@ -105,15 +105,15 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
}
|
||||
return new Min_Result($result);
|
||||
}
|
||||
|
||||
|
||||
function quote($string) {
|
||||
return "'" . sqlite_escape_string($string) . "'";
|
||||
}
|
||||
|
||||
|
||||
function store_result() {
|
||||
return $this->_result;
|
||||
}
|
||||
|
||||
|
||||
function result($query, $field = 0) {
|
||||
$result = $this->query($query);
|
||||
if (!is_object($result)) {
|
||||
@@ -123,17 +123,17 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
return $row[$field];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Min_Result {
|
||||
var $_result, $_offset = 0, $num_rows;
|
||||
|
||||
|
||||
function Min_Result($result) {
|
||||
$this->_result = $result;
|
||||
if (method_exists($result, 'numRows')) { // not available in unbuffered query
|
||||
$this->num_rows = $result->numRows();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function fetch_assoc() {
|
||||
$row = $this->_result->fetch(SQLITE_ASSOC);
|
||||
if (!$row) {
|
||||
@@ -145,11 +145,11 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
function fetch_row() {
|
||||
return $this->_result->fetch(SQLITE_NUM);
|
||||
}
|
||||
|
||||
|
||||
function fetch_field() {
|
||||
$name = $this->_result->fieldName($this->_offset++);
|
||||
$pattern = '(\\[.*]|"(?:[^"]|"")*"|(.+))';
|
||||
@@ -163,41 +163,41 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
"orgtable" => $table,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
} elseif (extension_loaded("pdo_sqlite")) {
|
||||
class Min_SQLite extends Min_PDO {
|
||||
var $extension = "PDO_SQLite";
|
||||
|
||||
|
||||
function Min_SQLite($filename) {
|
||||
$this->dsn(DRIVER . ":$filename", "", "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (class_exists("Min_SQLite")) {
|
||||
class Min_DB extends Min_SQLite {
|
||||
|
||||
|
||||
function Min_DB() {
|
||||
$this->Min_SQLite(":memory:");
|
||||
}
|
||||
|
||||
|
||||
function select_db($filename) {
|
||||
if (is_readable($filename) && $this->query("ATTACH " . $this->quote(ereg("(^[/\\\\]|:)", $filename) ? $filename : dirname($_SERVER["SCRIPT_FILENAME"]) . "/$filename") . " AS a")) { // is_readable - SQLite 3
|
||||
if (is_readable($filename) && $this->query("ATTACH " . $this->quote(preg_match("~(^[/\\\\]|:)~", $filename) ? $filename : dirname($_SERVER["SCRIPT_FILENAME"]) . "/$filename") . " AS a")) { // is_readable - SQLite 3
|
||||
$this->Min_SQLite($filename);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function multi_query($query) {
|
||||
return $this->_result = $this->query($query);
|
||||
}
|
||||
|
||||
|
||||
function next_result() {
|
||||
return false;
|
||||
}
|
||||
@@ -207,7 +207,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
|
||||
|
||||
class Min_Driver extends Min_SQL {
|
||||
|
||||
|
||||
function insertUpdate($table, $rows, $primary) {
|
||||
$values = array();
|
||||
foreach ($rows as $set) {
|
||||
@@ -215,7 +215,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
}
|
||||
return queries("REPLACE INTO " . table($table) . " (" . implode(", ", array_keys(reset($rows))) . ") VALUES\n" . implode(",\n", $values));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
function is_view($table_status) {
|
||||
return $table_status["Engine"] == "view";
|
||||
}
|
||||
|
||||
|
||||
function fk_support($table_status) {
|
||||
global $connection;
|
||||
return !$connection->result("SELECT sqlite_compileoption_used('OMIT_FOREIGN_KEY')");
|
||||
@@ -297,11 +297,11 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
$default = $row["dflt_value"];
|
||||
$return[$row["name"]] = array(
|
||||
"field" => $row["name"],
|
||||
"type" => (eregi("int", $type) ? "integer" : (eregi("char|clob|text", $type) ? "text" : (eregi("blob", $type) ? "blob" : (eregi("real|floa|doub", $type) ? "real" : "numeric")))),
|
||||
"type" => (preg_match('~int~i', $type) ? "integer" : (preg_match('~char|clob|text~i', $type) ? "text" : (preg_match('~blob~i', $type) ? "blob" : (preg_match('~real|floa|doub~i', $type) ? "real" : "numeric")))),
|
||||
"full_type" => $type,
|
||||
"default" => (ereg("'(.*)'", $default, $match) ? str_replace("''", "'", $match[1]) : ($default == "NULL" ? null : $default)),
|
||||
"default" => (preg_match("~'(.*)'~", $default, $match) ? str_replace("''", "'", $match[1]) : ($default == "NULL" ? null : $default)),
|
||||
"null" => !$row["notnull"],
|
||||
"auto_increment" => eregi('^integer$', $type) && $row["pk"], //! possible false positive
|
||||
"auto_increment" => preg_match('~^integer$~i', $type) && $row["pk"], //! possible false positive
|
||||
"privileges" => array("select" => 1, "insert" => 1, "update" => 1),
|
||||
"primary" => $row["pk"],
|
||||
);
|
||||
@@ -323,14 +323,14 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
$sqls = get_key_vals("SELECT name, sql FROM sqlite_master WHERE type = 'index' AND tbl_name = " . q($table));
|
||||
foreach (get_rows("PRAGMA index_list(" . table($table) . ")") as $row) {
|
||||
$name = $row["name"];
|
||||
if (!ereg("^sqlite_", $name)) {
|
||||
if (!preg_match("~^sqlite_~", $name)) {
|
||||
$return[$name]["type"] = ($row["unique"] ? "UNIQUE" : "INDEX");
|
||||
$return[$name]["lengths"] = array();
|
||||
foreach (get_rows("PRAGMA index_info(" . idf_escape($name) . ")") as $row1) {
|
||||
$return[$name]["columns"][] = $row1["name"];
|
||||
}
|
||||
$return[$name]["descs"] = array();
|
||||
if (eregi('^CREATE( UNIQUE)? INDEX ' . quotemeta(idf_escape($name) . ' ON ' . idf_escape($table)) . ' \((.*)\)$', $sqls[$name], $regs)) {
|
||||
if (preg_match('~^CREATE( UNIQUE)? INDEX ' . preg_quote(idf_escape($name) . ' ON ' . idf_escape($table), '~') . ' \((.*)\)$~i', $sqls[$name], $regs)) {
|
||||
preg_match_all('/("[^"]*+")+( DESC)?/', $regs[2], $matches);
|
||||
foreach ($matches[2] as $val) {
|
||||
$return[$name]["descs"][] = ($val ? '1' : null);
|
||||
@@ -372,7 +372,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
global $connection;
|
||||
return h($connection->error);
|
||||
}
|
||||
|
||||
|
||||
function check_sqlite_name($name) {
|
||||
// avoid creating PHP files on unsecured servers
|
||||
global $connection;
|
||||
@@ -383,7 +383,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function create_database($db, $collation) {
|
||||
global $connection;
|
||||
if (file_exists($db)) {
|
||||
@@ -399,7 +399,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
$link->query('DROP TABLE adminer');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function drop_databases($databases) {
|
||||
global $connection;
|
||||
$connection->Min_SQLite(":memory:"); // to unlock file, doesn't work in PDO on Windows
|
||||
@@ -411,7 +411,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function rename_database($name, $collation) {
|
||||
global $connection;
|
||||
if (!check_sqlite_name($name)) {
|
||||
@@ -421,11 +421,11 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
$connection->error = lang('File exists.');
|
||||
return @rename(DB, $name);
|
||||
}
|
||||
|
||||
|
||||
function auto_increment() {
|
||||
return " PRIMARY KEY" . (DRIVER == "sqlite" ? " AUTOINCREMENT" : "");
|
||||
}
|
||||
|
||||
|
||||
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
||||
$use_all_fields = ($table == "" || $foreign);
|
||||
foreach ($fields as $field) {
|
||||
@@ -525,7 +525,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function index_sql($table, $type, $name, $columns) {
|
||||
return "CREATE $type " . ($type != "INDEX" ? "INDEX " : "")
|
||||
. idf_escape($name != "" ? $name : uniqid($table . "_"))
|
||||
@@ -533,7 +533,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
. " $columns"
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
function alter_indexes($table, $alter) {
|
||||
foreach (array_reverse($alter) as $val) {
|
||||
if (!queries($val[2] == "DROP"
|
||||
@@ -545,23 +545,23 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function truncate_tables($tables) {
|
||||
return apply_queries("DELETE FROM", $tables);
|
||||
}
|
||||
|
||||
|
||||
function drop_views($views) {
|
||||
return apply_queries("DROP VIEW", $views);
|
||||
}
|
||||
|
||||
|
||||
function drop_tables($tables) {
|
||||
return apply_queries("DROP TABLE", $tables);
|
||||
}
|
||||
|
||||
|
||||
function move_tables($tables, $views, $target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function trigger($name) {
|
||||
global $connection;
|
||||
if ($name == "") {
|
||||
@@ -570,7 +570,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
preg_match('~^CREATE\\s+TRIGGER\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*([a-z]+)\\s+([a-z]+)\\s+ON\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*(?:FOR\\s*EACH\\s*ROW\\s)?(.*)~is', $connection->result("SELECT sql FROM sqlite_master WHERE name = " . q($name)), $match);
|
||||
return array("Timing" => strtoupper($match[1]), "Event" => strtoupper($match[2]), "Trigger" => $name, "Statement" => $match[3]);
|
||||
}
|
||||
|
||||
|
||||
function triggers($table) {
|
||||
$return = array();
|
||||
foreach (get_rows("SELECT * FROM sqlite_master WHERE type = 'trigger' AND tbl_name = " . q($table)) as $row) {
|
||||
@@ -579,58 +579,58 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
function trigger_options() {
|
||||
return array(
|
||||
"Timing" => array("BEFORE", "AFTER", "INSTEAD OF"),
|
||||
"Type" => array("FOR EACH ROW"),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function routine($name, $type) {
|
||||
// not supported by SQLite
|
||||
}
|
||||
|
||||
|
||||
function routines() {
|
||||
// not supported by SQLite
|
||||
}
|
||||
|
||||
|
||||
function routine_languages() {
|
||||
// not supported by SQLite
|
||||
}
|
||||
|
||||
|
||||
function begin() {
|
||||
return queries("BEGIN");
|
||||
}
|
||||
|
||||
|
||||
function last_id() {
|
||||
global $connection;
|
||||
return $connection->result("SELECT LAST_INSERT_ROWID()");
|
||||
}
|
||||
|
||||
|
||||
function explain($connection, $query) {
|
||||
return $connection->query("EXPLAIN $query");
|
||||
}
|
||||
|
||||
|
||||
function found_rows($table_status, $where) {
|
||||
}
|
||||
|
||||
|
||||
function types() {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
function schemas() {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
function get_schema() {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
function set_schema($scheme) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function create_sql($table, $auto_increment) {
|
||||
global $connection;
|
||||
$return = $connection->result("SELECT sql FROM sqlite_master WHERE type IN ('table', 'view') AND name = " . q($table));
|
||||
@@ -642,18 +642,18 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
function truncate_sql($table) {
|
||||
return "DELETE FROM " . table($table);
|
||||
}
|
||||
|
||||
|
||||
function use_sql($database) {
|
||||
}
|
||||
|
||||
|
||||
function trigger_sql($table, $style) {
|
||||
return implode(get_vals("SELECT sql || ';;\n' FROM sqlite_master WHERE type = 'trigger' AND tbl_name = " . q($table)));
|
||||
}
|
||||
|
||||
|
||||
function show_variables() {
|
||||
global $connection;
|
||||
$return = array();
|
||||
@@ -662,7 +662,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
function show_status() {
|
||||
$return = array();
|
||||
foreach (get_vals("PRAGMA compile_options") as $option) {
|
||||
@@ -671,18 +671,18 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
function convert_field($field) {
|
||||
}
|
||||
|
||||
|
||||
function unconvert_field($field, $return) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
function support($feature) {
|
||||
return ereg('^(database|table|sql|indexes|view|trigger|variables|status|dump|move_col|drop_col)$', $feature);
|
||||
return preg_match('~^(database|table|sql|indexes|view|trigger|variables|status|dump|move_col|drop_col)$~', $feature);
|
||||
}
|
||||
|
||||
|
||||
$jush = "sqlite";
|
||||
$types = array("integer" => 0, "real" => 0, "numeric" => 0, "text" => 0, "blob" => 0);
|
||||
$structured_types = array_keys($types);
|
||||
|
Reference in New Issue
Block a user