From a9408ddd2fd1512966d10e486f17f1048314f236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 13 Dec 2025 14:31:19 +0100 Subject: [PATCH] Implement setnextid for SQLite database --- trytond/trytond/backend/sqlite/database.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/trytond/trytond/backend/sqlite/database.py b/trytond/trytond/backend/sqlite/database.py index 5503b74355..d0a234297e 100644 --- a/trytond/trytond/backend/sqlite/database.py +++ b/trytond/trytond/backend/sqlite/database.py @@ -717,6 +717,25 @@ class Database(DatabaseInterface): return False return True + def setnextid(self, connection, table, value): + cursor = connection.cursor() + sequence = Table('sqlite_sequence') + cursor.execute(*sequence.select( + sequence.seq, + where=sequence.name == table)) + rows = cursor.fetchall() + if rows: + if rows[0][0] >= value: + return + cursor.execute(*sequence.update( + [sequence.seq], + [value - 1], + where=sequence.name == table)) + else: + cursor.execute(*sequence.insert( + [sequence.name, sequence.seq], + [[table, value - 1]])) + def lastid(self, cursor): # This call is not thread safe return cursor.lastrowid