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 (grafted from ceb3118cd35511412d7cf8f2eae6c1891cf5f47a) --HG-- branch : 6.0
This commit is contained in:
1 parent
3956eccf38
commit
9763ee5d39
2 files changed
+18
-11
No files matched your search
@@ -420,12 +420,15 @@ class Database(DatabaseInterface):
|
||||
|
||||
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()
|
||||
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()
|
||||
|
||||
@@ -56,9 +56,9 @@ class TableHandler(TableHandlerInterface):
|
||||
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)),
|
||||
(self.sequence_name,))
|
||||
('%I', self.sequence_name))
|
||||
cursor.execute(
|
||||
SQL('ALTER TABLE {} ADD PRIMARY KEY(id)')
|
||||
.format(Identifier(self.table_name)))
|
||||
@@ -71,27 +71,31 @@ class TableHandler(TableHandlerInterface):
|
||||
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)),
|
||||
(self.sequence_name,))
|
||||
('%I', self.sequence_name))
|
||||
cursor.execute(
|
||||
SQL('ALTER TABLE {} ADD PRIMARY KEY(__id)')
|
||||
.format(Identifier(self.table_name)))
|
||||
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 {} "
|
||||
"ALTER __id SET DEFAULT nextval(%s::regclass)")
|
||||
"ALTER __id SET "
|
||||
"DEFAULT nextval(format(%s, %s))")
|
||||
.format(Identifier(self.table_name)),
|
||||
(self.sequence_name,))
|
||||
('%I', self.sequence_name))
|
||||
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)),
|
||||
(self.sequence_name,))
|
||||
('%I', self.sequence_name,))
|
||||
self._update_definitions()
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in new issue
Block a user