]> git.joonet.de Git - adminer.git/commitdiff
SQLite: Fix type of $auto_increment
authorJakub Vrana <jakub@vrana.cz>
Mon, 31 Mar 2025 08:32:55 +0000 (10:32 +0200)
committerJakub Vrana <jakub@vrana.cz>
Mon, 31 Mar 2025 08:42:30 +0000 (10:42 +0200)
adminer/check.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/functions.inc.php

index c0c12341d6f325230db9d662d9f52e2a131a8edd..4c191430cfe2ee04f26f75a46b2ac5942504851a 100644 (file)
@@ -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"]) {
index d5690ce3fad2a31c128759c3117751f1b1af8dae..2c74db95390a84acaee089777accdd0b08fa6cb5 100644 (file)
@@ -675,7 +675,7 @@ if (!defined('Adminer\DRIVER')) {
        * @param string $name new name
        * @param list<array{string, list<string>, 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) {
index df910d1b51d109767c6881d02fad04310e3c30d7..3f417fa09ec5a450fcbe71ab45ca44343a31964f 100644 (file)
@@ -442,12 +442,12 @@ if (isset($_GET["sqlite"])) {
        * @param list<list<string>> $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<array{string, string, list<string>|'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) {
index cd033ccdd058593470af2dd15096c2f2a76e6b0d..2ff38ce87e7a682ba0ea5abef5e2a50eb8e59abc 100644 (file)
@@ -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);
 }