mirror of
https://github.com/vrana/adminer.git
synced 2025-08-13 18:14:07 +02:00
SQLite: Fix type of $auto_increment
This commit is contained in:
@@ -7,7 +7,7 @@ $row = $_POST;
|
|||||||
|
|
||||||
if ($row && !$error) {
|
if ($row && !$error) {
|
||||||
if (JUSH == "sqlite") {
|
if (JUSH == "sqlite") {
|
||||||
$result = recreate_table($TABLE, $TABLE, array(), array(), array(), 0, array(), $name, ($row["drop"] ? "" : $row["clause"]));
|
$result = recreate_table($TABLE, $TABLE, array(), array(), array(), "", array(), "$name", ($row["drop"] ? "" : $row["clause"]));
|
||||||
} else {
|
} else {
|
||||||
$result = ($name == "" || queries("ALTER TABLE " . table($TABLE) . " DROP CONSTRAINT " . idf_escape($name)));
|
$result = ($name == "" || queries("ALTER TABLE " . table($TABLE) . " DROP CONSTRAINT " . idf_escape($name)));
|
||||||
if (!$row["drop"]) {
|
if (!$row["drop"]) {
|
||||||
|
@@ -675,7 +675,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
* @param string $name new name
|
* @param string $name new name
|
||||||
* @param list<array{string, list<string>, string}> $fields of [$orig, $process_field, $after]
|
* @param list<array{string, list<string>, string}> $fields of [$orig, $process_field, $after]
|
||||||
* @param string[] $foreign
|
* @param string[] $foreign
|
||||||
* @param string $auto_increment number
|
* @param numeric-string $auto_increment
|
||||||
* @return Result|bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function alter_table(string $table, string $name, array $fields, array $foreign, ?string $comment, string $engine, string $collation, string $auto_increment, string $partitioning) {
|
function alter_table(string $table, string $name, array $fields, array $foreign, ?string $comment, string $engine, string $collation, string $auto_increment, string $partitioning) {
|
||||||
|
@@ -442,12 +442,12 @@ if (isset($_GET["sqlite"])) {
|
|||||||
* @param list<list<string>> $fields [process_field()], empty to preserve
|
* @param list<list<string>> $fields [process_field()], empty to preserve
|
||||||
* @param string[] $originals [$original => idf_escape($new_column)], empty to preserve
|
* @param string[] $originals [$original => idf_escape($new_column)], empty to preserve
|
||||||
* @param string[] $foreign [format_foreign_key()], empty to preserve
|
* @param string[] $foreign [format_foreign_key()], empty to preserve
|
||||||
* @param int $auto_increment set auto_increment to this value, 0 to preserve
|
* @param numeric-string $auto_increment set auto_increment to this value, "" to preserve
|
||||||
* @param list<array{string, string, list<string>|'DROP'}> $indexes [[$type, $name, $columns]], empty to preserve
|
* @param list<array{string, string, list<string>|'DROP'}> $indexes [[$type, $name, $columns]], empty to preserve
|
||||||
* @param string $drop_check CHECK constraint to drop
|
* @param string $drop_check CHECK constraint to drop
|
||||||
* @param string $add_check CHECK constraint to add
|
* @param string $add_check CHECK constraint to add
|
||||||
*/
|
*/
|
||||||
function recreate_table(string $table, string $name, array $fields, array $originals, array $foreign, int $auto_increment = 0, $indexes = array(), string $drop_check = "", string $add_check = ""): bool {
|
function recreate_table(string $table, string $name, array $fields, array $originals, array $foreign, string $auto_increment = "", $indexes = array(), string $drop_check = "", string $add_check = ""): bool {
|
||||||
if ($table != "") {
|
if ($table != "") {
|
||||||
if (!$fields) {
|
if (!$fields) {
|
||||||
foreach (fields($table) as $key => $field) {
|
foreach (fields($table) as $key => $field) {
|
||||||
@@ -534,7 +534,7 @@ if (isset($_GET["sqlite"])) {
|
|||||||
$trigger = trigger($trigger_name, $table);
|
$trigger = trigger($trigger_name, $table);
|
||||||
$triggers[] = "CREATE TRIGGER " . idf_escape($trigger_name) . " " . implode(" ", $timing_event) . " ON " . table($name) . "\n$trigger[Statement]";
|
$triggers[] = "CREATE TRIGGER " . idf_escape($trigger_name) . " " . implode(" ", $timing_event) . " ON " . table($name) . "\n$trigger[Statement]";
|
||||||
}
|
}
|
||||||
$auto_increment = $auto_increment ? 0 : get_val("SELECT seq FROM sqlite_sequence WHERE name = " . q($table)); // if $auto_increment is set then it will be updated later
|
$auto_increment = $auto_increment ? "" : get_val("SELECT seq FROM sqlite_sequence WHERE name = " . q($table)); // if $auto_increment is set then it will be updated later
|
||||||
if (
|
if (
|
||||||
!queries("DROP TABLE " . table($table)) // drop before creating indexes and triggers to allow using old names
|
!queries("DROP TABLE " . table($table)) // drop before creating indexes and triggers to allow using old names
|
||||||
|| ($table == $name && !queries("ALTER TABLE " . table($temp_name) . " RENAME TO " . table($name)))
|
|| ($table == $name && !queries("ALTER TABLE " . table($temp_name) . " RENAME TO " . table($name)))
|
||||||
@@ -566,7 +566,7 @@ if (isset($_GET["sqlite"])) {
|
|||||||
function alter_indexes($table, $alter) {
|
function alter_indexes($table, $alter) {
|
||||||
foreach ($alter as $primary) {
|
foreach ($alter as $primary) {
|
||||||
if ($primary[0] == "PRIMARY") {
|
if ($primary[0] == "PRIMARY") {
|
||||||
return recreate_table($table, $table, array(), array(), array(), 0, $alter);
|
return recreate_table($table, $table, array(), array(), array(), "", $alter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (array_reverse($alter) as $val) {
|
foreach (array_reverse($alter) as $val) {
|
||||||
|
@@ -64,7 +64,9 @@ function idx(?array $array, $key, $default = null) {
|
|||||||
return ($array && array_key_exists($key, $array) ? $array[$key] : $default);
|
return ($array && array_key_exists($key, $array) ? $array[$key] : $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove non-digits from a string */
|
/** Remove non-digits from a string; used instead of intval() to not corrupt big numbers
|
||||||
|
* @return numeric-string
|
||||||
|
*/
|
||||||
function number(string $val): string {
|
function number(string $val): string {
|
||||||
return preg_replace('~[^0-9]+~', '', $val);
|
return preg_replace('~[^0-9]+~', '', $val);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user