Display auto_increment value of inserted item

This commit is contained in:
Jakub Vrana 2010-05-12 18:07:46 +02:00
parent 22eb69b562
commit 29e7f041a3
7 changed files with 28 additions and 3 deletions

View file

@ -409,6 +409,11 @@ WHERE OBJECT_NAME(indexes.object_id) = " . $connection2->quote($table)
return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES")); return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
} }
function last_id() {
global $connection;
return $connection->result("SELECT SCOPE_IDENTITY()"); // @@IDENTITY can return trigger INSERT
}
function explain($connection, $query) { function explain($connection, $query) {
$connection->query("SET SHOWPLAN_ALL ON"); $connection->query("SET SHOWPLAN_ALL ON");
$return = $connection->query($query); $return = $connection->query($query);

View file

@ -769,6 +769,14 @@ if (!defined("DRIVER")) {
return queries("INSERT INTO " . table($table) . " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")"); return queries("INSERT INTO " . table($table) . " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")");
} }
/** Get last auto increment ID
* @return string
*/
function last_id() {
global $connection;
return $connection->result("SELECT LAST_INSERT_ID()"); // mysql_insert_id() truncates bigint
}
/** Explain select /** Explain select
* @param Min_DB * @param Min_DB
* @param string * @param string

View file

@ -466,6 +466,10 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES")); return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
} }
function last_id() {
return 0; // there can be several sequences
}
function explain($connection, $query) { function explain($connection, $query) {
return $connection->query("EXPLAIN $query"); return $connection->query("EXPLAIN $query");
} }

View file

@ -500,6 +500,11 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES")); return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
} }
function last_id() {
global $connection;
return $connection->result("SELECT LAST_INSERT_ROWID()");
}
function explain($connection, $query) { function explain($connection, $query) {
return $connection->query("EXPLAIN $query"); return $connection->query("EXPLAIN $query");
} }

View file

@ -31,7 +31,9 @@ if ($_POST && !$error && !isset($_GET["select"])) {
} }
query_redirect("UPDATE" . limit1(table($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where"), $location, lang('Item has been updated.')); query_redirect("UPDATE" . limit1(table($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where"), $location, lang('Item has been updated.'));
} else { } else {
queries_redirect($location, lang('Item has been inserted.'), insert_into($TABLE, $set)); $result = insert_into($TABLE, $set);
$last_id = ($result ? last_id() : 0);
queries_redirect($location, lang('Item%s has been inserted.', ($last_id ? " $last_id" : "")), $result); //! link
} }
} }
} }

View file

@ -40,7 +40,7 @@ $translations = array(
'Create new table' => 'Vytvořit novou tabulku', 'Create new table' => 'Vytvořit novou tabulku',
'Item has been deleted.' => 'Položka byla smazána.', 'Item has been deleted.' => 'Položka byla smazána.',
'Item has been updated.' => 'Položka byla aktualizována.', 'Item has been updated.' => 'Položka byla aktualizována.',
'Item has been inserted.' => 'Položka byla vložena.', 'Item%s has been inserted.' => 'Položka%s byla vložena.',
'Edit' => 'Upravit', 'Edit' => 'Upravit',
'Insert' => 'Vložit', 'Insert' => 'Vložit',
'Save and insert next' => 'Uložit a vložit další', 'Save and insert next' => 'Uložit a vložit další',

View file

@ -9,8 +9,9 @@ Remember export parameters in cookie
Allow semicolon as CSV separator Allow semicolon as CSV separator
Autofocus username in login form Autofocus username in login form
Disable spellchecking in SQL textareas Disable spellchecking in SQL textareas
Japanese translation Display auto_increment value of inserted item
Link table names in SQL queries Link table names in SQL queries
Japanese translation
Defer table information in database overview to JavaScript (performance) Defer table information in database overview to JavaScript (performance)
Big tables optimizations (performance) Big tables optimizations (performance)