From 341362a8fa9b21ba2ec2aa3c023db37cd52b93a8 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Fri, 23 Apr 2010 09:03:27 +0000 Subject: [PATCH] Driver specific INSERT INTO git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1484 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/drivers/mysql.inc.php | 9 +++++++++ adminer/drivers/pgsql.inc.php | 4 ++++ adminer/drivers/sqlite.inc.php | 4 ++++ adminer/edit.inc.php | 2 +- adminer/include/functions.inc.php | 10 +++++----- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index c429bde4..e11bd75b 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -680,6 +680,15 @@ if (!defined("DRIVER")) { ); } + /** Insert data into table + * @param string + * @param array + * @return bool + */ + function insert_into($table, $set) { + return queries("INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")"); + } + /** Explain select * @param Min_DB * @param string diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 611977fa..ae2c5adc 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -440,6 +440,10 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu ); } + function insert_into($table, $set) { + return queries("INSERT INTO " . idf_escape($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES")); + } + function explain($connection, $query) { return $connection->query("EXPLAIN $query"); } diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index d5cdef56..5563912a 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -474,6 +474,10 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { ); } + function insert_into($table, $set) { + return queries("INSERT INTO " . idf_escape($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES")); + } + function explain($connection, $query) { return $connection->query("EXPLAIN $query"); } diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index cef053e0..a411585a 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -31,7 +31,7 @@ if ($_POST && !$error && !isset($_GET["select"])) { } query_redirect("UPDATE" . limit1(idf_escape($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where"), $location, lang('Item has been updated.')); } else { - query_redirect("INSERT INTO " . idf_escape($TABLE) . " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")", $location, lang('Item has been inserted.')); + queries_redirect($location, lang('Item has been inserted.'), insert_into($TABLE, $set)); } } } diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 8374b835..0fda9145 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -193,11 +193,11 @@ function unique_array($row, $indexes) { */ function where($where) { $return = array(); - foreach (array("where", "null") as $type) { - foreach ((array) $where[$type] as $key => $val) { - $key = bracket_escape($key, "back"); - $return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . ($type == "null" ? " IS NULL" : (ereg('\\.', $val) ? " LIKE " . exact_value(addcslashes($val, "%_")) : " = " . exact_value($val))); // LIKE because of floats, but slow with ints //! enum and set, columns looking like functions - } + foreach ((array) $where["where"] as $key => $val) { + $return[] = idf_escape($key) . (ereg('\\.', $val) ? " LIKE " . exact_value(addcslashes($val, "%_")) : " = " . exact_value($val)); // LIKE because of floats, but slow with ints //! enum and set + } + foreach ((array) $where["null"] as $key) { + $return[] = idf_escape($key) . " IS NULL"; } return implode(" AND ", $return); }