From 41964badb099caf71c93908a56f45054724c8ba7 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Mon, 31 Mar 2025 10:32:55 +0200 Subject: [PATCH] SQLite: Fix type of $auto_increment --- adminer/check.inc.php | 2 +- adminer/drivers/mysql.inc.php | 2 +- adminer/drivers/sqlite.inc.php | 8 ++++---- adminer/include/functions.inc.php | 4 +++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/adminer/check.inc.php b/adminer/check.inc.php index c0c12341..4c191430 100644 --- a/adminer/check.inc.php +++ b/adminer/check.inc.php @@ -7,7 +7,7 @@ $row = $_POST; if ($row && !$error) { 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 { $result = ($name == "" || queries("ALTER TABLE " . table($TABLE) . " DROP CONSTRAINT " . idf_escape($name))); if (!$row["drop"]) { diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index d5690ce3..2c74db95 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -675,7 +675,7 @@ if (!defined('Adminer\DRIVER')) { * @param string $name new name * @param list, string}> $fields of [$orig, $process_field, $after] * @param string[] $foreign - * @param string $auto_increment number + * @param numeric-string $auto_increment * @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) { diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index df910d1b..3f417fa0 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -442,12 +442,12 @@ if (isset($_GET["sqlite"])) { * @param list> $fields [process_field()], empty to preserve * @param string[] $originals [$original => idf_escape($new_column)], 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|'DROP'}> $indexes [[$type, $name, $columns]], empty to preserve * @param string $drop_check CHECK constraint to drop * @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 (!$fields) { foreach (fields($table) as $key => $field) { @@ -534,7 +534,7 @@ if (isset($_GET["sqlite"])) { $trigger = trigger($trigger_name, $table); $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 ( !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))) @@ -566,7 +566,7 @@ if (isset($_GET["sqlite"])) { function alter_indexes($table, $alter) { foreach ($alter as $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) { diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index cd033ccd..2ff38ce8 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -64,7 +64,9 @@ function idx(?array $array, $key, $default = null) { 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 { return preg_replace('~[^0-9]+~', '', $val); }