Skip to content

Commit

Permalink
Driver specific INSERT INTO
Browse files Browse the repository at this point in the history
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1484 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information
jakubvrana committed Apr 23, 2010
1 parent e780f9b commit 341362a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
9 changes: 9 additions & 0 deletions adminer/drivers/mysql.inc.php
Expand Up @@ -680,6 +680,15 @@ function trigger_options() {
); );
} }


/** 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 /** Explain select
* @param Min_DB * @param Min_DB
* @param string * @param string
Expand Down
4 changes: 4 additions & 0 deletions adminer/drivers/pgsql.inc.php
Expand Up @@ -440,6 +440,10 @@ function trigger_options() {
); );
} }


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) { function explain($connection, $query) {
return $connection->query("EXPLAIN $query"); return $connection->query("EXPLAIN $query");
} }
Expand Down
4 changes: 4 additions & 0 deletions adminer/drivers/sqlite.inc.php
Expand Up @@ -474,6 +474,10 @@ function trigger_options() {
); );
} }


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) { function explain($connection, $query) {
return $connection->query("EXPLAIN $query"); return $connection->query("EXPLAIN $query");
} }
Expand Down
2 changes: 1 addition & 1 deletion adminer/edit.inc.php
Expand Up @@ -31,7 +31,7 @@
} }
query_redirect("UPDATE" . limit1(idf_escape($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where"), $location, lang('Item has been updated.')); query_redirect("UPDATE" . limit1(idf_escape($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where"), $location, lang('Item has been updated.'));
} else { } 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));
} }
} }
} }
Expand Down
10 changes: 5 additions & 5 deletions adminer/include/functions.inc.php
Expand Up @@ -193,11 +193,11 @@ function unique_array($row, $indexes) {
*/ */
function where($where) { function where($where) {
$return = array(); $return = array();
foreach (array("where", "null") as $type) { foreach ((array) $where["where"] as $key => $val) {
foreach ((array) $where[$type] 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
$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["null"] as $key) {
} $return[] = idf_escape($key) . " IS NULL";
} }
return implode(" AND ", $return); return implode(" AND ", $return);
} }
Expand Down

0 comments on commit 341362a

Please sign in to comment.