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:
Jakub Vrana 2013-07-24 16:26:41 -07:00
parent 34349f1482
commit e8c6ef04d2
33 changed files with 705 additions and 705 deletions

View file

@ -38,7 +38,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) {
ksort($row["fields"]);
$orig_field = reset($orig_fields);
$after = " FIRST";
foreach ($row["fields"] as $key => $field) {
$foreign_key = $foreign_keys[$field["type"]];
$type_field = ($foreign_key !== null ? $referencable_primary[$foreign_key] : $field); //! can collide with user defined type
@ -58,7 +58,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) {
}
}
if ($foreign_key !== null) {
$foreign[idf_escape($field["field"])] = ($TABLE != "" && $jush != "sqlite" ? "ADD" : " ") . " FOREIGN KEY (" . idf_escape($field["field"]) . ") REFERENCES " . table($foreign_keys[$field["type"]]) . " (" . idf_escape($type_field["field"]) . ")" . (ereg("^($on_actions)\$", $field["on_delete"]) ? " ON DELETE $field[on_delete]" : "");
$foreign[idf_escape($field["field"])] = ($TABLE != "" && $jush != "sqlite" ? "ADD" : " ") . " FOREIGN KEY (" . idf_escape($field["field"]) . ") REFERENCES " . table($foreign_keys[$field["type"]]) . " (" . idf_escape($type_field["field"]) . ")" . (preg_match("~^($on_actions)\$~", $field["on_delete"]) ? " ON DELETE $field[on_delete]" : "");
}
$after = " AFTER " . idf_escape($field["field"]);
} elseif ($field["orig"] != "") {
@ -72,7 +72,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) {
}
}
}
$partitioning = "";
if ($partition_by[$row["partition_by"]]) {
$partitions = array();
@ -86,17 +86,17 @@ if ($_POST && !process_fields($row["fields"]) && !$error) {
? " (" . implode(",", $partitions) . "\n)"
: ($row["partitions"] ? " PARTITIONS " . (+$row["partitions"]) : "")
);
} elseif (support("partitioning") && ereg("partitioned", $table_status["Create_options"])) {
} elseif (support("partitioning") && preg_match("~partitioned~", $table_status["Create_options"])) {
$partitioning .= "\nREMOVE PARTITIONING";
}
$message = lang('Table has been altered.');
if ($TABLE == "") {
cookie("adminer_engine", $row["Engine"]);
$message = lang('Table has been created.');
}
$name = trim($row["name"]);
queries_redirect(ME . (support("table") ? "table=" : "select=") . urlencode($name), $message, alter_table(
$TABLE,
$name,
@ -119,7 +119,7 @@ if (!$_POST) {
"fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")))),
"partition_names" => array(""),
);
if ($TABLE != "") {
$row = $table_status;
$row["name"] = $TABLE;
@ -131,7 +131,7 @@ if (!$_POST) {
$field["has_default"] = isset($field["default"]);
$row["fields"][] = $field;
}
if (support("partitioning")) {
$from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($TABLE);
$result = $connection->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");
@ -161,7 +161,7 @@ foreach ($engines as $engine) {
<?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo h($row["name"]); ?>" autocapitalize="off">
<?php if ($TABLE == "" && !$_POST) { ?><script type='text/javascript'>focus(document.getElementById('form')['name']);</script><?php } ?>
<?php echo ($engines ? "<select name='Engine' onchange='helpClose();'" . on_help("getTarget(event).value", 1) . ">" . optionlist(array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) . "</select>" : ""); ?>
<?php echo ($collations && !ereg("sqlite|mssql", $jush) ? html_select("Collation", array("" => "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?>
<?php echo ($collations && !preg_match("~sqlite|mssql~", $jush) ? html_select("Collation", array("" => "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?>
<input type="submit" value="<?php echo lang('Save'); ?>">
<?php } ?>
@ -196,7 +196,7 @@ edit_fields($row["fields"], $collations, "TABLE", $foreign_keys, $comments);
<?php if ($TABLE != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo confirm(); ?>><?php } ?>
<?php
if (support("partitioning")) {
$partition_table = ereg('RANGE|LIST', $row["partition_by"]);
$partition_table = preg_match('~RANGE|LIST~', $row["partition_by"]);
print_fieldset("partition", lang('Partition by'), $row["partition_by"]);
?>
<p>

View file

@ -31,7 +31,7 @@ if ($_POST && !$error && !isset($_POST["add_x"])) { // add is an image and PHP c
if (!$row["collation"]) {
redirect(substr(ME, 0, -1));
}
query_redirect("ALTER DATABASE " . idf_escape($name) . (eregi('^[a-z0-9_]+$', $row["collation"]) ? " COLLATE $row[collation]" : ""), substr(ME, 0, -1), lang('Database has been altered.'));
query_redirect("ALTER DATABASE " . idf_escape($name) . (preg_match('~^[a-z0-9_]+$~i', $row["collation"]) ? " COLLATE $row[collation]" : ""), substr(ME, 0, -1), lang('Database has been altered.'));
}
}

View file

@ -7,7 +7,7 @@ if ($tables_views && !$error && !$_POST["search"]) {
if ($jush == "sql" && count($_POST["tables"]) > 1 && ($_POST["drop"] || $_POST["truncate"] || $_POST["copy"])) {
queries("SET foreign_key_checks = 0"); // allows to truncate or drop several tables at once
}
if ($_POST["truncate"]) {
if ($_POST["tables"]) {
$result = truncate_tables($_POST["tables"]);
@ -40,7 +40,7 @@ if ($tables_views && !$error && !$_POST["search"]) {
$message .= "<b>" . h($row["Table"]) . "</b>: " . h($row["Msg_text"]) . "<br>";
}
}
queries_redirect(substr(ME, 0, -1), $message, $result);
}
@ -63,7 +63,7 @@ if ($adminer->homepage()) {
}
}
echo "<table cellspacing='0' class='nowrap checkable' onclick='tableClick(event);' ondblclick='tableClick(event, true);'>\n";
echo '<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="formCheck(this, /^(tables|views)\[/);">';
echo '<th>' . lang('Table');
echo '<td>' . lang('Engine');
@ -75,10 +75,10 @@ if ($adminer->homepage()) {
echo '<td>' . lang('Rows');
echo (support("comment") ? '<td>' . lang('Comment') : '');
echo "</thead>\n";
$tables = 0;
foreach ($tables_list as $name => $type) {
$view = ($type !== null && !eregi("table", $type));
$view = ($type !== null && !preg_match('~table~i', $type));
echo '<tr' . odd() . '><td>' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');");
echo '<th>' . (support("table") ? '<a href="' . h(ME) . 'table=' . urlencode($name) . '" title="' . lang('Show structure') . '">' . h($name) . '</a>' : h($name));
if ($view) {
@ -104,14 +104,14 @@ if ($adminer->homepage()) {
}
echo (support("comment") ? "<td id='Comment-" . h($name) . "'>&nbsp;" : "");
}
echo "<tr><td>&nbsp;<th>" . lang('%d in total', count($tables_list));
echo "<td>" . nbsp($jush == "sql" ? $connection->result("SELECT @@storage_engine") : "");
echo "<td>" . nbsp(db_collation(DB, collations()));
foreach (array("Data_length", "Index_length", "Data_free") as $key) {
echo "<td align='right' id='sum-$key'>&nbsp;";
}
echo "</table>\n";
if (!information_schema(DB)) {
$vacuum = "<input type='submit' value='" . lang('Vacuum') . "'" . on_help("'VACUUM'") . "> ";
@ -141,10 +141,10 @@ if ($adminer->homepage()) {
echo "</form>\n";
echo "<script type='text/javascript'>tableCheck();</script>\n";
}
echo '<p class="links"><a href="' . h(ME) . 'create=">' . lang('Create table') . "</a>\n";
echo (support("view") ? '<a href="' . h(ME) . 'view=">' . lang('Create view') . "</a>\n" : "");
if (support("routine")) {
echo "<h3 id='routines'>" . lang('Routines') . "</h3>\n";
$routines = routines();
@ -166,7 +166,7 @@ if ($adminer->homepage()) {
. '<a href="' . h(ME) . 'function=">' . lang('Create function') . "</a>\n"
;
}
if (support("sequence")) {
echo "<h3 id='sequences'>" . lang('Sequences') . "</h3>\n";
$sequences = get_vals("SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = current_schema()");
@ -181,7 +181,7 @@ if ($adminer->homepage()) {
}
echo "<p class='links'><a href='" . h(ME) . "sequence='>" . lang('Create sequence') . "</a>\n";
}
if (support("type")) {
echo "<h3 id='user-types'>" . lang('User types') . "</h3>\n";
$user_types = types();
@ -196,7 +196,7 @@ if ($adminer->homepage()) {
}
echo "<p class='links'><a href='" . h(ME) . "type='>" . lang('Create type') . "</a>\n";
}
if (support("event")) {
echo "<h3 id='events'>" . lang('Events') . "</h3>\n";
$rows = get_rows("SHOW EVENTS");
@ -218,7 +218,7 @@ if ($adminer->homepage()) {
}
echo '<p class="links"><a href="' . h(ME) . 'event=">' . lang('Create event') . "</a>\n";
}
if ($tables_list) {
echo "<script type='text/javascript'>ajaxSetHtml('" . js_escape(ME) . "script=db');</script>\n";
}

View file

@ -4,11 +4,11 @@ $drivers["elastic"] = "Elasticsearch";
if (isset($_GET["elastic"])) {
$possible_drivers = array("json");
define("DRIVER", "elastic");
if (function_exists('json_decode')) {
class Min_DB {
var $extension = "JSON", $server_info, $errno, $error, $_url;
function query($path) {
@ini_set('track_errors', 1); // @ - may be disabled
$file = @file_get_contents($this->_url . ($this->_db != "" ? "$this->_db/" : "") . $path, false, stream_context_create(array('http' => array(
@ -18,7 +18,7 @@ if (isset($_GET["elastic"])) {
$this->error = $php_errormsg;
return $file;
}
if (!eregi('^HTTP/[0-9.]+ 2', $http_response_header[0])) {
if (!preg_match('~^HTTP/[0-9.]+ 2~i', $http_response_header[0])) {
$this->error = $file;
return false;
}
@ -30,7 +30,7 @@ if (isset($_GET["elastic"])) {
} else {
$constants = get_defined_constants(true);
foreach ($constants['json'] as $name => $value) {
if ($value == $this->errno && ereg('^JSON_ERROR_', $name)) {
if ($value == $this->errno && preg_match('~^JSON_ERROR_~', $name)) {
$this->error = $name;
break;
}
@ -39,7 +39,7 @@ if (isset($_GET["elastic"])) {
}
return $return;
}
function connect($server, $username, $password) {
$this->_url = "http://$username:$password@$server/";
$return = $this->query('');
@ -48,51 +48,51 @@ if (isset($_GET["elastic"])) {
}
return (bool) $return;
}
function select_db($database) {
$this->_db = $database;
return true;
}
function quote($string) {
return $string;
}
}
class Min_Result {
var $_rows;
function Min_Result($rows) {
$this->_rows = $rows;
reset($this->_rows);
}
function fetch_assoc() {
$return = current($this->_rows);
next($this->_rows);
return $return;
}
function fetch_row() {
return array_values($this->fetch_assoc());
}
}
}
class Min_Driver extends Min_SQL {
function select($table, $select, $where, $group, $order, $limit, $page) {
global $adminer;
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
if (!$query) {
$query = "$table/_search?default_operator=AND"
. ($select != array("*") ? "&fields=" . urlencode(implode(",", $select)) : "")
. ($order ? "&sort=" . urlencode(ereg_replace(' DESC(,|$)', ':desc\1', implode(",", $order))) : "")
. ($order ? "&sort=" . urlencode(preg_replace('~ DESC(,|$)~', ':desc\1', implode(",", $order))) : "")
. ($limit ? "&size=" . (+$limit) . ($page ? "&from=" . ($page * $limit) : "") : "") // doesn't support returning all results
;
foreach ((array) $_GET["where"] as $val) {
@ -124,11 +124,11 @@ if (isset($_GET["elastic"])) {
}
return new Min_Result($return);
}
}
function connect() {
global $adminer;
$connection = new Min_DB;
@ -138,17 +138,17 @@ if (isset($_GET["elastic"])) {
}
return $connection->error;
}
function support($feature) {
return ereg("database|table", $feature);
return preg_match("~database|table~", $feature);
}
function logged_user() {
global $adminer;
$credentials = $adminer->credentials();
return $credentials[1];
}
function get_databases() {
global $connection;
$return = $connection->query('_aliases');
@ -157,14 +157,14 @@ if (isset($_GET["elastic"])) {
}
return $return;
}
function collations() {
return array();
}
function db_collation($db, $collations) {
}
function count_tables($databases) {
global $connection;
$return = $connection->query('_mapping');
@ -173,7 +173,7 @@ if (isset($_GET["elastic"])) {
}
return $return;
}
function tables_list() {
global $connection;
$return = $connection->query('_mapping');
@ -182,7 +182,7 @@ if (isset($_GET["elastic"])) {
}
return $return;
}
function table_status($name = "", $fast = false) {
$return = tables_list();
if ($return) {
@ -195,24 +195,24 @@ if (isset($_GET["elastic"])) {
}
return $return;
}
function error() {
global $connection;
return h($connection->error);
}
function information_schema() {
}
function is_view($table_status) {
}
function indexes($table, $connection2 = null) {
return array(
array("type" => "PRIMARY", "columns" => array("_id")),
);
}
function fields($table) {
global $connection;
$mapping = $connection->query("$table/_mapping");
@ -229,33 +229,33 @@ if (isset($_GET["elastic"])) {
}
return $return;
}
function foreign_keys($table) {
return array();
}
function table($idf) {
return $idf;
}
function idf_escape($idf) {
return $idf;
}
function convert_field($field) {
}
function unconvert_field($field, $return) {
return $return;
}
function fk_support($table_status) {
}
function found_rows($table_status, $where) {
return null;
}
$jush = "elastic";
$operators = array("=");
$functions = array();

View file

@ -104,7 +104,7 @@ if (isset($_GET["mssql"])) {
}
return $row;
}
function fetch_assoc() {
return $this->_convert(sqlsrv_fetch_array($this->_result, SQLSRV_FETCH_ASSOC, SQLSRV_SCROLL_NEXT));
}
@ -124,7 +124,7 @@ if (isset($_GET["mssql"])) {
$return->type = ($field["Type"] == 1 ? 254 : 0);
return $return;
}
function seek($offset) {
for ($i=0; $i < $offset; $i++) {
sqlsrv_fetch($this->_result); // SQLSRV_SCROLL_ABSOLUTE added in sqlsrv 1.1
@ -135,7 +135,7 @@ if (isset($_GET["mssql"])) {
sqlsrv_free_stmt($this->_result);
}
}
} elseif (extension_loaded("mssql")) {
class Min_DB {
var $extension = "MSSQL", $_link, $_result, $server_info, $affected_rows, $error;
@ -225,18 +225,18 @@ if (isset($_GET["mssql"])) {
function seek($offset) {
mssql_data_seek($this->_result, $offset);
}
function __destruct() {
mssql_free_result($this->_result);
}
}
}
class Min_Driver extends Min_SQL {
function insertUpdate($table, $rows, $primary) {
foreach ($rows as $set) {
$update = array();
@ -257,11 +257,11 @@ if (isset($_GET["mssql"])) {
}
return true;
}
function begin() {
return queries("BEGIN TRANSACTION");
}
}
@ -323,7 +323,7 @@ if (isset($_GET["mssql"])) {
}
return $return;
}
function table_status($name = "") {
$return = array();
foreach (get_rows("SELECT name AS Name, type_desc AS Engine FROM sys.all_objects WHERE schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND type IN ('S', 'U', 'V') " . ($name != "" ? "AND name = " . q($name) : "ORDER BY name")) as $row) {
@ -338,7 +338,7 @@ if (isset($_GET["mssql"])) {
function is_view($table_status) {
return $table_status["Engine"] == "VIEW";
}
function fk_support($table_status) {
return true;
}
@ -353,7 +353,7 @@ LEFT JOIN sys.default_constraints d ON c.default_object_id = d.parent_column_id
WHERE o.schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND o.type IN ('S', 'U', 'V') AND o.name = " . q($table)
) as $row) {
$type = $row["type"];
$length = (ereg("char|binary", $type) ? $row["max_length"] : ($type == "decimal" ? "$row[precision],$row[scale]" : ""));
$length = (preg_match("~char|binary~", $type) ? $row["max_length"] : ($type == "decimal" ? "$row[precision],$row[scale]" : ""));
$return[$row["name"]] = array(
"field" => $row["name"],
"full_type" => $type . ($length ? "($length)" : ""),
@ -392,11 +392,11 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
global $connection;
return array("select" => preg_replace('~^(?:[^[]|\\[[^]]*])*\\s+AS\\s+~isU', '', $connection->result("SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = SCHEMA_NAME() AND TABLE_NAME = " . q($name))));
}
function collations() {
$return = array();
foreach (get_vals("SELECT name FROM fn_helpcollations()") as $collation) {
$return[ereg_replace("_.*", "", $collation)][] = $collation;
$return[preg_replace('~_.*~', '', $collation)][] = $collation;
}
return $return;
}
@ -409,17 +409,17 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
global $connection;
return nl_br(h(preg_replace('~^(\\[[^]]*])+~m', '', $connection->error)));
}
function create_database($db, $collation) {
return queries("CREATE DATABASE " . idf_escape($db) . (eregi('^[a-z0-9_]+$', $collation) ? " COLLATE $collation" : ""));
return queries("CREATE DATABASE " . idf_escape($db) . (preg_match('~^[a-z0-9_]+$~i', $collation) ? " COLLATE $collation" : ""));
}
function drop_databases($databases) {
return queries("DROP DATABASE " . implode(", ", array_map('idf_escape', $databases)));
}
function rename_database($name, $collation) {
if (eregi('^[a-z0-9_]+$', $collation)) {
if (preg_match('~^[a-z0-9_]+$~i', $collation)) {
queries("ALTER DATABASE " . idf_escape(DB) . " COLLATE $collation");
}
queries("ALTER DATABASE " . idf_escape(DB) . " MODIFY NAME = " . idf_escape($name));
@ -429,7 +429,7 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
function auto_increment() {
return " IDENTITY" . ($_POST["Auto_increment"] != "" ? "(" . (+$_POST["Auto_increment"]) . ",1)" : "") . " PRIMARY KEY";
}
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
$alter = array();
foreach ($fields as $field) {
@ -466,7 +466,7 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
}
return true;
}
function alter_indexes($table, $alter) {
$index = array();
$drop = array();
@ -488,22 +488,22 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
&& (!$drop || queries("ALTER TABLE " . table($table) . " DROP " . implode(", ", $drop)))
;
}
function last_id() {
global $connection;
return $connection->result("SELECT SCOPE_IDENTITY()"); // @@IDENTITY can return trigger INSERT
}
function explain($connection, $query) {
$connection->query("SET SHOWPLAN_ALL ON");
$return = $connection->query($query);
$connection->query("SET SHOWPLAN_ALL OFF"); // connection is used also for indexes
return $return;
}
function found_rows($table_status, $where) {
}
function foreign_keys($table) {
$return = array();
foreach (get_rows("EXEC sp_fkeys @fktable_name = " . q($table)) as $row) {
@ -530,7 +530,7 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
function move_tables($tables, $views, $target) {
return apply_queries("ALTER SCHEMA " . idf_escape($target) . " TRANSFER", array_merge($tables, $views));
}
function trigger($name) {
if ($name == "") {
return array();
@ -549,7 +549,7 @@ WHERE s.xtype = 'TR' AND s.name = " . q($name)
}
return $return;
}
function triggers($table) {
$return = array();
foreach (get_rows("SELECT sys1.name,
@ -563,18 +563,18 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
}
return $return;
}
function trigger_options() {
return array(
"Timing" => array("AFTER", "INSTEAD OF"),
"Type" => array("AS"),
);
}
function schemas() {
return get_vals("SELECT name FROM sys.schemas");
}
function get_schema() {
global $connection;
if ($_GET["ns"] != "") {
@ -582,34 +582,34 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
}
return $connection->result("SELECT SCHEMA_NAME()");
}
function set_schema($schema) {
return true; // ALTER USER is permanent
}
function use_sql($database) {
return "USE " . idf_escape($database);
}
function show_variables() {
return array();
}
function show_status() {
return array();
}
function convert_field($field) {
}
function unconvert_field($field, $return) {
return $return;
}
function support($feature) {
return ereg('^(database|table|sql|indexes|scheme|trigger|view|drop_col)$', $feature); //! routine|
return preg_match('~^(database|table|sql|indexes|scheme|trigger|view|drop_col)$~', $feature); //! routine|
}
$jush = "mssql";
$types = array();
$structured_types = array();

View file

@ -8,11 +8,11 @@ if (!defined("DRIVER")) {
if (extension_loaded("mysqli")) {
class Min_DB extends MySQLi {
var $extension = "MySQLi";
function Min_DB() {
parent::init();
}
function connect($server, $username, $password) {
mysqli_report(MYSQLI_REPORT_OFF); // stays between requests, not required since PHP 5.3.4
list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket
@ -33,7 +33,7 @@ if (!defined("DRIVER")) {
}
return $return;
}
function result($query, $field = 0) {
$result = $this->query($query);
if (!$result) {
@ -42,12 +42,12 @@ if (!defined("DRIVER")) {
$row = $result->fetch_array();
return $row[$field];
}
function quote($string) {
return "'" . $this->escape_string($string) . "'";
}
}
} elseif (extension_loaded("mysql") && !(ini_get("sql.safe_mode") && extension_loaded("pdo_mysql"))) {
class Min_DB {
var
@ -58,7 +58,7 @@ if (!defined("DRIVER")) {
$error, ///< @var string last error message
$_link, $_result ///< @access private
;
/** Connect to server
* @param string
* @param string
@ -85,7 +85,7 @@ if (!defined("DRIVER")) {
}
return (bool) $this->_link;
}
/** Quote string to use in SQL
* @param string
* @return string escaped string enclosed in '
@ -93,7 +93,7 @@ if (!defined("DRIVER")) {
function quote($string) {
return "'" . mysql_real_escape_string($string, $this->_link) . "'";
}
/** Select database
* @param string
* @return bool
@ -101,7 +101,7 @@ if (!defined("DRIVER")) {
function select_db($database) {
return mysql_select_db($database, $this->_link);
}
/** Send query
* @param string
* @param bool
@ -122,7 +122,7 @@ if (!defined("DRIVER")) {
}
return new Min_Result($result);
}
/** Send query with more resultsets
* @param string
* @return bool
@ -130,14 +130,14 @@ if (!defined("DRIVER")) {
function multi_query($query) {
return $this->_result = $this->query($query);
}
/** Get current resultset
* @return Min_Result
*/
function store_result() {
return $this->_result;
}
/** Fetch next resultset
* @return bool
*/
@ -145,7 +145,7 @@ if (!defined("DRIVER")) {
// MySQL extension doesn't support multiple results
return false;
}
/** Get single field from result
* @param string
* @param int
@ -159,13 +159,13 @@ if (!defined("DRIVER")) {
return mysql_result($result->_result, 0, $field);
}
}
class Min_Result {
var
$num_rows, ///< @var int number of rows in the result
$_result, $_offset = 0 ///< @access private
;
/** Constructor
* @param resource
*/
@ -173,21 +173,21 @@ if (!defined("DRIVER")) {
$this->_result = $result;
$this->num_rows = mysql_num_rows($result);
}
/** Fetch next row as associative array
* @return array
*/
function fetch_assoc() {
return mysql_fetch_assoc($this->_result);
}
/** Fetch next row as numbered array
* @return array
*/
function fetch_row() {
return mysql_fetch_row($this->_result);
}
/** Fetch next field
* @return object properties: name, type, orgtable, orgname, charsetnr
*/
@ -198,45 +198,45 @@ if (!defined("DRIVER")) {
$return->charsetnr = ($return->blob ? 63 : 0);
return $return;
}
/** Free result set
*/
function __destruct() {
mysql_free_result($this->_result); //! not called in PHP 4 which is a problem with mysql.trace_mode
}
}
} elseif (extension_loaded("pdo_mysql")) {
class Min_DB extends Min_PDO {
var $extension = "PDO_MySQL";
function connect($server, $username, $password) {
$this->dsn("mysql:host=" . str_replace(":", ";unix_socket=", preg_replace('~:(\\d)~', ';port=\\1', $server)), $username, $password);
$this->query("SET NAMES utf8"); // charset in DSN is ignored
return true;
}
function select_db($database) {
// database selection is separated from the connection so dbname in DSN can't be used
return $this->query("USE " . idf_escape($database));
}
function query($query, $unbuffered = false) {
$this->setAttribute(1000, !$unbuffered); // 1000 - PDO::MYSQL_ATTR_USE_BUFFERED_QUERY
return parent::query($query, $unbuffered);
}
}
}
class Min_Driver extends Min_SQL {
function insert($table, $set) {
return ($set ? parent::insert($table, $set) : queries("INSERT INTO " . table($table) . " ()\nVALUES ()"));
}
function insertUpdate($table, $rows, $primary) {
$columns = array_keys(reset($rows));
$prefix = "INSERT INTO " . table($table) . " (" . implode(", ", $columns) . ") VALUES\n";
@ -261,7 +261,7 @@ if (!defined("DRIVER")) {
}
return queries($prefix . implode(",\n", $values) . $suffix);
}
}
@ -366,7 +366,7 @@ if (!defined("DRIVER")) {
function engines() {
$return = array();
foreach (get_rows("SHOW ENGINES") as $row) {
if (ereg("YES|DEFAULT", $row["Support"])) {
if (preg_match("~YES|DEFAULT~", $row["Support"])) {
$return[] = $row["Engine"];
}
}
@ -441,7 +441,7 @@ if (!defined("DRIVER")) {
* @return bool
*/
function fk_support($table_status) {
return eregi("InnoDB|IBMDB2I", $table_status["Engine"]);
return preg_match('~InnoDB|IBMDB2I~i', $table_status["Engine"]);
}
/** Get information about fields
@ -458,10 +458,10 @@ if (!defined("DRIVER")) {
"type" => $match[1],
"length" => $match[2],
"unsigned" => ltrim($match[3] . $match[4]),
"default" => ($row["Default"] != "" || ereg("char|set", $match[1]) ? $row["Default"] : null),
"default" => ($row["Default"] != "" || preg_match("~char|set~", $match[1]) ? $row["Default"] : null),
"null" => ($row["Null"] == "YES"),
"auto_increment" => ($row["Extra"] == "auto_increment"),
"on_update" => (eregi('^on update (.+)', $row["Extra"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23
"on_update" => (preg_match('~^on update (.+)~i', $row["Extra"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23
"collation" => $row["Collation"],
"privileges" => array_flip(explode(",", $row["Privileges"])),
"comment" => $row["Comment"],
@ -565,7 +565,7 @@ if (!defined("DRIVER")) {
*/
function error_line() {
global $connection;
if (ereg(' at line ([0-9]+)$', $connection->error, $regs)) {
if (preg_match('~ at line ([0-9]+)$~', $connection->error, $regs)) {
return $regs[1] - 1;
}
}
@ -579,7 +579,7 @@ if (!defined("DRIVER")) {
set_session("dbs", null);
return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " COLLATE " . q($collation) : ""));
}
/** Drop databases
* @param array
* @return bool
@ -589,7 +589,7 @@ if (!defined("DRIVER")) {
set_session("dbs", null);
return apply_queries("DROP DATABASE", $databases, 'idf_escape');
}
/** Rename database from DB
* @param string new name
* @param string
@ -609,7 +609,7 @@ if (!defined("DRIVER")) {
}
return false;
}
/** Generate modifier for auto increment column
* @return string
*/
@ -629,7 +629,7 @@ if (!defined("DRIVER")) {
}
return " AUTO_INCREMENT$auto_increment_index";
}
/** Run commands to create or alter table
* @param string "" to create
* @param string new name
@ -666,7 +666,7 @@ if (!defined("DRIVER")) {
$alter[] = $status;
return queries("ALTER TABLE " . table($table) . "\n" . implode(",\n", $alter));
}
/** Run commands to alter indexes
* @param string escaped table name
* @param array of array("index type", "name", "(columns definition)") or array("index type", "name", "DROP")
@ -681,7 +681,7 @@ if (!defined("DRIVER")) {
}
return queries("ALTER TABLE " . table($table) . implode(",", $alter));
}
/** Run commands to truncate tables
* @param array
* @return bool
@ -689,7 +689,7 @@ if (!defined("DRIVER")) {
function truncate_tables($tables) {
return apply_queries("TRUNCATE TABLE", $tables);
}
/** Drop views
* @param array
* @return bool
@ -697,7 +697,7 @@ if (!defined("DRIVER")) {
function drop_views($views) {
return queries("DROP VIEW " . implode(", ", array_map('table', $views)));
}
/** Drop tables
* @param array
* @return bool
@ -705,7 +705,7 @@ if (!defined("DRIVER")) {
function drop_tables($tables) {
return queries("DROP TABLE " . implode(", ", array_map('table', $tables)));
}
/** Move tables to other schema
* @param array
* @param array
@ -720,7 +720,7 @@ if (!defined("DRIVER")) {
return queries("RENAME TABLE " . implode(", ", $rename));
//! move triggers
}
/** Copy tables to other schema
* @param array
* @param array
@ -749,7 +749,7 @@ if (!defined("DRIVER")) {
}
return true;
}
/** Get information about trigger
* @param string trigger name
* @return array array("Trigger" => , "Timing" => , "Event" => , "Type" => , "Statement" => )
@ -761,7 +761,7 @@ if (!defined("DRIVER")) {
$rows = get_rows("SHOW TRIGGERS WHERE `Trigger` = " . q($name));
return reset($rows);
}
/** Get defined triggers
* @param string
* @return array array($name => array($timing, $event))
@ -773,7 +773,7 @@ if (!defined("DRIVER")) {
}
return $return;
}
/** Get trigger options
* @return array ("Timing" => array(), "Type" => array())
*/
@ -784,7 +784,7 @@ if (!defined("DRIVER")) {
"Type" => array("FOR EACH ROW"),
);
}
/** Get information about stored routine
* @param string
* @param string "FUNCTION" or "PROCEDURE"
@ -822,21 +822,21 @@ if (!defined("DRIVER")) {
"language" => "SQL", // available in information_schema.ROUTINES.PARAMETER_STYLE
);
}
/** Get list of routines
* @return array ("ROUTINE_TYPE" => , "ROUTINE_NAME" => , "DTD_IDENTIFIER" => )
*/
function routines() {
return get_rows("SELECT ROUTINE_NAME, ROUTINE_TYPE, DTD_IDENTIFIER FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . q(DB));
}
/** Get list of available routine languages
* @return array
*/
function routine_languages() {
return array(); // "SQL" not required
}
/** Get last auto increment ID
* @return string
*/
@ -844,7 +844,7 @@ if (!defined("DRIVER")) {
global $connection;
return $connection->result("SELECT LAST_INSERT_ID()"); // mysql_insert_id() truncates bigint
}
/** Explain select
* @param Min_DB
* @param string
@ -853,7 +853,7 @@ if (!defined("DRIVER")) {
function explain($connection, $query) {
return $connection->query("EXPLAIN " . ($connection->server_info >= 5.1 ? "PARTITIONS " : "") . $query);
}
/** Get approximate number of rows
* @param array
* @param array
@ -862,28 +862,28 @@ if (!defined("DRIVER")) {
function found_rows($table_status, $where) {
return ($where || $table_status["Engine"] != "InnoDB" ? null : $table_status["Rows"]);
}
/** Get user defined types
* @return array
*/
function types() {
return array();
}
/** Get existing schemas
* @return array
*/
function schemas() {
return array();
}
/** Get current schema
* @return string
*/
function get_schema() {
return "";
}
/** Set current schema
* @param string
* @return bool
@ -891,7 +891,7 @@ if (!defined("DRIVER")) {
function set_schema($schema) {
return true;
}
/** Get SQL command to create table
* @param string
* @param bool
@ -905,7 +905,7 @@ if (!defined("DRIVER")) {
}
return $return;
}
/** Get SQL command to truncate table
* @param string
* @return string
@ -913,7 +913,7 @@ if (!defined("DRIVER")) {
function truncate_sql($table) {
return "TRUNCATE " . table($table);
}
/** Get SQL command to change database
* @param string
* @return string
@ -921,7 +921,7 @@ if (!defined("DRIVER")) {
function use_sql($database) {
return "USE " . idf_escape($database);
}
/** Get SQL commands to create triggers
* @param string
* @param string
@ -935,69 +935,69 @@ if (!defined("DRIVER")) {
}
return $return;
}
/** Get server variables
* @return array ($name => $value)
*/
function show_variables() {
return get_key_vals("SHOW VARIABLES");
}
/** Get process list
* @return array ($row)
*/
function process_list() {
return get_rows("SHOW FULL PROCESSLIST");
}
/** Get status variables
* @return array ($name => $value)
*/
function show_status() {
return get_key_vals("SHOW STATUS");
}
/** Convert field in select and edit
* @param array one element from fields()
* @return string
*/
function convert_field($field) {
if (ereg("binary", $field["type"])) {
if (preg_match("~binary~", $field["type"])) {
return "HEX(" . idf_escape($field["field"]) . ")";
}
if ($field["type"] == "bit") {
return "BIN(" . idf_escape($field["field"]) . " + 0)"; // + 0 is required outside MySQLnd
}
if (ereg("geometry|point|linestring|polygon", $field["type"])) {
if (preg_match("~geometry|point|linestring|polygon~", $field["type"])) {
return "AsWKT(" . idf_escape($field["field"]) . ")";
}
}
/** Convert value in edit after applying functions back
* @param array one element from fields()
* @param string
* @return string
*/
function unconvert_field($field, $return) {
if (ereg("binary", $field["type"])) {
if (preg_match("~binary~", $field["type"])) {
$return = "UNHEX($return)";
}
if ($field["type"] == "bit") {
$return = "CONV($return, 2, 10) + 0";
}
if (ereg("geometry|point|linestring|polygon", $field["type"])) {
if (preg_match("~geometry|point|linestring|polygon~", $field["type"])) {
$return = "GeomFromText($return)";
}
return $return;
}
/** Check whether a feature is supported
* @param string "comment", "copy", "database", "drop_col", "dump", "event", "kill", "partitioning", "privileges", "procedure", "processlist", "routine", "scheme", "sequence", "status", "table", "trigger", "type", "variables", "view"
* @return bool
*/
function support($feature) {
global $connection;
return !ereg("scheme|sequence|type" . ($connection->server_info < 5.1 ? "|event|partitioning" . ($connection->server_info < 5 ? "|view|routine|trigger" : "") : ""), $feature);
return !preg_match("~scheme|sequence|type" . ($connection->server_info < 5.1 ? "|event|partitioning" . ($connection->server_info < 5 ? "|view|routine|trigger" : "") : "") . "~", $feature);
}
$jush = "sql"; ///< @var string JUSH identifier

View file

@ -12,10 +12,10 @@ if (isset($_GET["oracle"])) {
if (ini_bool("html_errors")) {
$error = html_entity_decode(strip_tags($error));
}
$error = ereg_replace('^[^:]*: ', '', $error);
$error = preg_replace('~^[^:]*: ~', '', $error);
$this->error = $error;
}
function connect($server, $username, $password) {
$this->_link = @oci_new_connect($username, $password, $server, "AL32UTF8");
if ($this->_link) {
@ -59,15 +59,15 @@ if (isset($_GET["oracle"])) {
function multi_query($query) {
return $this->_result = $this->query($query);
}
function store_result() {
return $this->_result;
}
function next_result() {
return false;
}
function result($query, $field = 1) {
$result = $this->query($query);
if (!is_object($result) || !oci_fetch($result->_result)) {
@ -92,7 +92,7 @@ if (isset($_GET["oracle"])) {
}
return $row;
}
function fetch_assoc() {
return $this->_convert(oci_fetch_assoc($this->_result));
}
@ -107,41 +107,41 @@ if (isset($_GET["oracle"])) {
$return->name = oci_field_name($this->_result, $column);
$return->orgname = $return->name;
$return->type = oci_field_type($this->_result, $column);
$return->charsetnr = (ereg("raw|blob|bfile", $return->type) ? 63 : 0); // 63 - binary
$return->charsetnr = (preg_match("~raw|blob|bfile~", $return->type) ? 63 : 0); // 63 - binary
return $return;
}
function __destruct() {
oci_free_statement($this->_result);
}
}
} elseif (extension_loaded("pdo_oci")) {
class Min_DB extends Min_PDO {
var $extension = "PDO_OCI";
function connect($server, $username, $password) {
$this->dsn("oci:dbname=//$server;charset=AL32UTF8", $username, $password);
return true;
}
function select_db($database) {
return true;
}
}
}
class Min_Driver extends Min_SQL {
//! support empty $set in insert()
function begin() {
return true; // automatic start
}
}
@ -203,7 +203,7 @@ ORDER BY 1"
function count_tables($databases) {
return array();
}
function table_status($name = "") {
$return = array();
$search = q($name);
@ -222,7 +222,7 @@ ORDER BY 1"
function is_view($table_status) {
return $table_status["Engine"] == "view";
}
function fk_support($table_status) {
return true;
}
@ -272,7 +272,7 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) {
$rows = get_rows('SELECT text "select" FROM user_views WHERE view_name = ' . q($name));
return reset($rows);
}
function collations() {
return array(); //!
}
@ -285,15 +285,15 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) {
global $connection;
return h($connection->error); //! highlight sqltext from offset
}
function explain($connection, $query) {
$connection->query("EXPLAIN PLAN FOR $query");
return $connection->query("SELECT * FROM plan_table");
}
function found_rows($table_status, $where) {
}
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
$alter = $drop = array();
foreach ($fields as $field) {
@ -315,11 +315,11 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) {
&& ($table == $name || queries("ALTER TABLE " . table($table) . " RENAME TO " . table($name)))
;
}
function foreign_keys($table) {
return array(); //!
}
function truncate_tables($tables) {
return apply_queries("TRUNCATE TABLE", $tables);
}
@ -335,25 +335,25 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) {
function last_id() {
return 0; //!
}
function schemas() {
return get_vals("SELECT DISTINCT owner FROM dba_segments WHERE owner IN (SELECT username FROM dba_users WHERE default_tablespace NOT IN ('SYSTEM','SYSAUX'))");
}
function get_schema() {
global $connection;
return $connection->result("SELECT sys_context('USERENV', 'SESSION_USER') FROM dual");
}
function set_schema($scheme) {
global $connection;
return $connection->query("ALTER SESSION SET CURRENT_SCHEMA = " . idf_escape($scheme));
}
function show_variables() {
return get_key_vals('SELECT name, display_value FROM v$parameter');
}
function process_list() {
return get_rows('SELECT sess.process AS "process", sess.username AS "user", sess.schemaname AS "schema", sess.status AS "status", sess.wait_class AS "wait_class", sess.seconds_in_wait AS "seconds_in_wait", sql.sql_text AS "sql_text", sess.machine AS "machine", sess.port AS "port"
FROM v$session sess LEFT OUTER JOIN v$sql sql
@ -362,23 +362,23 @@ WHERE sess.type = \'USER\'
ORDER BY PROCESS
');
}
function show_status() {
$rows = get_rows('SELECT * FROM v$instance');
return reset($rows);
}
function convert_field($field) {
}
function unconvert_field($field, $return) {
return $return;
}
function support($feature) {
return ereg('^(database|table|sql|indexes|view|scheme|processlist|drop_col|variables|status)$', $feature); //!
return preg_match('~^(database|table|sql|indexes|view|scheme|processlist|drop_col|variables|status)$~', $feature); //!
}
$jush = "oracle";
$types = array();
$structured_types = array();

View file

@ -7,15 +7,15 @@ if (isset($_GET["pgsql"])) {
if (extension_loaded("pgsql")) {
class Min_DB {
var $extension = "PgSQL", $_link, $_result, $_string, $_database = true, $server_info, $affected_rows, $error;
function _error($errno, $error) {
if (ini_bool("html_errors")) {
$error = html_entity_decode(strip_tags($error));
}
$error = ereg_replace('^[^:]*: ', '', $error);
$error = preg_replace('~^[^:]*: ~', '', $error);
$this->error = $error;
}
function connect($server, $username, $password) {
global $adminer;
$db = $adminer->database();
@ -35,11 +35,11 @@ if (isset($_GET["pgsql"])) {
}
return (bool) $this->_link;
}
function quote($string) {
return "'" . pg_escape_string($this->_link, $string) . "'"; //! bytea
}
function select_db($database) {
global $adminer;
if ($database == $adminer->database()) {
@ -51,11 +51,11 @@ if (isset($_GET["pgsql"])) {
}
return $return;
}
function close() {
$this->_link = @pg_connect("$this->_string dbname='postgres'");
}
function query($query, $unbuffered = false) {
$result = @pg_query($this->_link, $query);
$this->error = "";
@ -68,20 +68,20 @@ if (isset($_GET["pgsql"])) {
}
return new Min_Result($result);
}
function multi_query($query) {
return $this->_result = $this->query($query);
}
function store_result() {
return $this->_result;
}
function next_result() {
// PgSQL extension doesn't support multiple results
return false;
}
function result($query, $field = 0) {
$result = $this->query($query);
if (!$result || !$result->num_rows) {
@ -90,23 +90,23 @@ if (isset($_GET["pgsql"])) {
return pg_fetch_result($result->_result, 0, $field);
}
}
class Min_Result {
var $_result, $_offset = 0, $num_rows;
function Min_Result($result) {
$this->_result = $result;
$this->num_rows = pg_num_rows($result);
}
function fetch_assoc() {
return pg_fetch_assoc($this->_result);
}
function fetch_row() {
return pg_fetch_row($this->_result);
}
function fetch_field() {
$column = $this->_offset++;
$return = new stdClass;
@ -119,16 +119,16 @@ if (isset($_GET["pgsql"])) {
$return->charsetnr = ($return->type == "bytea" ? 63 : 0); // 63 - binary
return $return;
}
function __destruct() {
pg_free_result($this->_result);
}
}
} elseif (extension_loaded("pdo_pgsql")) {
class Min_DB extends Min_PDO {
var $extension = "PDO_PgSQL";
function connect($server, $username, $password) {
global $adminer;
$db = $adminer->database();
@ -137,22 +137,22 @@ if (isset($_GET["pgsql"])) {
//! connect without DB in case of an error
return true;
}
function select_db($database) {
global $adminer;
return ($adminer->database() == $database);
}
function close() {
}
}
}
class Min_Driver extends Min_SQL {
function insertUpdate($table, $rows, $primary) {
global $connection;
foreach ($rows as $set) {
@ -172,7 +172,7 @@ if (isset($_GET["pgsql"])) {
}
return true;
}
}
@ -197,11 +197,11 @@ if (isset($_GET["pgsql"])) {
}
return $connection->error;
}
function get_databases() {
return get_vals("SELECT datname FROM pg_database ORDER BY datname");
}
function limit($query, $where, $limit, $offset = 0, $separator = " ") {
return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
}
@ -209,7 +209,7 @@ if (isset($_GET["pgsql"])) {
function limit1($query, $where) {
return " $query$where";
}
function db_collation($db, $collations) {
global $connection;
return $connection->result("SHOW LC_COLLATE"); //! respect $db
@ -218,16 +218,16 @@ if (isset($_GET["pgsql"])) {
function engines() {
return array();
}
function logged_user() {
global $connection;
return $connection->result("SELECT user");
}
function tables_list() {
return get_key_vals("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema() ORDER BY table_name");
}
function count_tables($databases) {
return array(); // would require reconnect
}
@ -244,15 +244,15 @@ AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema(
}
return ($name != "" ? $return[$name] : $return);
}
function is_view($table_status) {
return $table_status["Engine"] == "view";
}
function fk_support($table_status) {
return true;
}
function fields($table) {
$return = array();
$aliases = array(
@ -272,13 +272,13 @@ ORDER BY a.attnum"
) as $row) {
//! collation, primary
$type = $row["full_type"];
if (ereg('(.+)\\((.*)\\)$', $row["full_type"], $match)) {
if (preg_match('~(.+)\\((.*)\\)$~', $row["full_type"], $match)) {
list(, $type, $row["length"]) = $match;
}
$row["type"] = ($aliases[$type] ? $aliases[$type] : $type);
$row["full_type"] = $row["type"] . ($row["length"] ? "($row[length])" : "");
$row["null"] = !$row["attnotnull"];
$row["auto_increment"] = eregi("^nextval\\(", $row["default"]);
$row["auto_increment"] = preg_match('~^nextval\\(~i', $row["default"]);
$row["privileges"] = array("insert" => 1, "select" => 1, "update" => 1);
if (preg_match('~(.+)::[^)]+(.*)~', $row["default"], $match)) {
$row["default"] = ($match[1][0] == "'" ? idf_unescape($match[1]) : $match[1]) . $match[2];
@ -287,7 +287,7 @@ ORDER BY a.attnum"
}
return $return;
}
function indexes($table, $connection2 = null) {
global $connection;
if (!is_object($connection2)) {
@ -311,7 +311,7 @@ ORDER BY a.attnum"
}
return $return;
}
function foreign_keys($table) {
global $on_actions;
$return = array();
@ -335,21 +335,21 @@ ORDER BY conkey, conname") as $row) {
}
return $return;
}
function view($name) {
global $connection;
return array("select" => $connection->result("SELECT pg_get_viewdef(" . q($name) . ")"));
}
function collations() {
//! supported in CREATE DATABASE
return array();
}
function information_schema($db) {
return ($db == "information_schema");
}
function error() {
global $connection;
$return = h($connection->error);
@ -358,26 +358,26 @@ ORDER BY conkey, conname") as $row) {
}
return nl_br($return);
}
function create_database($db, $collation) {
return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " ENCODING " . idf_escape($collation) : ""));
}
function drop_databases($databases) {
global $connection;
$connection->close();
return apply_queries("DROP DATABASE", $databases, 'idf_escape');
}
function rename_database($name, $collation) {
//! current database cannot be renamed
return queries("ALTER DATABASE " . idf_escape(DB) . " RENAME TO " . idf_escape($name));
}
function auto_increment() {
return "";
}
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
$alter = array();
$queries = array();
@ -431,7 +431,7 @@ ORDER BY conkey, conname") as $row) {
}
return true;
}
function alter_indexes($table, $alter) {
$create = array();
$drop = array();
@ -462,20 +462,20 @@ ORDER BY conkey, conname") as $row) {
}
return true;
}
function truncate_tables($tables) {
return queries("TRUNCATE " . implode(", ", array_map('table', $tables)));
return true;
}
function drop_views($views) {
return queries("DROP VIEW " . implode(", ", array_map('table', $views)));
}
function drop_tables($tables) {
return queries("DROP TABLE " . implode(", ", array_map('table', $tables)));
}
function move_tables($tables, $views, $target) {
foreach ($tables as $table) {
if (!queries("ALTER TABLE " . table($table) . " SET SCHEMA " . idf_escape($target))) {
@ -489,7 +489,7 @@ ORDER BY conkey, conname") as $row) {
}
return true;
}
function trigger($name) {
if ($name == "") {
return array("Statement" => "EXECUTE PROCEDURE ()");
@ -497,7 +497,7 @@ ORDER BY conkey, conname") as $row) {
$rows = get_rows('SELECT trigger_name AS "Trigger", condition_timing AS "Timing", event_manipulation AS "Event", \'FOR EACH \' || action_orientation AS "Type", action_statement AS "Statement" FROM information_schema.triggers WHERE event_object_table = ' . q($_GET["trigger"]) . ' AND trigger_name = ' . q($name));
return reset($rows);
}
function triggers($table) {
$return = array();
foreach (get_rows("SELECT * FROM information_schema.triggers WHERE event_object_table = " . q($table)) as $row) {
@ -505,14 +505,14 @@ ORDER BY conkey, conname") as $row) {
}
return $return;
}
function trigger_options() {
return array(
"Timing" => array("BEFORE", "AFTER"),
"Type" => array("FOR EACH ROW", "FOR EACH STATEMENT"),
);
}
/*
function routine($name, $type) {
//! there can be more functions with the same name differing only in parameters, it must be also passed to DROP FUNCTION
@ -526,7 +526,7 @@ WHERE n.nspname = current_schema() AND p.proname = ' . q($name));
return $rows[0];
}
*/
function routines() {
return get_rows('SELECT p.proname AS "ROUTINE_NAME", p.proargtypes AS "ROUTINE_TYPE", pg_catalog.format_type(p.prorettype, NULL) AS "DTD_IDENTIFIER"
FROM pg_catalog.pg_namespace n
@ -534,23 +534,23 @@ JOIN pg_catalog.pg_proc p ON p.pronamespace = n.oid
WHERE n.nspname = current_schema()
ORDER BY p.proname');
}
function routine_languages() {
return get_vals("SELECT langname FROM pg_catalog.pg_language");
}
function last_id() {
return 0; // there can be several sequences
}
function explain($connection, $query) {
return $connection->query("EXPLAIN $query");
}
function found_rows($table_status, $where) {
global $connection;
if (ereg(
" rows=([0-9]+)",
if (preg_match(
"~ rows=([0-9]+)~",
$connection->result("EXPLAIN SELECT * FROM " . idf_escape($table_status["Name"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")),
$regs
)) {
@ -558,7 +558,7 @@ ORDER BY p.proname');
}
return false;
}
function types() {
return get_vals("SELECT typname
FROM pg_type
@ -567,16 +567,16 @@ AND typtype IN ('b','d','e')
AND typelem = 0"
);
}
function schemas() {
return get_vals("SELECT nspname FROM pg_namespace ORDER BY nspname");
}
function get_schema() {
global $connection;
return $connection->result("SELECT current_schema()");
}
function set_schema($schema) {
global $connection, $types, $structured_types;
$return = $connection->query("SET search_path TO " . idf_escape($schema));
@ -588,11 +588,11 @@ AND typelem = 0"
}
return $return;
}
function use_sql($database) {
return "\connect " . idf_escape($database);
}
function show_variables() {
return get_key_vals("SHOW ALL");
}
@ -601,21 +601,21 @@ AND typelem = 0"
global $connection;
return get_rows("SELECT * FROM pg_stat_activity ORDER BY " . ($connection->server_info < 9.2 ? "procpid" : "pid"));
}
function show_status() {
}
function convert_field($field) {
}
function unconvert_field($field, $return) {
return $return;
}
function support($feature) {
return ereg('^(database|table|sql|indexes|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$', $feature); //! routine|
return preg_match('~^(database|table|sql|indexes|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$~', $feature); //! routine|
}
$jush = "pgsql";
$types = array();
$structured_types = array();

View file

@ -12,15 +12,15 @@ $drivers["simpledb"] = "SimpleDB";
if (isset($_GET["simpledb"])) {
$possible_drivers = array("SimpleXML");
define("DRIVER", "simpledb");
if (class_exists('SimpleXMLElement')) {
class Min_DB {
var $extension = "SimpleXML", $server_info = '2009-04-15', $error, $timeout, $next, $affected_rows, $_result;
function select_db($database) {
return ($database == "domain");
}
function query($query, $unbuffered = false) {
$params = array('SelectExpression' => $query, 'ConsistentRead' => 'true');
if ($this->next) {
@ -42,28 +42,28 @@ if (isset($_GET["simpledb"])) {
}
return new Min_Result($result);
}
function multi_query($query) {
return $this->_result = $this->query($query);
}
function store_result() {
return $this->_result;
}
function next_result() {
return false;
}
function quote($string) {
return "'" . str_replace("'", "''", $string) . "'";
}
}
class Min_Result {
var $num_rows, $_rows = array(), $_offset = 0;
function Min_Result($result) {
foreach ($result as $item) {
$row = array();
@ -83,11 +83,11 @@ if (isset($_GET["simpledb"])) {
}
$this->num_rows = count($this->_rows);
}
function _processValue($element) {
return (is_object($element) && $element['encoding'] == 'base64' ? base64_decode($element) : (string) $element);
}
function fetch_assoc() {
$row = current($this->_rows);
if (!$row) {
@ -100,7 +100,7 @@ if (isset($_GET["simpledb"])) {
next($this->_rows);
return $return;
}
function fetch_row() {
$return = $this->fetch_assoc();
if (!$return) {
@ -108,19 +108,19 @@ if (isset($_GET["simpledb"])) {
}
return array_values($return);
}
function fetch_field() {
$keys = array_keys($this->_rows[0]);
return (object) array('name' => $keys[$this->_offset++]);
}
}
}
class Min_Driver extends Min_SQL {
function _chunkRequest($ids, $action, $params, $expand = array()) {
global $connection;
foreach (array_chunk($ids, 25) as $chunk) {
@ -138,7 +138,7 @@ if (isset($_GET["simpledb"])) {
$connection->affected_rows = count($ids);
return true;
}
function _extractIds($table, $queryWhere, $limit) {
$return = array();
if (preg_match_all("~itemName\(\) = ('[^']*+')+~", $queryWhere, $matches)) {
@ -150,7 +150,7 @@ if (isset($_GET["simpledb"])) {
}
return $return;
}
function select($table, $select, $where, $group, $order, $limit, $page) {
global $connection;
$connection->next = $_GET["next"];
@ -158,7 +158,7 @@ if (isset($_GET["simpledb"])) {
$connection->next = 0;
return $return;
}
function delete($table, $queryWhere, $limit = 0) {
return $this->_chunkRequest(
$this->_extractIds($table, $queryWhere, $limit),
@ -166,7 +166,7 @@ if (isset($_GET["simpledb"])) {
array('DomainName' => $table)
);
}
function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") {
$delete = array();
$insert = array();
@ -188,7 +188,7 @@ if (isset($_GET["simpledb"])) {
&& (!$delete || $this->_chunkRequest($ids, 'BatchDeleteAttributes', $params, $delete))
;
}
function insert($table, $set) {
$params = array("DomainName" => $table);
$i = 0;
@ -207,7 +207,7 @@ if (isset($_GET["simpledb"])) {
}
return sdb_request('PutAttributes', $params);
}
function insertUpdate($table, $rows, $primary) {
//! use one batch request
foreach ($rows as $set) {
@ -217,48 +217,48 @@ if (isset($_GET["simpledb"])) {
}
return true;
}
function begin() {
return false;
}
function commit() {
return false;
}
function rollback() {
return false;
}
}
function connect() {
return new Min_DB;
}
function support($feature) {
return ereg('sql', $feature);
return preg_match('~sql~', $feature);
}
function logged_user() {
global $adminer;
$credentials = $adminer->credentials();
return $credentials[1];
}
function get_databases() {
return array("domain");
}
function collations() {
return array();
}
function db_collation($db, $collations) {
}
function tables_list() {
global $connection;
$return = array();
@ -270,7 +270,7 @@ if (isset($_GET["simpledb"])) {
}
return $return;
}
function table_status($name = "", $fast = false) {
$return = array();
foreach (($name != "" ? array($name => true) : tables_list()) as $table => $type) {
@ -295,27 +295,27 @@ if (isset($_GET["simpledb"])) {
}
return $return;
}
function explain($connection, $query) {
}
function error() {
global $connection;
return h($connection->error);
}
function information_schema() {
}
function is_view($table_status) {
}
function indexes($table, $connection2 = null) {
return array(
array("type" => "PRIMARY", "columns" => array("itemName()")),
);
}
function fields($table) {
$return = array();
foreach ((array) $_POST["field_keys"] as $key => $val) {
@ -332,38 +332,38 @@ if (isset($_GET["simpledb"])) {
}
return $return;
}
function foreign_keys($table) {
return array();
}
function table($idf) {
return idf_escape($idf);
}
function idf_escape($idf) {
return "`" . str_replace("`", "``", $idf) . "`";
}
function limit($query, $where, $limit, $offset = 0, $separator = " ") {
return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" : "");
}
function unconvert_field($field, $return) {
return $return;
}
function fk_support($table_status) {
}
function engines() {
return array();
}
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
return ($table == "" && sdb_request('CreateDomain', array('DomainName' => $name)));
}
function drop_tables($tables) {
foreach ($tables as $table) {
if (!sdb_request('DeleteDomain', array('DomainName' => $table))) {
@ -372,20 +372,20 @@ if (isset($_GET["simpledb"])) {
}
return true;
}
function count_tables($databases) {
foreach ($databases as $db) {
return array($db => count(tables_list()));
}
}
function found_rows($table_status, $where) {
return ($where ? null : $table_status["Rows"]);
}
function last_id() {
}
function hmac($algo, $data, $key, $raw_output = false) {
// can use hash_hmac() since PHP 5.1.2
$blocksize = 64;
@ -416,9 +416,9 @@ if (isset($_GET["simpledb"])) {
$query .= '&' . rawurlencode($key) . '=' . rawurlencode($val);
}
$query = str_replace('%7E', '~', substr($query, 1));
$query .= "&Signature=" . urlencode(base64_encode(hmac('sha1', "POST\n" . ereg_replace('^https?://', '', $host) . "\n/\n$query", $secret, true)));
$query .= "&Signature=" . urlencode(base64_encode(hmac('sha1', "POST\n" . preg_replace('~^https?://~', '', $host) . "\n/\n$query", $secret, true)));
@ini_set('track_errors', 1); // @ - may be disabled
$file = @file_get_contents((ereg('^https?://', $host) ? $host : "http://$host"), false, stream_context_create(array('http' => array(
$file = @file_get_contents((preg_match('~^https?://~', $host) ? $host : "http://$host"), false, stream_context_create(array('http' => array(
'method' => 'POST', // may not fit in URL with GET
'content' => $query,
'ignore_errors' => 1, // available since PHP 5.2.10
@ -443,7 +443,7 @@ if (isset($_GET["simpledb"])) {
$tag = $action . "Result";
return ($xml->$tag ? $xml->$tag : true);
}
function sdb_request_all($action, $tag, $params = array(), $timeout = 0) {
$return = array();
$start = ($timeout ? microtime(true) : 0);
@ -470,7 +470,7 @@ if (isset($_GET["simpledb"])) {
} while ($xml->NextToken);
return $return;
}
$jush = "simpledb";
$operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "IS NOT NULL");
$functions = array();

View file

@ -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);

View file

@ -11,8 +11,8 @@ if ($_POST && !$error) {
$ext = dump_headers(
(count($tables) == 1 ? key($tables) : DB),
(DB == "" || count($tables) > 1));
$is_sql = ereg('sql', $_POST["format"]);
$is_sql = preg_match('~sql~', $_POST["format"]);
if ($is_sql) {
echo "-- Adminer $VERSION " . $drivers[DRIVER] . " dump
@ -23,7 +23,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
" : "") . "
");
}
$style = $_POST["db_style"];
$databases = array(DB);
if (DB == "") {
@ -32,11 +32,11 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
$databases = explode("\n", rtrim(str_replace("\r", "", $databases), "\n"));
}
}
foreach ((array) $databases as $db) {
$adminer->dumpDatabase($db);
if ($connection->select_db($db)) {
if ($is_sql && ereg('CREATE', $style) && ($create = $connection->result("SHOW CREATE DATABASE " . idf_escape($db), 1))) {
if ($is_sql && preg_match('~CREATE~', $style) && ($create = $connection->result("SHOW CREATE DATABASE " . idf_escape($db), 1))) {
if ($style == "DROP+CREATE") {
echo "DROP DATABASE IF EXISTS " . idf_escape($db) . ";\n";
}
@ -47,7 +47,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
echo use_sql($db) . ";\n\n";
}
$out = "";
if ($_POST["routines"]) {
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
foreach (get_rows("SHOW $routine STATUS WHERE Db = " . q($db), null, "-- ") as $row) {
@ -56,19 +56,19 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
}
}
}
if ($_POST["events"]) {
foreach (get_rows("SHOW EVENTS", null, "-- ") as $row) {
$out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "")
. remove_definer($connection->result("SHOW CREATE EVENT " . idf_escape($row["Name"]), 3)) . ";;\n\n";
}
}
if ($out) {
echo "DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n";
}
}
if ($_POST["table_style"] || $_POST["data_style"]) {
$views = array();
foreach (table_status('', true) as $name => $table_status) {
@ -79,7 +79,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
$tmp_file = new TmpFile;
ob_start(array($tmp_file, 'write'), 1e5);
}
$adminer->dumpTable($name, ($table ? $_POST["table_style"] : ""), (is_view($table_status) ? 2 : 0));
if (is_view($table_status)) {
$views[] = $name;
@ -90,7 +90,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($name, $_POST["table_style"]))) {
echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n";
}
if ($ext == "tar") {
ob_end_flush();
tar_file((DB != "" ? "" : "$db/") . "$name.csv", $tmp_file);
@ -99,18 +99,18 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
}
}
}
foreach ($views as $view) {
$adminer->dumpTable($view, $_POST["table_style"], 1);
}
if ($ext == "tar") {
echo pack("x512");
}
}
}
}
if ($is_sql) {
echo "-- " . $connection->result("SELECT NOW()") . "\n";
}
@ -167,14 +167,14 @@ if (DB != "") {
echo "<th style='text-align: left;'><label class='block'><input type='checkbox' id='check-tables'$checked onclick='formCheck(this, /^tables\\[/);'>" . lang('Tables') . "</label>";
echo "<th style='text-align: right;'><label class='block'>" . lang('Data') . "<input type='checkbox' id='check-data'$checked onclick='formCheck(this, /^data\\[/);'></label>";
echo "</thead>\n";
$views = "";
$tables_list = tables_list();
foreach ($tables_list as $name => $type) {
$prefix = ereg_replace("_.*", "", $name);
$prefix = preg_replace('~_.*~', '', $name);
$checked = ($TABLE == "" || $TABLE == (substr($TABLE, -1) == "%" ? "$prefix%" : $name)); //! % may be part of table name
$print = "<tr><td>" . checkbox("tables[]", $name, $checked, $name, "checkboxClick(event, this); formUncheck('check-tables');", "block");
if ($type !== null && !eregi("table", $type)) {
if ($type !== null && !preg_match('~table~i', $type)) {
$views .= "$print\n";
} else {
echo "$print<td align='right'><label class='block'><span id='Rows-" . h($name) . "'></span>" . checkbox("data[]", $name, $checked, "", "checkboxClick(event, this); formUncheck('check-data');") . "</label>\n";
@ -182,18 +182,18 @@ if (DB != "") {
$prefixes[$prefix]++;
}
echo $views;
if ($tables_list) {
echo "<script type='text/javascript'>ajaxSetHtml('" . js_escape(ME) . "script=db');</script>\n";
}
} else {
echo "<thead><tr><th style='text-align: left;'><label class='block'><input type='checkbox' id='check-databases'" . ($TABLE == "" ? " checked" : "") . " onclick='formCheck(this, /^databases\\[/);'>" . lang('Database') . "</label></thead>\n";
$databases = $adminer->databases();
if ($databases) {
foreach ($databases as $db) {
if (!information_schema($db)) {
$prefix = ereg_replace("_.*", "", $db);
$prefix = preg_replace('~_.*~', '', $db);
echo "<tr><td>" . checkbox("databases[]", $db, $TABLE == "" || $TABLE == "$prefix%", $db, "formUncheck('check-databases');", "block") . "\n";
$prefixes[$prefix]++;
}

View file

@ -13,21 +13,21 @@ if ($_POST && !$error && !isset($_GET["select"])) {
$location = $_POST["referer"];
if ($_POST["insert"]) { // continue edit or insert
$location = ($update ? null : $_SERVER["REQUEST_URI"]);
} elseif (!ereg('^.+&select=.+$', $location)) {
} elseif (!preg_match('~^.+&select=.+$~', $location)) {
$location = ME . "select=" . urlencode($TABLE);
}
$indexes = indexes($TABLE);
$unique_array = unique_array($_GET["where"], $indexes);
$query_where = "\nWHERE $where";
if (isset($_POST["delete"])) {
queries_redirect(
$location,
lang('Item has been deleted.'),
$driver->delete($TABLE, $query_where, !$unique_array)
);
} else {
$set = array();
foreach ($fields as $name => $field) {
@ -36,7 +36,7 @@ if ($_POST && !$error && !isset($_GET["select"])) {
$set[idf_escape($name)] = $val;
}
}
if ($update) {
if (!$set) {
redirect($location);
@ -78,7 +78,7 @@ if ($_POST["save"]) {
if ($_POST["clone"] && $field["auto_increment"]) {
$as = "''";
}
if ($jush == "sql" && ereg("enum|set", $field["type"])) {
if ($jush == "sql" && preg_match("~enum|set~", $field["type"])) {
$as = "1*" . idf_escape($name);
}
$select[] = ($as ? "$as AS " : "") . idf_escape($name);
@ -124,36 +124,36 @@ if (!$fields) {
echo "<p class='error'>" . lang('You have no privileges to update this table.') . "\n";
} else {
echo "<table cellspacing='0' onkeydown='return editingKeydown(event);'>\n";
foreach ($fields as $name => $field) {
echo "<tr><th>" . $adminer->fieldName($field);
$default = $_GET["set"][bracket_escape($name)];
if ($default === null) {
$default = $field["default"];
if ($field["type"] == "bit" && ereg("^b'([01]*)'\$", $default, $regs)) {
if ($field["type"] == "bit" && preg_match("~^b'([01]*)'\$~", $default, $regs)) {
$default = $regs[1];
}
}
$value = ($row !== null
? ($row[$name] != "" && $jush == "sql" && ereg("enum|set", $field["type"]) ? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name]) : $row[$name])
? ($row[$name] != "" && $jush == "sql" && preg_match("~enum|set~", $field["type"]) ? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name]) : $row[$name])
: (!$update && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : $default))
);
if (!$_POST["save"] && is_string($value)) {
$value = $adminer->editVal($value, $field);
}
$function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($update && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : ($value !== null ? '' : 'NULL'))));
if (ereg("time", $field["type"]) && $value == "CURRENT_TIMESTAMP") {
if (preg_match("~time~", $field["type"]) && $value == "CURRENT_TIMESTAMP") {
$value = "";
$function = "now";
}
input($field, $value, $function);
echo "\n";
}
if (!support("table")) {
echo "<tr><th><input name='field_keys[]'><td class='function'>&nbsp;<td><input name='field_vals[]'>";
}
echo "</table>\n";
}
?>

View file

@ -13,12 +13,12 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-
foreach ($source as $key => $val) {
$target[$key] = $row["target"][$key];
}
query_redirect("ALTER TABLE " . table($TABLE)
. ($name != "" ? "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($name) . "," : "")
. "\nADD FOREIGN KEY (" . implode(", ", array_map('idf_escape', $source)) . ") REFERENCES " . table($row["table"]) . " (" . implode(", ", array_map('idf_escape', $target)) . ")" //! reuse $name - check in older MySQL versions
. (ereg("^($on_actions)\$", $row["on_delete"]) ? " ON DELETE $row[on_delete]" : "")
. (ereg("^($on_actions)\$", $row["on_update"]) ? " ON UPDATE $row[on_update]" : "")
. (preg_match("~^($on_actions)\$~", $row["on_delete"]) ? " ON DELETE $row[on_delete]" : "")
. (preg_match("~^($on_actions)\$~", $row["on_update"]) ? " ON UPDATE $row[on_update]" : "")
, ME . "table=" . urlencode($TABLE), ($name != "" ? lang('Foreign key has been altered.') : lang('Foreign key has been created.')));
$error = lang('Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exist.') . "<br>$error"; //! no partitioning
}

View file

@ -207,8 +207,8 @@ username.form['auth[driver]'].onchange();
* @return string
*/
function selectVal($val, $link, $field) {
$return = ($val === null ? "<i>NULL</i>" : (ereg("char|binary", $field["type"]) && !ereg("var", $field["type"]) ? "<code>$val</code>" : $val));
if (ereg('blob|bytea|raw|file', $field["type"]) && !is_utf8($val)) {
$return = ($val === null ? "<i>NULL</i>" : (preg_match("~char|binary~", $field["type"]) && !preg_match("~var~", $field["type"]) ? "<code>$val</code>" : $val));
if (preg_match('~blob|bytea|raw|file~', $field["type"]) && !is_utf8($val)) {
$return = lang('%d byte(s)', strlen(html_entity_decode($val, ENT_QUOTES)));
}
return ($link ? "<a href='" . h($link) . "'>$return</a>" : $return);
@ -401,14 +401,14 @@ username.form['auth[driver]'].onchange();
foreach ((array) $_GET["where"] as $val) {
if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
$cond = " $val[op]";
if (ereg('IN$', $val["op"])) {
if (preg_match('~IN$~', $val["op"])) {
$in = process_length($val["val"]);
$cond .= " (" . ($in != "" ? $in : "NULL") . ")";
} elseif ($val["op"] == "SQL") {
$cond = " $val[val]"; // SQL injection
} elseif ($val["op"] == "LIKE %%") {
$cond = " LIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%");
} elseif (!ereg('NULL$', $val["op"])) {
} elseif (!preg_match('~NULL$~', $val["op"])) {
$cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]);
}
if ($val["col"] != "") {
@ -417,12 +417,12 @@ username.form['auth[driver]'].onchange();
// find anywhere
$cols = array();
foreach ($fields as $name => $field) {
$is_text = ereg('char|text|enum|set', $field["type"]);
if ((is_numeric($val["val"]) || !ereg('(^|[^o])int|float|double|decimal|bit', $field["type"]))
&& (!ereg("[\x80-\xFF]", $val["val"]) || $is_text)
$is_text = preg_match('~char|text|enum|set~', $field["type"]);
if ((is_numeric($val["val"]) || !preg_match('~(^|[^o])int|float|double|decimal|bit~', $field["type"]))
&& (!preg_match("~[\x80-\xFF]~", $val["val"]) || $is_text)
) {
$name = idf_escape($name);
$cols[] = ($jush == "sql" && $is_text && !ereg('^utf8', $field["collation"]) ? "CONVERT($name USING utf8)" : $name);
$cols[] = ($jush == "sql" && $is_text && !preg_match('~^utf8~', $field["collation"]) ? "CONVERT($name USING utf8)" : $name);
}
}
$return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0");
@ -495,7 +495,7 @@ username.form['auth[driver]'].onchange();
$history = &get_session("queries");
$id = "sql-" . count($history[$_GET["db"]]);
if (strlen($query) > 1e6) {
$query = ereg_replace('[\x80-\xFF]+$', '', substr($query, 0, 1e6)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
$query = preg_replace('~[\x80-\xFF]+$~', '', substr($query, 0, 1e6)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
}
$history[$_GET["db"]][] = array($query, time()); // not DB - $_GET["db"] is changed in database.inc.php //! respect $_GET["ns"]
return " <span class='time'>" . @date("H:i:s") . "</span> <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre><code class='jush-$jush'>" . shorten_utf8($query, 1000) . '</code></pre><p><a href="' . h(str_replace("db=" . urlencode(DB), "db=" . urlencode($_GET["db"]), ME) . 'sql=&history=' . (count($history[$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a></div>'; // @ - time zone may be not set
@ -511,11 +511,11 @@ username.form['auth[driver]'].onchange();
foreach ($edit_functions as $key => $functions) {
if (!$key || (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET)))) { // relative functions
foreach ($functions as $pattern => $val) {
if (!$pattern || ereg($pattern, $field["type"])) {
if (!$pattern || preg_match("~$pattern~", $field["type"])) {
$return .= "/$val";
}
}
if ($key && !ereg('set|blob|bytea|raw|file', $field["type"])) {
if ($key && !preg_match('~set|blob|bytea|raw|file~', $field["type"])) {
$return .= "/SQL";
}
}
@ -552,17 +552,17 @@ username.form['auth[driver]'].onchange();
}
$name = $field["field"];
$return = q($value);
if (ereg('^(now|getdate|uuid)$', $function)) {
if (preg_match('~^(now|getdate|uuid)$~', $function)) {
$return = "$function()";
} elseif (ereg('^current_(date|timestamp)$', $function)) {
} elseif (preg_match('~^current_(date|timestamp)$~', $function)) {
$return = $function;
} elseif (ereg('^([+-]|\\|\\|)$', $function)) {
} elseif (preg_match('~^([+-]|\\|\\|)$~', $function)) {
$return = idf_escape($name) . " $function $return";
} elseif (ereg('^[+-] interval$', $function)) {
} elseif (preg_match('~^[+-] interval$~', $function)) {
$return = idf_escape($name) . " $function " . (preg_match("~^(\\d+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : $return);
} elseif (ereg('^(addtime|subtime|concat)$', $function)) {
} elseif (preg_match('~^(addtime|subtime|concat)$~', $function)) {
$return = "$function(" . idf_escape($name) . ", $return)";
} elseif (ereg('^(md5|sha1|password|encrypt)$', $function)) {
} elseif (preg_match('~^(md5|sha1|password|encrypt)$~', $function)) {
$return = "$function($return)";
}
return unconvert_field($field, $return);
@ -674,7 +674,7 @@ username.form['auth[driver]'].onchange();
foreach ($row as $key => $val) {
$field = $fields[$key];
$row[$key] = ($val !== null
? unconvert_field($field, ereg('(^|[^o])int|float|double|decimal', $field["type"]) && $val != '' ? $val : q($val))
? unconvert_field($field, preg_match('~(^|[^o])int|float|double|decimal~', $field["type"]) && $val != '' ? $val : q($val))
: "NULL"
);
}
@ -713,7 +713,7 @@ username.form['auth[driver]'].onchange();
*/
function dumpHeaders($identifier, $multi_table = false) {
$output = $_POST["output"];
$ext = (ereg('sql', $_POST["format"]) ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR
$ext = (preg_match('~sql~', $_POST["format"]) ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR
header("Content-Type: " .
($output == "gz" ? "application/x-gzip" :
($ext == "tar" ? "application/x-tar" :

View file

@ -4,7 +4,7 @@ error_reporting(6135); // errors and warnings
include "../adminer/include/coverage.inc.php";
// disable filter.default
$filter = !ereg('^(unsafe_raw)?$', ini_get("filter.default"));
$filter = !preg_match('~^(unsafe_raw)?$~', ini_get("filter.default"));
if ($filter || ini_get("filter.default_flags")) {
foreach (array('_GET', '_POST', '_COOKIE', '_SERVER') as $val) {
$unsafe = filter_input_array(constant("INPUT$val"), FILTER_UNSAFE_RAW);

View file

@ -140,11 +140,11 @@ function edit_type($key, $field, $collations, $foreign_keys = array()) {
global $structured_types, $types, $unsigned, $on_actions;
?>
<td><select name="<?php echo $key; ?>[type]" class="type" onfocus="lastType = selectValue(this);" onchange="editingTypeChange(this);"<?php echo on_help("getTarget(event).value", 1); ?>><?php echo optionlist((!$field["type"] || isset($types[$field["type"]]) ? array() : array($field["type"])) + $structured_types + ($foreign_keys ? array(lang('Foreign keys') => $foreign_keys) : array()), $field["type"]); ?></select>
<td><input name="<?php echo $key; ?>[length]" value="<?php echo h($field["length"]); ?>" size="3" onfocus="editingLengthFocus(this);"<?php echo (!$field["length"] && ereg('var(char|binary)$', $field["type"]) ? " class='required'" : ""); ?> onchange="editingLengthChange(this);" onkeyup="this.onchange();"><td class="options"><?php //! type="number" with enabled JavaScript
echo "<select name='$key" . "[collation]'" . (ereg('(char|text|enum|set)$', $field["type"]) ? "" : " class='hidden'") . '><option value="">(' . lang('collation') . ')' . optionlist($collations, $field["collation"]) . '</select>';
echo ($unsigned ? "<select name='$key" . "[unsigned]'" . (!$field["type"] || ereg('((^|[^o])int|float|double|decimal)$', $field["type"]) ? "" : " class='hidden'") . '><option>' . optionlist($unsigned, $field["unsigned"]) . '</select>' : '');
<td><input name="<?php echo $key; ?>[length]" value="<?php echo h($field["length"]); ?>" size="3" onfocus="editingLengthFocus(this);"<?php echo (!$field["length"] && preg_match('~var(char|binary)$~', $field["type"]) ? " class='required'" : ""); ?> onchange="editingLengthChange(this);" onkeyup="this.onchange();"><td class="options"><?php //! type="number" with enabled JavaScript
echo "<select name='$key" . "[collation]'" . (preg_match('~(char|text|enum|set)$~', $field["type"]) ? "" : " class='hidden'") . '><option value="">(' . lang('collation') . ')' . optionlist($collations, $field["collation"]) . '</select>';
echo ($unsigned ? "<select name='$key" . "[unsigned]'" . (!$field["type"] || preg_match('~((^|[^o])int|float|double|decimal)$~', $field["type"]) ? "" : " class='hidden'") . '><option>' . optionlist($unsigned, $field["unsigned"]) . '</select>' : '');
echo (isset($field['on_update']) ? "<select name='$key" . "[on_update]'" . ($field["type"] == "timestamp" ? "" : " class='hidden'") . '>' . optionlist(array("" => "(" . lang('ON UPDATE') . ")", "CURRENT_TIMESTAMP"), $field["on_update"]) . '</select>' : '');
echo ($foreign_keys ? "<select name='$key" . "[on_delete]'" . (ereg("`", $field["type"]) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist(explode("|", $on_actions), $field["on_delete"]) . "</select> " : " "); // space for IE
echo ($foreign_keys ? "<select name='$key" . "[on_delete]'" . (preg_match("~`~", $field["type"]) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist(explode("|", $on_actions), $field["on_delete"]) . "</select> " : " "); // space for IE
}
/** Filter length value including enums
@ -165,8 +165,8 @@ function process_type($field, $collate = "COLLATE") {
global $unsigned;
return " $field[type]"
. ($field["length"] != "" ? "(" . process_length($field["length"]) . ")" : "")
. (ereg('(^|[^o])int|float|double|decimal', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
. (ereg('char|text|enum|set', $field["type"]) && $field["collation"] ? " $collate " . q($field["collation"]) : "")
. (preg_match('~(^|[^o])int|float|double|decimal~', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
. (preg_match('~char|text|enum|set~', $field["type"]) && $field["collation"] ? " $collate " . q($field["collation"]) : "")
;
}
@ -183,9 +183,9 @@ function process_field($field, $type_field) {
process_type($type_field),
($field["null"] ? " NULL" : " NOT NULL"), // NULL for timestamp
(isset($default) ? " DEFAULT " . (
(ereg("time", $field["type"]) && eregi('^CURRENT_TIMESTAMP$', $default))
|| ($field["type"] == "bit" && ereg("^([0-9]+|b'[0-1]+')\$", $default))
|| ($jush == "pgsql" && ereg("^[a-z]+\(('[^']*')+\)\$", $default))
(preg_match('~time~', $field["type"]) && preg_match('~^CURRENT_TIMESTAMP$~i', $default))
|| ($field["type"] == "bit" && preg_match("~^([0-9]+|b'[0-1]+')\$~", $default))
|| ($jush == "pgsql" && preg_match("~^[a-z]+\\(('[^']*')+\\)\$~", $default))
? $default : q($default)) : ""),
($field["type"] == "timestamp" && $field["on_update"] ? " ON UPDATE $field[on_update]" : ""),
(support("comment") && $field["comment"] != "" ? " COMMENT " . q($field["comment"]) : ""),
@ -204,7 +204,7 @@ function type_class($type) {
'binary' => 'blob',
'enum' => 'set',
) as $key => $val) {
if (ereg("$key|$val", $type)) {
if (preg_match("~$key|$val~", $type)) {
return " class='$key'";
}
}
@ -398,7 +398,7 @@ function create_routine($routine, $row) {
ksort($fields); // enforce fields order
foreach ($fields as $field) {
if ($field["field"] != "") {
$set[] = (ereg("^($inout)\$", $field["inout"]) ? "$field[inout] " : "") . idf_escape($field["field"]) . process_type($field, "CHARACTER SET");
$set[] = (preg_match("~^($inout)\$~", $field["inout"]) ? "$field[inout] " : "") . idf_escape($field["field"]) . process_type($field, "CHARACTER SET");
}
}
return "CREATE $routine "

View file

@ -234,7 +234,7 @@ function json_row($key, $val = null) {
*/
function ini_bool($ini) {
$val = ini_get($ini);
return (eregi('^(on|true|yes)$', $val) || (int) $val); // boolean values set by php_value are strings
return (preg_match('~^(on|true|yes)$~i', $val) || (int) $val); // boolean values set by php_value are strings
}
/** Check if SID is neccessary
@ -325,7 +325,7 @@ function get_rows($query, $connection2 = null, $error = "<p class='error'>") {
*/
function unique_array($row, $indexes) {
foreach ($indexes as $index) {
if (ereg("PRIMARY|UNIQUE", $index["type"])) {
if (preg_match("~PRIMARY|UNIQUE~", $index["type"])) {
$return = array();
foreach ($index["columns"] as $key) {
if (!isset($row[$key])) { // NULL is ambiguous
@ -351,12 +351,12 @@ function where($where, $fields = array()) {
$key = bracket_escape($key, 1); // 1 - back
$column = (preg_match($function_pattern, $key) ? $key : idf_escape($key)); //! SQL injection
$return[] = $column
. (($jush == "sql" && ereg('^[0-9]*\\.[0-9]*$', $val)) || $jush == "mssql"
. (($jush == "sql" && preg_match('~^[0-9]*\\.[0-9]*$~', $val)) || $jush == "mssql"
? " LIKE " . q(addcslashes($val, "%_\\"))
: " = " . unconvert_field($fields[$key], q($val))
) // LIKE because of floats but slow with ints, in MS SQL because of text
; //! enum and set
if ($jush == "sql" && ereg("[^ -@]", $val)) { // not just [a-z] to catch non-ASCII characters
if ($jush == "sql" && preg_match("~[^ -@]~", $val)) { // not just [a-z] to catch non-ASCII characters
$return[] = "$column = " . q($val) . " COLLATE utf8_bin";
}
}
@ -417,7 +417,7 @@ function cookie($name, $value) {
global $HTTPS;
$params = array(
$name,
(ereg("\n", $value) ? "" : $value), // HTTP Response Splitting protection in PHP < 5.1.2
(preg_match("~\n~", $value) ? "" : $value), // HTTP Response Splitting protection in PHP < 5.1.2
time() + 2592000, // 2592000 - 30 days
preg_replace('~\\?.*~', '', $_SERVER["REQUEST_URI"]),
"",
@ -553,7 +553,7 @@ function queries($query = null) {
}
$start = microtime();
$return = $connection->query($query);
$queries[] = (ereg(';$', $query) ? "DELIMITER ;;\n$query;\nDELIMITER " : $query)
$queries[] = (preg_match('~;$~', $query) ? "DELIMITER ;;\n$query;\nDELIMITER " : $query)
. "; -- " . format_time($start, microtime());
return $return;
}
@ -632,13 +632,13 @@ function get_file($key, $decompress = false) {
}
$name = $file["name"][$key];
$tmp_name = $file["tmp_name"][$key];
$content = file_get_contents($decompress && ereg('\\.gz$', $name)
$content = file_get_contents($decompress && preg_match('~\\.gz$~', $name)
? "compress.zlib://$tmp_name"
: $tmp_name
); //! may not be reachable because of open_basedir
if ($decompress) {
$start = substr($content, 0, 3);
if (function_exists("iconv") && ereg("^\xFE\xFF|^\xFF\xFE", $start, $regs)) { // not ternary operator to save memory
if (function_exists("iconv") && preg_match("~^\xFE\xFF|^\xFF\xFE~", $start, $regs)) { // not ternary operator to save memory
$content = iconv("utf-16", "utf-8", $content);
} elseif ($start == "\xEF\xBB\xBF") { // UTF-8 BOM
$content = substr($content, 3);
@ -813,9 +813,9 @@ function input($field, $value, $function) {
$checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true));
echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . (1 << $i) . "'" . ($checked ? ' checked' : '') . "$onchange>" . h($adminer->editVal($val, $field)) . '</label>';
}
} elseif (ereg('blob|bytea|raw|file', $field["type"]) && ini_bool("file_uploads")) {
} elseif (preg_match('~blob|bytea|raw|file~', $field["type"]) && ini_bool("file_uploads")) {
echo "<input type='file' name='fields-$name'$onchange>";
} elseif (($text = ereg('text|lob', $field["type"])) || ereg("\n", $value)) {
} elseif (($text = preg_match('~text|lob~', $field["type"])) || preg_match("~\n~", $value)) {
if ($text && $jush != "sqlite") {
$attrs .= " cols='50' rows='12'";
} else {
@ -825,12 +825,12 @@ function input($field, $value, $function) {
echo "<textarea$attrs>" . h($value) . '</textarea>';
} else {
// int(3) is only a display hint
$maxlength = (!ereg('int', $field["type"]) && preg_match('~^(\\d+)(,(\\d+))?$~', $field["length"], $match) ? ((ereg("binary", $field["type"]) ? 2 : 1) * $match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0));
if ($jush == 'sql' && $connection->server_info >= 5.6 && ereg('time', $field["type"])) {
$maxlength = (!preg_match('~int~', $field["type"]) && preg_match('~^(\\d+)(,(\\d+))?$~', $field["length"], $match) ? ((preg_match("~binary~", $field["type"]) ? 2 : 1) * $match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0));
if ($jush == 'sql' && $connection->server_info >= 5.6 && preg_match('~time~', $field["type"])) {
$maxlength += 7; // microtime
}
// type='date' and type='time' display localized value which may be confusing, type='datetime' uses 'T' as date and time separator
echo "<input" . (ereg('int', $field["type"]) ? " type='number'" : "") . " value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "") . (ereg('char|binary', $field["type"]) && $maxlength > 20 ? " size='40'" : "") . "$attrs>";
echo "<input" . (preg_match('~int~', $field["type"]) ? " type='number'" : "") . " value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "") . (preg_match('~char|binary~', $field["type"]) && $maxlength > 20 ? " size='40'" : "") . "$attrs>";
}
}
}
@ -865,7 +865,7 @@ function process_input($field) {
if ($field["type"] == "set") {
return array_sum((array) $value);
}
if (ereg('blob|bytea|raw|file', $field["type"]) && ini_bool("file_uploads")) {
if (preg_match('~blob|bytea|raw|file~', $field["type"]) && ini_bool("file_uploads")) {
$file = get_file("fields-$idf");
if (!is_string($file)) {
return false; //! report errors
@ -913,7 +913,7 @@ function dump_headers($identifier, $multi_table = false) {
$return = $adminer->dumpHeaders($identifier, $multi_table);
$output = $_POST["output"];
if ($output != "text") {
header("Content-Disposition: attachment; filename=" . $adminer->dumpFilename($identifier) . ".$return" . ($output != "file" && !ereg('[^0-9a-z]', $output) ? ".$output" : ""));
header("Content-Disposition: attachment; filename=" . $adminer->dumpFilename($identifier) . ".$return" . ($output != "file" && !preg_match('~[^0-9a-z]~', $output) ? ".$output" : ""));
}
session_write_close();
ob_flush();
@ -1000,7 +1000,7 @@ function is_url($string) {
* @return bool
*/
function is_shortable($field) {
return ereg('char|text|lob|geometry|point|linestring|polygon|string', $field["type"]);
return preg_match('~char|text|lob|geometry|point|linestring|polygon|string~', $field["type"]);
}
/** Get query to compute number of found rows

View file

@ -2,7 +2,7 @@
$TABLE = $_GET["indexes"];
$index_types = array("PRIMARY", "UNIQUE", "INDEX");
$table_status = table_status($TABLE, true);
if (eregi("MyISAM|M?aria" . ($connection->server_info >= 5.6 ? "|InnoDB" : ""), $table_status["Engine"])) {
if (preg_match('~MyISAM|M?aria' . ($connection->server_info >= 5.6 ? '|InnoDB' : '') . '~i', $table_status["Engine"])) {
$index_types[] = "FULLTEXT";
}
$indexes = indexes($TABLE);
@ -32,7 +32,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
$descs[] = $desc;
}
}
if ($columns) {
$existing = $indexes[$name];
if ($existing) {
@ -53,7 +53,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
}
}
}
// drop removed indexes
foreach ($indexes as $name => $existing) {
$alter[] = array($existing["type"], $name, "DROP");
@ -101,7 +101,7 @@ $j = 1;
foreach ($row["indexes"] as $index) {
if (!$_POST["drop_col"] || $j != key($_POST["drop_col"])) {
echo "<tr><td>" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) ? "indexesAddRow(this);" : 1));
echo "<td>";
ksort($index["columns"]);
$i = 1;
@ -112,7 +112,7 @@ foreach ($row["indexes"] as $index) {
echo " </span>";
$i++;
}
echo "<td><input name='indexes[$j][name]' value='" . h($index["name"]) . "' autocapitalize='off'>\n";
echo "<td><input type='image' class='icon' name='drop_col[$j]' src='../adminer/static/cross.gif' alt='x' title='" . lang('Remove') . "' onclick=\"return !editingRemoveRow(this, 'indexes\$1[type]');\">\n";
}

View file

@ -18,7 +18,7 @@ page_header(lang('Process list'), $error);
// HTML valid because there is always at least one process
$i = -1;
foreach (process_list() as $i => $row) {
if (!$i) {
echo "<thead><tr lang='en'>" . (support("kill") ? "<th>&nbsp;" : "");
foreach ($row as $key => $val) {
@ -26,11 +26,11 @@ foreach (process_list() as $i => $row) {
}
echo "</thead>\n";
}
echo "<tr" . odd() . ">" . (support("kill") ? "<td>" . checkbox("kill[]", $row["Id"], 0) : "");
foreach ($row as $key => $val) {
echo "<td>" . (
($jush == "sql" && $key == "Info" && ereg("Query|Killed", $row["Command"]) && $val != "") ||
($jush == "sql" && $key == "Info" && preg_match("~Query|Killed~", $row["Command"]) && $val != "") ||
($jush == "pgsql" && $key == "current_query" && $val != "<IDLE>") ||
($jush == "oracle" && $key == "sql_text" && $val != "")
? "<code class='jush-$jush'>" . shorten_utf8($val, 100, "</code>") . ' <a href="' . h(ME . ($row["db"] != "" ? "db=" . urlencode($row["db"]) . "&" : "") . "sql=" . urlencode($val)) . '">' . lang('Clone') . '</a>'

View file

@ -63,7 +63,7 @@ if ($_POST && !$error) {
unset($unselected[$key]);
}
}
if ($_POST["export"]) {
cookie("adminer_import", "output=" . urlencode($_POST["output"]) . "&format=" . urlencode($_POST["format"]));
dump_headers($TABLE);
@ -81,7 +81,7 @@ if ($_POST && !$error) {
$adminer->dumpData($TABLE, "table", $query);
exit;
}
if (!$adminer->selectEmailProcess($where, $foreign_keys)) {
if ($_POST["save"] || $_POST["delete"]) { // edit
$result = true;
@ -135,7 +135,7 @@ if ($_POST && !$error) {
}
queries_redirect(remove_from_uri($_POST["all"] && $_POST["delete"] ? "page" : ""), $message, $result);
//! display edit page in case of an error
} elseif (!$_POST["import"]) { // modify
if (!$_POST["val"]) {
$error = lang('Ctrl+click on a value to modify it.');
@ -146,7 +146,7 @@ if ($_POST && !$error) {
$set = array();
foreach ($row as $key => $val) {
$key = bracket_escape($key, 1); // 1 - back
$set[idf_escape($key)] = (ereg('char|text', $fields[$key]["type"]) || $val != "" ? $adminer->processInput($fields[$key], $val) : "NULL");
$set[idf_escape($key)] = (preg_match('~char|text~', $fields[$key]["type"]) || $val != "" ? $adminer->processInput($fields[$key], $val) : "NULL");
}
$result = $driver->update(
$TABLE,
@ -162,7 +162,7 @@ if ($_POST && !$error) {
}
queries_redirect(remove_from_uri(), lang('%d item(s) have been affected.', $affected), $result);
}
} elseif (!is_string($file = get_file("csv_file", true))) {
$error = upload_error($file);
} elseif (!preg_match('~~u', $file)) {
@ -196,7 +196,7 @@ if ($_POST && !$error) {
}
queries_redirect(remove_from_uri("page"), lang('%d row(s) have been imported.', $affected), $result);
$driver->rollback(); // after queries_redirect() to not overwrite error
}
}
}
@ -214,7 +214,7 @@ if (isset($rights["insert"]) || !support("table")) {
$set = "";
foreach ((array) $_GET["where"] as $val) {
if (count($foreign_keys[$val["col"]]) == 1 && ($val["op"] == "="
|| (!$val["op"] && !ereg('[_%]', $val["val"])) // LIKE in Editor
|| (!$val["op"] && !preg_match('~[_%]~', $val["val"])) // LIKE in Editor
)) {
$set .= "&set" . urlencode("[" . bracket_escape($val["col"]) . "]") . "=" . urlencode($val["val"]);
}
@ -238,7 +238,7 @@ if (!$columns && support("table")) {
$adminer->selectLengthPrint($text_length);
$adminer->selectActionPrint($indexes);
echo "</form>\n";
$page = $_GET["page"];
if ($page == "last") {
$found_rows = $connection->result(count_rows($TABLE, $where, $is_group, $group));
@ -257,7 +257,7 @@ if (!$columns && support("table")) {
$select2[] = substr($convert_fields, 2);
}
$result = $driver->select($TABLE, $select2, $where, $group, $order, $limit, $page);
if (!$result) {
echo "<p class='error'>" . error() . "\n";
} else {
@ -273,17 +273,17 @@ if (!$columns && support("table")) {
}
$rows[] = $row;
}
// use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
if ($_GET["page"] != "last" && +$limit && $group && $is_group && $jush == "sql") {
$found_rows = $connection->result(" SELECT FOUND_ROWS()"); // space to allow mysql.trace_mode
}
if (!$rows) {
echo "<p class='message'>" . lang('No rows.') . "\n";
} else {
$backward_keys = $adminer->backwardKeys($TABLE, $table_name);
echo "<table id='table' cellspacing='0' class='nowrap checkable' onclick='tableClick(event);' ondblclick='tableClick(event, true);' onkeydown='return editingKeydown(event);'>\n";
echo "<thead><tr>" . (!$group && $select ? "" : "<td><input type='checkbox' id='all-page' onclick='formCheck(this, /check/);'> <a href='" . h($_GET["modify"] ? remove_from_uri("modify") : $_SERVER["REQUEST_URI"] . "&modify=1") . "'>" . lang('Modify') . "</a>");
$names = array();
@ -315,7 +315,7 @@ if (!$columns && support("table")) {
next($select);
}
}
$lengths = array();
if ($_GET["modify"]) {
foreach ($rows as $row) {
@ -324,16 +324,16 @@ if (!$columns && support("table")) {
}
}
}
echo ($backward_keys ? "<th>" . lang('Relations') : "") . "</thead>\n";
if (is_ajax()) {
if ($limit % 2 == 1 && $page % 2 == 1) {
odd();
}
ob_end_clean();
}
foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) {
$unique_array = unique_array($rows[$n], $indexes);
if (!$unique_array) {
@ -353,18 +353,18 @@ if (!$columns && support("table")) {
$unique_idf .= "&" . ($val !== null ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
}
echo "<tr" . odd() . ">" . (!$group && $select ? "" : "<td>" . checkbox("check[]", substr($unique_idf, 1), in_array(substr($unique_idf, 1), (array) $_POST["check"]), "", "this.form['all'].checked = false; formUncheck('all-page');") . ($is_group || information_schema(DB) ? "" : " <a href='" . h(ME . "edit=" . urlencode($TABLE) . $unique_idf) . "'>" . lang('edit') . "</a>"));
foreach ($row as $key => $val) {
if (isset($names[$key])) {
$field = $fields[$key];
if ($val != "" && (!isset($email_fields[$key]) || $email_fields[$key] != "")) {
$email_fields[$key] = (is_mail($val) ? $names[$key] : ""); //! filled e-mails can be contained on other pages
}
$link = "";
$val = $adminer->editVal($val, $field);
if ($val !== null) {
if (ereg('blob|bytea|raw|file', $field["type"]) && $val != "") {
if (preg_match('~blob|bytea|raw|file~', $field["type"]) && $val != "") {
$link = ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf;
}
if ($val === "") { // === - may be int
@ -374,7 +374,7 @@ if (!$columns && support("table")) {
} else {
$val = h($val);
}
if (!$link) { // link related items
foreach ((array) $foreign_keys[$key] as $foreign_key) {
if (count($foreign_keys[$key]) == 1 || end($foreign_key["source"]) == $key) {
@ -389,7 +389,7 @@ if (!$columns && support("table")) {
}
}
}
if ($key == "COUNT(*)") { //! columns looking like functions
$link = ME . "select=" . urlencode($TABLE);
$i = 0;
@ -402,9 +402,9 @@ if (!$columns && support("table")) {
$link .= where_link($i++, $k, $v);
}
}
}
if (!$link && ($link = $adminer->selectLink($row[$key], $field)) === null) {
if (is_mail($row[$key])) {
$link = "mailto:$row[$key]";
@ -416,33 +416,33 @@ if (!$columns && support("table")) {
);
}
}
$id = h("val[$unique_idf][" . bracket_escape($key) . "]");
$value = $_POST["val"][$unique_idf][bracket_escape($key)];
$h_value = h($value !== null ? $value : $row[$key]);
$long = strpos($val, "<i>...</i>");
$editable = is_utf8($val) && $rows[$n][$key] == $row[$key] && !$functions[$key];
$text = ereg('text|lob', $field["type"]);
$text = preg_match('~text|lob~', $field["type"]);
echo (($_GET["modify"] && $editable) || $value !== null
? "<td>" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>")
: "<td id='$id' onclick=\"selectClick(this, event, " . ($long ? 2 : ($text ? 1 : 0)) . ($editable ? "" : ", '" . h(lang('Use edit link to modify this value.')) . "'") . ");\">" . $adminer->selectVal($val, $link, $field)
);
}
}
if ($backward_keys) {
echo "<td>";
}
$adminer->backwardKeysPrint($backward_keys, $rows[$n]);
echo "</tr>\n"; // close to allow white-space: pre
}
if (is_ajax()) {
exit;
}
echo "</table>\n";
}
if (($rows || $page) && !is_ajax()) {
$exact_count = true;
if ($_GET["page"] != "last") {
@ -458,7 +458,7 @@ if (!$columns && support("table")) {
}
}
}
if (+$limit && ($found_rows === false || $found_rows > $limit || $page)) {
echo "<p class='pages'>";
// display first, previous 4, next 4 and last page
@ -490,12 +490,12 @@ if (!$columns && support("table")) {
echo ($max_page > $page ? pagination($page + 1, $page) . ($max_page > $page + 1 ? " ..." : "") : "");
}
}
echo "<p>\n";
echo ($found_rows !== false ? "(" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ") " : "");
$display_rows = ($exact_count ? "" : "~ ") . $found_rows;
echo checkbox("all", 1, 0, lang('whole result'), "var checked = formChecked(this, /check/); selectCount('selected', this.checked ? '$display_rows' : checked); selectCount('selected2', this.checked || !checked ? '$display_rows' : checked);") . "\n";
if ($adminer->selectCommandPrint()) {
?>
<fieldset<?php echo ($_GET["modify"] ? '' : ' class="jsonly"'); ?>><legend><?php echo lang('Modify'); ?></legend><div>
@ -508,7 +508,7 @@ if (!$columns && support("table")) {
</div></fieldset>
<?php
}
$format = $adminer->dumpFormat();
foreach ((array) $_GET["columns"] as $column) {
if ($column["fun"]) {
@ -524,10 +524,10 @@ if (!$columns && support("table")) {
echo " <input type='submit' name='export' value='" . lang('Export') . "'>\n";
echo "</div></fieldset>\n";
}
echo (!$group && $select ? "" : "<script type='text/javascript'>tableCheck();</script>\n");
}
if ($adminer->selectImportPrint()) {
print_fieldset("import", lang('Import'), !$rows);
echo "<input type='file' name='csv_file'> ";
@ -535,9 +535,9 @@ if (!$columns && support("table")) {
echo " <input type='submit' name='import' value='" . lang('Import') . "'>";
echo "</div></fieldset>\n";
}
$adminer->selectEmailPrint(array_filter($email_fields, 'strlen'), $columns);
echo "<p><input type='hidden' name='token' value='$token'></p>\n";
echo "</form>\n";
}

View file

@ -28,14 +28,14 @@ if (!$error && $_POST) {
} elseif ($_FILES && $_FILES["sql_file"]["error"][0] != 4) { // 4 - UPLOAD_ERR_NO_FILE
$query = get_file("sql_file", true);
}
if (is_string($query)) { // get_file() returns error as number, fread() as false
if (function_exists('memory_get_usage')) {
@ini_set("memory_limit", max(ini_bytes("memory_limit"), 2 * strlen($query) + memory_get_usage() + 8e6)); // @ - may be disabled, 2 - substr and trim, 8e6 - other variables
}
if ($query != "" && strlen($query) < 1e6) { // don't add big queries
$q = $query . (ereg(";[ \t\r\n]*\$", $query) ? "" : ";"); //! doesn't work with DELIMITER |
$q = $query . (preg_match("~;[ \t\r\n]*\$~", $query) ? "" : ";"); //! doesn't work with DELIMITER |
if (!$history || reset(end($history)) != $q) { // no repeated queries
restart_session();
$history[] = array($q, time());
@ -43,7 +43,7 @@ if (!$error && $_POST) {
stop_session();
}
}
$space = "(?:\\s|/\\*.*\\*/|(?:#|-- )[^\n]*\n|--\n)";
$delimiter = ";";
$offset = 0;
@ -60,7 +60,7 @@ if (!$error && $_POST) {
parse_str($_COOKIE["adminer_export"], $adminer_export);
$dump_format = $adminer->dumpFormat();
unset($dump_format["sql"]);
while ($query != "") {
if (!$offset && preg_match("~^$space*DELIMITER\\s+(\\S+)~i", $query, $match)) {
$delimiter = $match[1];
@ -75,9 +75,9 @@ if (!$error && $_POST) {
break;
}
$offset = $pos + strlen($found);
if ($found && rtrim($found) != $delimiter) { // find matching quote or comment end
while (preg_match('(' . ($found == '/*' ? '\\*/' : ($found == '[' ? ']' : (ereg('^-- |^#', $found) ? "\n" : preg_quote($found) . "|\\\\."))) . '|$)s', $query, $match, PREG_OFFSET_CAPTURE, $offset)) { //! respect sql_mode NO_BACKSLASH_ESCAPES
while (preg_match('(' . ($found == '/*' ? '\\*/' : ($found == '[' ? ']' : (preg_match('~^-- |^#~', $found) ? "\n" : preg_quote($found) . "|\\\\."))) . '|$)s', $query, $match, PREG_OFFSET_CAPTURE, $offset)) { //! respect sql_mode NO_BACKSLASH_ESCAPES
$s = $match[0][0];
if (!$s && $fp && !feof($fp)) {
$query .= fread($fp, 1e5);
@ -88,7 +88,7 @@ if (!$error && $_POST) {
}
}
}
} else { // end of a query
$empty = false;
$q = substr($query, 0, $pos);
@ -104,14 +104,14 @@ if (!$error && $_POST) {
if ($connection->multi_query($q) && is_object($connection2) && preg_match("~^$space*USE\\b~isU", $q)) {
$connection2->query($q);
}
do {
$result = $connection->store_result();
$end = microtime();
$time = " <span class='time'>(" . format_time($start, $end) . ")</span>"
. (strlen($q) < 1000 ? " <a href='" . h(ME) . "sql=" . urlencode(trim($q)) . "'>" . lang('Edit') . "</a>" : "") // 1000 - maximum length of encoded URL in IE is 2083 characters
;
if ($connection->error) {
echo ($_POST["only_errors"] ? $print : "");
echo "<p class='error'>" . lang('Error in query') . ($connection->errno ? " ($connection->errno)" : "") . ": " . error() . "\n";
@ -119,7 +119,7 @@ if (!$error && $_POST) {
if ($_POST["error_stops"]) {
break 2;
}
} elseif (is_object($result)) {
$orgtables = select($result, $connection2);
if (!$_POST["only_errors"]) {
@ -143,7 +143,7 @@ if (!$error && $_POST) {
}
echo "</form>\n";
}
} else {
if (preg_match("~^$space*(CREATE|DROP|ALTER)$space+(DATABASE|SCHEMA)\\b~isU", $q)) {
restart_session();
@ -154,19 +154,19 @@ if (!$error && $_POST) {
echo "<p class='message' title='" . h($connection->info) . "'>" . lang('Query executed OK, %d row(s) affected.', $connection->affected_rows) . "$time\n";
}
}
$start = $end;
} while ($connection->next_result());
$line += substr_count($q.$found, "\n");
$query = substr($query, $offset);
$offset = 0;
}
}
}
}
if ($empty) {
echo "<p class='message'>" . lang('No commands to execute.') . "\n";
} elseif ($_POST["only_errors"]) {
@ -176,7 +176,7 @@ if (!$error && $_POST) {
echo "<p class='error'>" . lang('Error in query') . ": " . implode("", $errors) . "\n";
}
//! MS SQL - SET SHOWPLAN_ALL OFF
} else {
echo "<p class='error'>" . upload_error($query) . "\n";
}

View file

@ -34,7 +34,7 @@ if (isset($_GET["host"]) && ($result = $connection->query("SHOW GRANTS FOR " . q
if ($val[1] != "USAGE") {
$grants["$match[2]$val[2]"][$val[1]] = true;
}
if (ereg(' WITH GRANT OPTION', $row[0])) { //! don't check inside strings and identifiers
if (preg_match('~ WITH GRANT OPTION~', $row[0])) { //! don't check inside strings and identifiers
$grants["$match[2]$val[2]"]["GRANT OPTION"] = true;
}
}
@ -57,7 +57,7 @@ if ($_POST && !$error) {
$pass = $connection->result("SELECT PASSWORD(" . q($pass) . ")");
$error = !$pass;
}
$created = false;
if (!$error) {
if ($old_user != $new_user) {
@ -67,7 +67,7 @@ if ($_POST && !$error) {
queries("SET PASSWORD FOR $new_user = " . q($pass));
}
}
if (!$error) {
$revoke = array();
foreach ($new_grants as $object => $grant) {
@ -93,7 +93,7 @@ if ($_POST && !$error) {
}
}
}
if (!$error && isset($_GET["host"])) {
if ($old_user != $new_user) {
queries("DROP USER $old_user");
@ -105,9 +105,9 @@ if ($_POST && !$error) {
}
}
}
queries_redirect(ME . "privileges=", (isset($_GET["host"]) ? lang('User has been altered.') : lang('User has been created.')), !$error);
if ($created) {
// delete new user in case of an error
$connection->query("DROP USER $new_user");

View file

@ -1,35 +1,35 @@
<?php
function adminer_object() {
class AdminerCds extends Adminer {
function name() {
// custom name in title and heading
return 'CDs';
}
function credentials() {
// ODBC user without password on localhost
return array('localhost', 'ODBC', '');
}
function database() {
// will be escaped by Adminer
return 'adminer_test';
}
function login($login, $password) {
// username: 'admin', password: anything
return ($login == 'admin');
}
function tableName($tableStatus) {
// tables without comments would return empty string and will be ignored by Adminer
return h($tableStatus["Comment"]);
}
function fieldName($field, $order = 0) {
if ($order && ereg('_(md5|sha1)$', $field["field"])) {
if ($order && preg_match('~_(md5|sha1)$~', $field["field"])) {
return ""; // hide hashes in select
}
// display only column with comments, first five of them plus searched columns
@ -43,9 +43,9 @@ function adminer_object() {
}
return "";
}
}
return new AdminerCds;
}

View file

@ -2,21 +2,21 @@
class Adminer {
var $operators = array("<=", ">=");
var $_values = array();
function name() {
return "<a href='http://www.adminer.org/editor/' id='h1'>" . lang('Editor') . "</a>";
}
//! driver, ns
function credentials() {
return array(SERVER, $_GET["username"], get_session("pwds"));
}
function permanentLogin($create = false) {
return password_file($create);
}
function database() {
global $connection;
if ($connection) {
@ -27,23 +27,23 @@ class Adminer {
);
}
}
function databases($flush = true) {
return get_databases($flush);
}
function queryTimeout() {
return 5;
}
function headers() {
return true;
}
function head() {
return true;
}
function loginForm() {
?>
<table cellspacing="0">
@ -57,32 +57,32 @@ focus(document.getElementById('username'));
echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
}
function login($login, $password) {
global $connection;
$connection->query("SET time_zone = " . q(substr_replace(@date("O"), ":", -2, 0))); // date("P") available since PHP 5.1.3, @ - requires date.timezone since PHP 5.3.0
return true;
}
function tableName($tableStatus) {
return h($tableStatus["Comment"] != "" ? $tableStatus["Comment"] : $tableStatus["Name"]);
}
function fieldName($field, $order = 0) {
return h($field["comment"] != "" ? $field["comment"] : $field["field"]);
}
function selectLinks($tableStatus, $set = "") {
$TABLE = $tableStatus["Name"];
if ($set !== null) {
echo '<p class="tabs"><a href="' . h(ME . 'edit=' . urlencode($TABLE) . $set) . '">' . lang('New item') . "</a>\n";
}
}
function foreignKeys($table) {
return foreign_keys($table);
}
function backwardKeys($table, $tableName) {
$return = array();
foreach (get_rows("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
@ -105,7 +105,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
}
return $return;
}
function backwardKeysPrint($backwardKeys, $row) {
foreach ($backwardKeys as $table => $backwardKey) {
foreach ($backwardKey["keys"] as $cols) {
@ -123,21 +123,21 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
}
}
}
function selectQuery($query) {
return "<!--\n" . str_replace("--", "--><!-- ", $query) . "\n-->\n";
}
function rowDescription($table) {
// first varchar column
foreach (fields($table) as $field) {
if (ereg("varchar|character varying", $field["type"])) {
if (preg_match("~varchar|character varying~", $field["type"])) {
return idf_escape($field["field"]);
}
}
return "";
}
function rowDescriptions($rows, $foreignKeys) {
$return = $rows;
foreach ($rows[0] as $key => $val) {
@ -162,16 +162,16 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
}
return $return;
}
function selectLink($val, $field) {
}
function selectVal($val, $link, $field) {
$return = ($val === null ? "&nbsp;" : $val);
$link = h($link);
if (ereg('blob|bytea', $field["type"]) && !is_utf8($val)) {
if (preg_match('~blob|bytea~', $field["type"]) && !is_utf8($val)) {
$return = lang('%d byte(s)', strlen($val));
if (ereg("^(GIF|\xFF\xD8\xFF|\x89PNG\x0D\x0A\x1A\x0A)", $val)) { // GIF|JPG|PNG, getimagetype() works with filename
if (preg_match("~^(GIF|\xFF\xD8\xFF|\x89PNG\x0D\x0A\x1A\x0A)~", $val)) { // GIF|JPG|PNG, getimagetype() works with filename
$return = "<img src='$link' alt='$return'>";
}
}
@ -181,25 +181,25 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
if ($link) {
$return = "<a href='$link'>$return</a>";
}
if (!$link && !like_bool($field) && ereg('int|float|double|decimal', $field["type"])) {
if (!$link && !like_bool($field) && preg_match('~int|float|double|decimal~', $field["type"])) {
$return = "<div class='number'>$return</div>"; // Firefox doesn't support <colgroup>
} elseif (ereg('date', $field["type"])) {
} elseif (preg_match('~date~', $field["type"])) {
$return = "<div class='datetime'>$return</div>";
}
return $return;
}
function editVal($val, $field) {
if (ereg('date|timestamp', $field["type"]) && $val !== null) {
if (preg_match('~date|timestamp~', $field["type"]) && $val !== null) {
return preg_replace('~^(\\d{2}(\\d+))-(0?(\\d+))-(0?(\\d+))~', lang('$1-$3-$5'), $val);
}
return $val;
}
function selectColumnsPrint($select, $columns) {
// can allow grouping functions by indexes
}
function selectSearchPrint($where, $columns, $indexes) {
$where = (array) $_GET["where"];
echo '<fieldset id="fieldset-search"><legend>' . lang('Search') . "</legend><div>\n";
@ -211,7 +211,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
$fields = fields($_GET["select"]);
foreach ($columns as $name => $desc) {
$field = $fields[$name];
if (ereg("enum", $field["type"]) || like_bool($field)) { //! set - uses 1 << $i and FIND_IN_SET()
if (preg_match("~enum~", $field["type"]) || like_bool($field)) { //! set - uses 1 << $i and FIND_IN_SET()
$key = $keys[$name];
$i--;
echo "<div>" . h($desc) . "<input type='hidden' name='where[$i][col]' value='" . h($name) . "'>:";
@ -245,7 +245,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
echo "<input type='search' name='where[$i][val]' onchange='selectAddRow(this);' onsearch='selectSearch(this);'></div>\n";
echo "</div></fieldset>\n";
}
function selectOrderPrint($order, $columns, $indexes) {
//! desc
$orders = array();
@ -270,30 +270,30 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
)) . "</div>\n";
}
}
function selectLimitPrint($limit) {
echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
echo html_select("limit", array("", "50", "100"), $limit);
echo "</div></fieldset>\n";
}
function selectLengthPrint($text_length) {
}
function selectActionPrint($indexes) {
echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
echo "<input type='submit' value='" . lang('Select') . "'>";
echo "</div></fieldset>\n";
}
function selectCommandPrint() {
return true;
}
function selectImportPrint() {
return true;
}
function selectEmailPrint($emailFields, $columns) {
if ($emailFields) {
print_fieldset("email", lang('E-mail'), $_POST["email_append"]);
@ -309,11 +309,11 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
echo "</div></fieldset>\n";
}
}
function selectColumnsProcess($columns, $indexes) {
return array(array(), array());
}
function selectSearchProcess($fields, $indexes) {
$return = array();
foreach ((array) $_GET["where"] as $key => $where) {
@ -323,13 +323,13 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
if (($key < 0 ? "" : $col) . $val != "") {
$conds = array();
foreach (($col != "" ? array($col => $fields[$col]) : $fields) as $name => $field) {
if ($col != "" || is_numeric($val) || !ereg('int|float|double|decimal', $field["type"])) {
if ($col != "" || is_numeric($val) || !preg_match('~int|float|double|decimal~', $field["type"])) {
$name = idf_escape($name);
if ($col != "" && $field["type"] == "enum") {
$conds[] = (in_array(0, $val) ? "$name IS NULL OR " : "") . "$name IN (" . implode(", ", array_map('intval', $val)) . ")";
} else {
$text_type = ereg('char|text|enum|set', $field["type"]);
$value = $this->processInput($field, (!$op && $text_type && ereg('^[^%]+$', $val) ? "%$val%" : $val));
$text_type = preg_match('~char|text|enum|set~', $field["type"]);
$value = $this->processInput($field, (!$op && $text_type && preg_match('~^[^%]+$~', $val) ? "%$val%" : $val));
$conds[] = $name . ($value == "NULL" ? " IS" . ($op == ">=" ? " NOT" : "") . " $value"
: (in_array($op, $this->operators) || $op == "=" ? " $op $value"
: ($text_type ? " LIKE $value"
@ -346,7 +346,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
}
return $return;
}
function selectOrderProcess($fields, $indexes) {
$index_order = $_GET["index_order"];
if ($index_order != "") {
@ -360,7 +360,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
$has_desc = array_filter($index["descs"]);
$desc = false;
foreach ($index["columns"] as $val) {
if (ereg('date|timestamp', $fields[$val]["type"])) {
if (preg_match('~date|timestamp~', $fields[$val]["type"])) {
$desc = true;
break;
}
@ -374,15 +374,15 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
}
return array();
}
function selectLimitProcess() {
return (isset($_GET["limit"]) ? $_GET["limit"] : "50");
}
function selectLengthProcess() {
return "100";
}
function selectEmailProcess($where, $foreignKeys) {
if ($_POST["email_append"]) {
return true;
@ -416,31 +416,31 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
}
return false;
}
function selectQueryBuild($select, $where, $group, $order, $limit, $page) {
return "";
}
function messageQuery($query) {
return " <span class='time'>" . @date("H:i:s") . "</span><!--\n" . str_replace("--", "--><!-- ", $query) . "\n-->";
}
function editFunctions($field) {
$return = array();
if ($field["null"] && ereg('blob', $field["type"])) {
if ($field["null"] && preg_match('~blob~', $field["type"])) {
$return["NULL"] = lang('empty');
}
$return[""] = ($field["null"] || $field["auto_increment"] || like_bool($field) ? "" : "*");
//! respect driver
if (ereg('date|time', $field["type"])) {
if (preg_match('~date|time~', $field["type"])) {
$return["now"] = lang('now');
}
if (eregi('_(md5|sha1)$', $field["field"], $match)) {
if (preg_match('~_(md5|sha1)$~i', $field["field"], $match)) {
$return[] = strtolower($match[1]);
}
return $return;
}
function editInput($table, $field, $attrs, $value) {
if ($field["type"] == "enum") {
return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
@ -458,55 +458,55 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
return '<input type="checkbox" value="' . h($value ? $value : 1) . '"' . ($value ? ' checked' : '') . "$attrs>";
}
$hint = "";
if (ereg('time', $field["type"])) {
if (preg_match('~time~', $field["type"])) {
$hint = lang('HH:MM:SS');
}
if (ereg('date|timestamp', $field["type"])) {
if (preg_match('~date|timestamp~', $field["type"])) {
$hint = lang('[yyyy]-mm-dd') . ($hint ? " [$hint]" : "");
}
if ($hint) {
return "<input value='" . h($value) . "'$attrs> ($hint)"; //! maxlength
}
if (eregi('_(md5|sha1)$', $field["field"])) {
if (preg_match('~_(md5|sha1)$~i', $field["field"])) {
return "<input type='password' value='" . h($value) . "'$attrs>";
}
return '';
}
function processInput($field, $value, $function = "") {
if ($function == "now") {
return "$function()";
}
$return = $value;
if (ereg('date|timestamp', $field["type"]) && preg_match('(^' . str_replace('\\$1', '(?P<p1>\\d*)', preg_replace('~(\\\\\\$([2-6]))~', '(?P<p\\2>\\d{1,2})', preg_quote(lang('$1-$3-$5')))) . '(.*))', $value, $match)) {
if (preg_match('~date|timestamp~', $field["type"]) && preg_match('(^' . str_replace('\\$1', '(?P<p1>\\d*)', preg_replace('~(\\\\\\$([2-6]))~', '(?P<p\\2>\\d{1,2})', preg_quote(lang('$1-$3-$5')))) . '(.*))', $value, $match)) {
$return = ($match["p1"] != "" ? $match["p1"] : ($match["p2"] != "" ? ($match["p2"] < 70 ? 20 : 19) . $match["p2"] : gmdate("Y"))) . "-$match[p3]$match[p4]-$match[p5]$match[p6]" . end($match);
}
$return = ($field["type"] == "bit" && ereg('^[0-9]+$', $value) ? $return : q($return));
$return = ($field["type"] == "bit" && preg_match('~^[0-9]+$~', $value) ? $return : q($return));
if ($value == "" && like_bool($field)) {
$return = "0";
} elseif ($value == "" && ($field["null"] || !ereg('char|text', $field["type"]))) {
} elseif ($value == "" && ($field["null"] || !preg_match('~char|text~', $field["type"]))) {
$return = "NULL";
} elseif (ereg('^(md5|sha1)$', $function)) {
} elseif (preg_match('~^(md5|sha1)$~', $function)) {
$return = "$function($return)";
}
return unconvert_field($field, $return);
}
function dumpOutput() {
return array();
}
function dumpFormat() {
return array('csv' => 'CSV,', 'csv;' => 'CSV;', 'tsv' => 'TSV');
}
function dumpDatabase($db) {
}
function dumpTable() {
echo "\xef\xbb\xbf"; // UTF-8 byte order mark
}
function dumpData($table, $style, $query) {
global $connection;
$result = $connection->query($query, 1); // 1 - MYSQLI_USE_RESULT
@ -520,21 +520,21 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
}
}
}
function dumpFilename($identifier) {
return friendly_url($identifier);
}
function dumpHeaders($identifier, $multi_table = false) {
$ext = "csv";
header("Content-Type: text/csv; charset=utf-8");
return $ext;
}
function homepage() {
return true;
}
function navigation($missing) {
global $VERSION;
?>
@ -566,10 +566,10 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
}
}
}
function databasesPrint($missing) {
}
function tablesPrint($tables) {
echo "<p id='tables' onmouseover='menuOver(this, event);' onmouseout='menuOut(this);'>\n";
foreach ($tables as $row) {
@ -579,7 +579,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
}
}
}
function _foreignColumn($foreignKeys, $column) {
foreach ((array) $foreignKeys[$column] as $foreignKey) {
if (count($foreignKey["source"]) == 1) {
@ -591,7 +591,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
}
}
}
function _foreignKeyOptions($table, $column, $value = null) {
global $connection;
if (list($target, $id, $name) = $this->_foreignColumn(column_foreign_keys($table), $column)) {

View file

@ -49,5 +49,5 @@ function send_mail($email, $subject, $message, $from = "", $files = array()) {
* @return bool
*/
function like_bool($field) {
return ereg("bool|(tinyint|bit)\\(1\\)", $field["full_type"]);
return preg_match("~bool|(tinyint|bit)\\(1\\)~", $field["full_type"]);
}

View file

@ -4,7 +4,7 @@ if ($_GET["script"] == "kill") {
} elseif (list($table, $id, $name) = $adminer->_foreignColumn(column_foreign_keys($_GET["source"]), $_GET["field"])) {
$limit = 11;
$result = $connection->query("SELECT $id, $name FROM " . table($table) . " WHERE " . (ereg('^[0-9]+$', $_GET["value"]) ? "$id = $_GET[value] OR " : "") . "$name LIKE " . q("$_GET[value]%") . " ORDER BY 2 LIMIT $limit");
$result = $connection->query("SELECT $id, $name FROM " . table($table) . " WHERE " . (preg_match('~^[0-9]+$~', $_GET["value"]) ? "$id = $_GET[value] OR " : "") . "$name LIKE " . q("$_GET[value]%") . " ORDER BY 2 LIMIT $limit");
for ($i=1; ($row = $result->fetch_row()) && $i < $limit; $i++) {
echo "<a href='" . h(ME . "edit=" . urlencode($table) . "&where" . urlencode("[" . bracket_escape(idf_unescape($id)) . "]") . "=" . urlencode($row[0])) . "'>" . h($row[1]) . "</a><br>\n";
}

View file

@ -10,14 +10,14 @@
class AdminerDumpZip {
/** @access protected */
var $filename, $data;
function dumpOutput() {
if (!class_exists('ZipArchive')) {
return array();
}
return array('zip' => 'ZIP');
}
function _zip($string, $state) {
// ZIP can be created without temporary file by gzcompress - see PEAR File_Archive
$this->data .= $string;
@ -33,10 +33,10 @@ class AdminerDumpZip {
}
return "";
}
function dumpHeaders($identifier, $multi_table = false) {
if ($_POST["output"] == "zip") {
$this->filename = "$identifier." . ($multi_table && ereg("[ct]sv", $_POST["format"]) ? "tar" : $_POST["format"]);
$this->filename = "$identifier." . ($multi_table && preg_match("~[ct]sv~", $_POST["format"]) ? "tar" : $_POST["format"]);
header("Content-Type: application/zip");
ob_start(array($this, '_zip'));
}

View file

@ -11,7 +11,7 @@
class AdminerEditCalendar {
/** @access protected */
var $prepend, $langPath;
/**
* @param string text to append before first calendar usage
* @param string path to language file, %s stands for language code
@ -20,7 +20,7 @@ class AdminerEditCalendar {
$this->prepend = $prepend;
$this->langPath = $langPath;
}
function head() {
echo $this->prepend;
if ($this->langPath && function_exists('get_lang')) { // since Adminer 3.2.0
@ -32,17 +32,17 @@ class AdminerEditCalendar {
}
}
}
function editInput($table, $field, $attrs, $value) {
if (ereg("date|time", $field["type"])) {
if (preg_match("~date|time~", $field["type"])) {
$dateFormat = "changeYear: true, dateFormat: 'yy-mm-dd'"; //! yy-mm-dd regional
$timeFormat = "showSecond: true, timeFormat: 'hh:mm:ss'";
return "<input id='fields-" . h($field["field"]) . "' value='" . h($value) . "'" . (+$field["length"] ? " maxlength='" . (+$field["length"]) . "'" : "") . "$attrs><script type='text/javascript'>jQuery('#fields-" . js_escape($field["field"]) . "')."
. ($field["type"] == "time" ? "timepicker({ $timeFormat })"
: (ereg("time", $field["type"]) ? "datetimepicker({ $dateFormat, $timeFormat })"
: (preg_match("~time~", $field["type"]) ? "datetimepicker({ $dateFormat, $timeFormat })"
: "datepicker({ $dateFormat })"
)) . ";</script>";
}
}
}

View file

@ -7,11 +7,11 @@
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerEditTextarea {
function editInput($table, $field, $attrs, $value) {
if (ereg('char', $field["type"])) {
if (preg_match('~char~', $field["type"])) {
return "<textarea cols='30' rows='1' style='height: 1.2em;'$attrs>" . h($value) . '</textarea>';
}
}
}

View file

@ -10,7 +10,7 @@
class AdminerFileUpload {
/** @access protected */
var $uploadPath, $displayPath, $extensions;
/**
* @param string prefix for uploading data (create writable subdirectory for each table containing uploadable fields)
* @param string prefix for displaying data, null stands for $uploadPath
@ -21,18 +21,18 @@ class AdminerFileUpload {
$this->displayPath = ($displayPath !== null ? $displayPath : $uploadPath);
$this->extensions = $extensions;
}
function editInput($table, $field, $attrs, $value) {
if (ereg('(.*)_path$', $field["field"])) {
if (preg_match('~(.*)_path$~', $field["field"])) {
return "<input type='file' name='fields-$field[field]'>";
}
}
function processInput($field, $value, $function = "") {
if (ereg('(.*)_path$', $field["field"], $regs)) {
if (preg_match('~(.*)_path$~', $field["field"], $regs)) {
$table = ($_GET["edit"] != "" ? $_GET["edit"] : $_GET["select"]);
$name = "fields-$field[field]";
if ($_FILES[$name]["error"] || !ereg("(\\.($this->extensions))?\$", $_FILES[$name]["name"], $regs2)) {
if ($_FILES[$name]["error"] || !preg_match("~(\\.($this->extensions))?\$~", $_FILES[$name]["name"], $regs2)) {
return false;
}
//! unlink old
@ -43,11 +43,11 @@ class AdminerFileUpload {
return q($filename);
}
}
function selectVal($val, &$link, $field) {
if ($val != "&nbsp;" && ereg('(.*)_path$', $field["field"], $regs)) {
if ($val != "&nbsp;" && preg_match('~(.*)_path$~', $field["field"], $regs)) {
$link = "$this->displayPath$_GET[select]/$regs[1]-$val";
}
}
}

View file

@ -9,7 +9,7 @@
class AdminerSlugify {
/** @access protected */
var $from, $to;
/**
* @param string find these characters ...
* @param string ... and replace them by these
@ -18,7 +18,7 @@ class AdminerSlugify {
$this->from = $from;
$this->to = $to;
}
function editInput($table, $field, $attrs, $value) {
static $slugify;
if (!$_GET["select"] && !$_GET["where"]) {
@ -26,7 +26,7 @@ class AdminerSlugify {
$slugify = array();
$prev = null;
foreach (fields($table) as $name => $val) {
if ($prev && ereg('(^|_)slug(_|$)', $name)) {
if ($prev && preg_match('~(^|_)slug(_|$)~', $name)) {
$slugify[$prev] = $name;
}
$prev = $name;
@ -38,5 +38,5 @@ class AdminerSlugify {
}
}
}
}

View file

@ -10,14 +10,14 @@
class AdminerTinymce {
/** @access protected */
var $path;
/**
* @param string
*/
function AdminerTinymce($path = "tiny_mce/tiny_mce.js") {
$this->path = $path;
}
function head() {
$lang = "en";
if (function_exists('get_lang')) { // since Adminer 3.2.0
@ -45,9 +45,9 @@ tinyMCE.init({
</script>
<?php
}
function selectVal(&$val, $link, $field) {
if (ereg("_html", $field["field"]) && $val != '&nbsp;') {
if (preg_match("~_html~", $field["field"]) && $val != '&nbsp;') {
$shortened = (substr($val, -10) == "<i>...</i>");
if ($shortened) {
$val = substr($val, 0, -10);
@ -65,9 +65,9 @@ tinyMCE.init({
}
}
}
function editInput($table, $field, $attrs, $value) {
if (ereg("text", $field["type"]) && ereg("_html", $field["field"])) {
if (preg_match("~text~", $field["type"]) && preg_match("~_html~", $field["field"])) {
return "<textarea$attrs id='fields-" . h($field["field"]) . "' rows='12' cols='50'>" . h($value) . "</textarea><script type='text/javascript'>
tinyMCE.remove(tinyMCE.get('fields-" . js_escape($field["field"]) . "') || { });
tinyMCE.execCommand('mceAddControl', true, 'fields-" . js_escape($field["field"]) . "');
@ -79,5 +79,5 @@ document.getElementById('form').onsubmit = function () {
</script>";
}
}
}

View file

@ -10,7 +10,7 @@
class AdminerWymeditor {
/** @access protected */
var $scripts, $options;
/**
* @param array
* @param string in format "skin: 'custom', preInit: function () { }"
@ -19,16 +19,16 @@ class AdminerWymeditor {
$this->scripts = $scripts;
$this->options = $options;
}
function head() {
foreach ($this->scripts as $script) {
echo "<script type='text/javascript' src='" . h($script) . "'></script>\n";
}
}
function selectVal(&$val, $link, $field) {
// copied from tinymce.php
if (ereg("_html", $field["field"]) && $val != '&nbsp;') {
if (preg_match("~_html~", $field["field"]) && $val != '&nbsp;') {
$shortened = (substr($val, -10) == "<i>...</i>");
if ($shortened) {
$val = substr($val, 0, -10);
@ -46,10 +46,10 @@ class AdminerWymeditor {
}
}
}
function editInput($table, $field, $attrs, $value) {
static $lang = "";
if (!$lang && ereg("text", $field["type"]) && ereg("_html", $field["field"])) {
if (!$lang && preg_match("~text~", $field["type"]) && preg_match("~_html~", $field["field"])) {
$lang = "en";
if (function_exists('get_lang')) { // since Adminer 3.2.0
$lang = get_lang();
@ -60,5 +60,5 @@ jQuery('#fields-" . js_escape($field["field"]) . "').wymeditor({ updateSelector:
</script>";
}
}
}