1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-18 04:11:27 +02:00

Save bytes ($connection->quote shortcut)

This commit is contained in:
Jakub Vrana
2010-10-13 18:04:40 +02:00
parent b0d637b638
commit 7e644b4346
16 changed files with 89 additions and 123 deletions

View File

@@ -304,11 +304,11 @@ document.getElementById('username').focus();
* @return array expressions to join by AND
*/
function selectSearchProcess($fields, $indexes) {
global $connection, $jush;
global $jush;
$return = array();
foreach ($indexes as $i => $index) {
if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") {
$return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . $connection->quote($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
$return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . q($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
}
}
foreach ((array) $_GET["where"] as $val) {
@@ -436,9 +436,8 @@ document.getElementById('username').focus();
* @return string expression to use in a query
*/
function processInput($field, $value, $function = "") {
global $connection;
$name = $field["field"];
$return = $connection->quote($value);
$return = q($value);
if (ereg('^(now|getdate|uuid)$', $function)) {
$return = "$function()";
} elseif (ereg('^current_(date|timestamp)$', $function)) {

View File

@@ -139,11 +139,11 @@ function process_length($length) {
* @return string
*/
function process_type($field, $collate = "COLLATE") {
global $connection, $unsigned;
global $unsigned;
return " $field[type]"
. ($field["length"] != "" ? "(" . process_length($field["length"]) . ")" : "")
. (ereg('int|float|double|decimal', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
. (ereg('char|text|enum|set', $field["type"]) && $field["collation"] ? " $collate " . $connection->quote($field["collation"]) : "")
. (ereg('char|text|enum|set', $field["type"]) && $field["collation"] ? " $collate " . q($field["collation"]) : "")
;
}
@@ -153,14 +153,13 @@ function process_type($field, $collate = "COLLATE") {
* @return array array("field", "type", "NULL", "DEFAULT", "ON UPDATE", "COMMENT", "AUTO_INCREMENT")
*/
function process_field($field, $type_field) {
global $connection;
return array(
idf_escape($field["field"]),
process_type($type_field),
($field["null"] ? " NULL" : " NOT NULL"), // NULL for timestamp
(isset($field["default"]) ? " DEFAULT " . ($field["type"] == "timestamp" && eregi("^CURRENT_TIMESTAMP$", $field["default"]) ? $field["default"] : $connection->quote($field["default"])) : ""),
(isset($field["default"]) ? " DEFAULT " . ($field["type"] == "timestamp" && eregi("^CURRENT_TIMESTAMP$", $field["default"]) ? $field["default"] : q($field["default"])) : ""),
($field["on_update"] ? " ON UPDATE $field[on_update]" : ""),
(support("comment") && $field["comment"] != "" ? " COMMENT " . $connection->quote($field["comment"]) : ""),
(support("comment") && $field["comment"] != "" ? " COMMENT " . q($field["comment"]) : ""),
($field["auto_increment"] ? auto_increment() : null),
);
}

View File

@@ -10,7 +10,6 @@ function tar_file($filename, $contents) {
}
function dump_table($table, $style, $is_view = false) {
global $connection;
if ($_POST["format"] != "sql") {
echo "\xef\xbb\xbf"; // UTF-8 byte order mark
if ($style) {
@@ -30,7 +29,7 @@ function dump_table($table, $style, $is_view = false) {
}
if ($style == "CREATE+ALTER" && !$is_view) {
// create procedure which iterates over original columns and adds new and removes old
$query = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLLATION_NAME, COLUMN_TYPE, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = " . $connection->quote($table) . " ORDER BY ORDINAL_POSITION";
$query = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLLATION_NAME, COLUMN_TYPE, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = " . q($table) . " ORDER BY ORDINAL_POSITION";
echo "DELIMITER ;;
CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
DECLARE _column_name, _collation_name, after varchar(64) DEFAULT '';
@@ -44,15 +43,15 @@ CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
$after = "";
foreach (get_rows($query) as $row) {
$default = $row["COLUMN_DEFAULT"];
$row["default"] = (isset($default) ? $connection->quote($default) : "NULL");
$row["after"] = $connection->quote($after); //! rgt AFTER lft, lft AFTER id doesn't work
$row["default"] = (isset($default) ? q($default) : "NULL");
$row["after"] = q($after); //! rgt AFTER lft, lft AFTER id doesn't work
$row["alter"] = escape_string(idf_escape($row["COLUMN_NAME"])
. " $row[COLUMN_TYPE]"
. ($row["COLLATION_NAME"] ? " COLLATE $row[COLLATION_NAME]" : "")
. (isset($default) ? " DEFAULT " . ($default == "CURRENT_TIMESTAMP" ? $default : $row["default"]) : "")
. ($row["IS_NULLABLE"] == "YES" ? "" : " NOT NULL")
. ($row["EXTRA"] ? " $row[EXTRA]" : "")
. ($row["COLUMN_COMMENT"] ? " COMMENT " . $connection->quote($row["COLUMN_COMMENT"]) : "")
. ($row["COLUMN_COMMENT"] ? " COMMENT " . q($row["COLUMN_COMMENT"]) : "")
. ($after ? " AFTER " . idf_escape($after) : " FIRST")
);
echo ", ADD $row[alter]";
@@ -71,9 +70,9 @@ CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
CASE _column_name";
foreach ($fields as $row) {
echo "
WHEN " . $connection->quote($row["COLUMN_NAME"]) . " THEN
WHEN " . q($row["COLUMN_NAME"]) . " THEN
SET add_columns = REPLACE(add_columns, ', ADD $row[alter]', '');
IF NOT (_column_default <=> $row[default]) OR _is_nullable != '$row[IS_NULLABLE]' OR _collation_name != '$row[COLLATION_NAME]' OR _column_type != " . $connection->quote($row["COLUMN_TYPE"]) . " OR _extra != '$row[EXTRA]' OR _column_comment != " . $connection->quote($row["COLUMN_COMMENT"]) . " OR after != $row[after] THEN
IF NOT (_column_default <=> $row[default]) OR _is_nullable != '$row[IS_NULLABLE]' OR _collation_name != '$row[COLLATION_NAME]' OR _column_type != " . q($row["COLUMN_TYPE"]) . " OR _extra != '$row[EXTRA]' OR _column_comment != " . q($row["COLUMN_COMMENT"]) . " OR after != $row[after] THEN
SET @alter_table = CONCAT(@alter_table, ', MODIFY $row[alter]');
END IF;"; //! don't replace in comment
}
@@ -122,7 +121,7 @@ function dump_data($table, $style, $select = "") {
$insert = "INSERT INTO " . table($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
}
foreach ($row as $key => $val) {
$row[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : $connection->quote($val)) : "NULL"); //! columns looking like functions
$row[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : q($val)) : "NULL"); //! columns looking like functions
}
$s = implode(",\t", $row);
if ($style == "INSERT+UPDATE") {

View File

@@ -22,8 +22,7 @@ function idf_unescape($idf) {
* @return string
*/
function escape_string($val) {
global $connection;
return substr($connection->quote($val), 1, -1);
return substr(q($val), 1, -1);
}
/** Disable magic_quotes_gpc
@@ -149,6 +148,11 @@ function ini_bool($ini) {
return (eregi('^(on|true|yes)$', $val) || (int) $val); // boolean values set by php_value are strings
}
function q($string) {
global $connection;
return $connection->quote($string);
}
/** Get list of values from database
* @param string
* @param mixed
@@ -609,7 +613,7 @@ function input($field, $value, $function) {
* @return string
*/
function process_input($field) {
global $connection, $adminer;
global $adminer;
$idf = bracket_escape($field["field"]);
$function = $_POST["function"][$idf];
$value = $_POST["fields"][$idf];
@@ -639,7 +643,7 @@ function process_input($field) {
if (!is_string($file)) {
return false; //! report errors
}
return $connection->quote($file);
return q($file);
}
return $adminer->processInput($field, $value, $function);
}