Skip to content

Commit

Permalink
Display auto_increment value of inserted item
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed May 12, 2010
1 parent 22eb69b commit 29e7f04
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions adminer/drivers/mssql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions adminer/drivers/mysql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions adminer/drivers/pgsql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
5 changes: 5 additions & 0 deletions adminer/drivers/sqlite.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
4 changes: 3 additions & 1 deletion adminer/edit.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion adminer/lang/cs.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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ší',
Expand Down
3 changes: 2 additions & 1 deletion changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 29e7f04

Please sign in to comment.