mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-29 05:54:21 +01:00
Merge 'Stop ignoring table's max value incase of a manual update in autoincrement.' from Pavan Nambi
closes https://github.com/tursodatabase/turso/issues/3664 Reviewed-by: Preston Thorpe <preston@turso.tech> Closes #3668
This commit is contained in:
@@ -6412,7 +6412,7 @@ pub fn op_new_rowid(
|
||||
NewRowid {
|
||||
cursor,
|
||||
rowid_reg,
|
||||
..
|
||||
prev_largest_reg,
|
||||
},
|
||||
insn
|
||||
);
|
||||
@@ -6455,6 +6455,11 @@ pub fn op_new_rowid(
|
||||
return_if_io!(cursor.rowid())
|
||||
};
|
||||
|
||||
if *prev_largest_reg > 0 {
|
||||
state.registers[*prev_largest_reg] =
|
||||
Register::Value(Value::Integer(current_max.unwrap_or(0)));
|
||||
}
|
||||
|
||||
match current_max {
|
||||
Some(rowid) if rowid < MAX_ROWID => {
|
||||
// Can use sequential
|
||||
|
||||
@@ -174,4 +174,17 @@ do_execsql_test_on_specific_db {:memory:} autoinc-conflict-on-nothing {
|
||||
INSERT INTO t (k) VALUES ('a') ON CONFLICT DO NOTHING;
|
||||
INSERT INTO t (k) VALUES ('b');
|
||||
SELECT * FROM t ORDER BY id;
|
||||
} {1|a 2|a 4|b}
|
||||
} {1|a 2|a 4|b}
|
||||
|
||||
# https://github.com/tursodatabase/turso/issues/3664
|
||||
do_execsql_test_on_specific_db {:memory:} autoinc-skips-manually-updated-pk {
|
||||
CREATE TABLE t(a INTEGER PRIMARY KEY AUTOINCREMENT);
|
||||
INSERT INTO t DEFAULT VALUES;
|
||||
select * from sqlite_sequence;
|
||||
UPDATE t SET a = a + 1;
|
||||
SELECT * FROM sqlite_sequence;
|
||||
INSERT INTO t DEFAULT VALUES;
|
||||
SELECT * FROM sqlite_sequence;
|
||||
} {t|1
|
||||
t|1
|
||||
t|3}
|
||||
|
||||
Reference in New Issue
Block a user