Permalink
Browse files

Display auto_increment value of inserted item

  • Loading branch information...
1 parent 22eb69b commit 29e7f041a342f59ad2741700c9af6be5472a82bf @vrana committed May 12, 2010
@@ -409,6 +409,11 @@ function insert_into($table, $set) {
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) {
$connection->query("SET SHOWPLAN_ALL ON");
$return = $connection->query($query);
@@ -769,6 +769,14 @@ function insert_into($table, $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
* @param Min_DB
* @param string
@@ -466,6 +466,10 @@ function insert_into($table, $set) {
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) {
return $connection->query("EXPLAIN $query");
}
@@ -500,6 +500,11 @@ function insert_into($table, $set) {
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) {
return $connection->query("EXPLAIN $query");
}
@@ -31,7 +31,9 @@
}
query_redirect("UPDATE" . limit1(table($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where"), $location, lang('Item has been updated.'));
} 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
}
}
}
@@ -40,7 +40,7 @@
'Create new table' => 'Vytvořit novou tabulku',
'Item has been deleted.' => 'Položka byla smazá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',
'Insert' => 'Vložit',
'Save and insert next' => 'Uložit a vložit další',
View
@@ -9,8 +9,9 @@ Remember export parameters in cookie
Allow semicolon as CSV separator
Autofocus username in login form
Disable spellchecking in SQL textareas
-Japanese translation
+Display auto_increment value of inserted item
Link table names in SQL queries
+Japanese translation
Defer table information in database overview to JavaScript (performance)
Big tables optimizations (performance)

0 comments on commit 29e7f04

Please sign in to comment.