Cédric Krier pushed to branch branch/6.6 at Tryton / Tryton
Commits: ceb3118c by Cédric Krier at 2023-04-08T12:03:00+02:00 Format using SQL Identifier type sequence name The sequence functions are using string parameters so for case sensitive sequence name we must pass a string containing double-quoting if necessary. Closes #12194 - - - - - 2 changed files: - trytond/trytond/backend/postgresql/database.py - trytond/trytond/backend/postgresql/table.py Changes: ===================================== trytond/trytond/backend/postgresql/database.py ===================================== @@ -412,8 +412,9 @@ def nextid(self, connection, table): cursor = connection.cursor() - cursor.execute("SELECT NEXTVAL(%s)", (table + '_id_seq',)) + cursor.execute( + "SELECT nextval(format(%s, %s))", ('%I', table + '_id_seq',)) return cursor.fetchone()[0] def setnextid(self, connection, table, value): cursor = connection.cursor() @@ -416,8 +417,10 @@ return cursor.fetchone()[0] def setnextid(self, connection, table, value): cursor = connection.cursor() - cursor.execute("SELECT SETVAL(%s, %s)", (table + '_id_seq', value)) + cursor.execute( + "SELECT setval(format(%s, %s), %s)", + ('%I', table + '_id_seq', value)) def currid(self, connection, table): cursor = connection.cursor() ===================================== trytond/trytond/backend/postgresql/table.py ===================================== @@ -56,5 +56,5 @@ cursor.execute( SQL( "ALTER TABLE {} ADD COLUMN id INTEGER " - "DEFAULT nextval(%s) NOT NULL").format( + "DEFAULT nextval(format(%s, %s)) NOT NULL").format( Identifier(self.table_name)), @@ -60,5 +60,5 @@ Identifier(self.table_name)), - (self.sequence_name,)) + ('%I', self.sequence_name)) cursor.execute( SQL('ALTER TABLE {} ADD PRIMARY KEY(id)') .format(Identifier(self.table_name))) @@ -71,5 +71,5 @@ cursor.execute( SQL( "ALTER TABLE {} ADD COLUMN __id INTEGER " - "DEFAULT nextval(%s) NOT NULL").format( + "DEFAULT nextval(format(%s, %s)) NOT NULL").format( Identifier(self.table_name)), @@ -75,7 +75,7 @@ Identifier(self.table_name)), - (self.sequence_name,)) + ('%I', self.sequence_name)) cursor.execute( SQL('ALTER TABLE {} ADD PRIMARY KEY(__id)') .format(Identifier(self.table_name))) self._update_definitions(columns=True) else: @@ -77,10 +77,12 @@ cursor.execute( SQL('ALTER TABLE {} ADD PRIMARY KEY(__id)') .format(Identifier(self.table_name))) self._update_definitions(columns=True) else: - default = "nextval('%s'::regclass)" % self.sequence_name + default = ( + "nextval((format('%%I'::text, '%s'))::regclass)" + % self.sequence_name) if self.history: if self._columns['__id']['default'] != default: cursor.execute( SQL("ALTER TABLE {} " @@ -83,6 +85,7 @@ if self.history: if self._columns['__id']['default'] != default: cursor.execute( SQL("ALTER TABLE {} " - "ALTER __id SET DEFAULT nextval(%s::regclass)") + "ALTER __id SET " + "DEFAULT nextval(format(%s, %s))") .format(Identifier(self.table_name)), @@ -88,6 +91,6 @@ .format(Identifier(self.table_name)), - (self.sequence_name,)) + ('%I', self.sequence_name)) self._update_definitions(columns=True) if self._columns['id']['default'] != default: cursor.execute( SQL("ALTER TABLE {} " @@ -90,6 +93,7 @@ self._update_definitions(columns=True) if self._columns['id']['default'] != default: cursor.execute( SQL("ALTER TABLE {} " - "ALTER id SET DEFAULT nextval(%s::regclass)") + "ALTER id SET " + "DEFAULT nextval(format(%s, %s))") .format(Identifier(self.table_name)), @@ -95,5 +99,5 @@ .format(Identifier(self.table_name)), - (self.sequence_name,)) + ('%I', self.sequence_name,)) self._update_definitions(columns=True) @classmethod View it on Heptapod: https://foss.heptapod.net/tryton/tryton/-/commit/ceb3118cd35511412d7cf8f2eae6c1891cf5f47a -- View it on Heptapod: https://foss.heptapod.net/tryton/tryton/-/commit/ceb3118cd35511412d7cf8f2eae6c1891cf5f47a You're receiving this email because of your account on foss.heptapod.net.