Fixed #13821 -- Added a double-quoting to the PostgreSQL sequence reset code. Thanks to PaulM for the report, and to PaulM and Simon Meers for their work on the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13450 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
bab9aab9a2
commit
398415fc23
|
@ -56,7 +56,8 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
def last_insert_id(self, cursor, table_name, pk_name):
|
def last_insert_id(self, cursor, table_name, pk_name):
|
||||||
# Use pg_get_serial_sequence to get the underlying sequence name
|
# Use pg_get_serial_sequence to get the underlying sequence name
|
||||||
# from the table name and column name (available since PostgreSQL 8)
|
# from the table name and column name (available since PostgreSQL 8)
|
||||||
cursor.execute("SELECT CURRVAL(pg_get_serial_sequence('%s','%s'))" % (table_name, pk_name))
|
cursor.execute("SELECT CURRVAL(pg_get_serial_sequence('%s','%s'))" % (
|
||||||
|
self.quote_name(table_name), pk_name))
|
||||||
return cursor.fetchone()[0]
|
return cursor.fetchone()[0]
|
||||||
|
|
||||||
def no_limit_value(self):
|
def no_limit_value(self):
|
||||||
|
@ -98,7 +99,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
column_name = 'id'
|
column_name = 'id'
|
||||||
sql.append("%s setval(pg_get_serial_sequence('%s','%s'), 1, false);" % \
|
sql.append("%s setval(pg_get_serial_sequence('%s','%s'), 1, false);" % \
|
||||||
(style.SQL_KEYWORD('SELECT'),
|
(style.SQL_KEYWORD('SELECT'),
|
||||||
style.SQL_TABLE(table_name),
|
style.SQL_TABLE(self.quote_name(table_name)),
|
||||||
style.SQL_FIELD(column_name))
|
style.SQL_FIELD(column_name))
|
||||||
)
|
)
|
||||||
return sql
|
return sql
|
||||||
|
@ -120,7 +121,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
if isinstance(f, models.AutoField):
|
if isinstance(f, models.AutoField):
|
||||||
output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
||||||
(style.SQL_KEYWORD('SELECT'),
|
(style.SQL_KEYWORD('SELECT'),
|
||||||
style.SQL_TABLE(model._meta.db_table),
|
style.SQL_TABLE(qn(model._meta.db_table)),
|
||||||
style.SQL_FIELD(f.column),
|
style.SQL_FIELD(f.column),
|
||||||
style.SQL_FIELD(qn(f.column)),
|
style.SQL_FIELD(qn(f.column)),
|
||||||
style.SQL_FIELD(qn(f.column)),
|
style.SQL_FIELD(qn(f.column)),
|
||||||
|
@ -132,7 +133,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
if not f.rel.through:
|
if not f.rel.through:
|
||||||
output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
||||||
(style.SQL_KEYWORD('SELECT'),
|
(style.SQL_KEYWORD('SELECT'),
|
||||||
style.SQL_TABLE(f.m2m_db_table()),
|
style.SQL_TABLE(qn(f.m2m_db_table())),
|
||||||
style.SQL_FIELD('id'),
|
style.SQL_FIELD('id'),
|
||||||
style.SQL_FIELD(qn('id')),
|
style.SQL_FIELD(qn('id')),
|
||||||
style.SQL_FIELD(qn('id')),
|
style.SQL_FIELD(qn('id')),
|
||||||
|
|
|
@ -51,6 +51,8 @@ class Post(models.Model):
|
||||||
text = models.TextField()
|
text = models.TextField()
|
||||||
tags = generic.GenericRelation('Tag')
|
tags = generic.GenericRelation('Tag')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = 'CaseSensitive_Post'
|
||||||
|
|
||||||
qn = connection.ops.quote_name
|
qn = connection.ops.quote_name
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue