Changes between Version 1 and Version 2 of Ticket #11512, comment 24
- Timestamp:
- Apr 18, 2014, 10:05:06 AM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #11512, comment 24
v1 v2 1 1 Sorry for late. I tested [log:rjollos.git@t11512.5_0.12] with PostgreSQL 8.1.23 and Python 2.4. It seems to need to apply like this. 2 2 3 {{{#!diff --git a/trac/db/postgres_backend.py b/trac/db/postgres_backend.py 4 index ad43a0c..4bdab20 100644 3 {{{#!diff 4 diff --git a/trac/db/postgres_backend.py b/trac/db/postgres_backend.py 5 index ad43a0c..a21e7e2 100644 5 6 --- a/trac/db/postgres_backend.py 6 7 +++ b/trac/db/postgres_backend.py … … 14 15 from trac.util.translation import _ 15 16 16 @@ -261, 7 +261,8 @@ class PostgreSQLConnection(ConnectionWrapper):17 @@ -261,18 +261,18 @@ class PostgreSQLConnection(ConnectionWrapper): 17 18 return IterableCursor(self.cnx.cursor(), self.log) 18 19 19 20 def drop_table(self, table): 20 21 - if (self._version or '').startswith(('8.0.', '8.1.')): 22 - cursor = self.cursor() 23 + cursor = self.cursor() 21 24 + if self._version and any(self._version.startswith(version) 22 25 + for version in ('8.0.', '8.1.')): 23 cursor = self.cursor()24 26 cursor.execute("""SELECT table_name FROM information_schema.tables 25 27 WHERE table_schema=current_schema() 26 @@ -272,7 +273,6 @@ class PostgreSQLConnection(ConnectionWrapper): 28 AND table_name=%s""", (table,)) 29 for row in cursor: 30 if row[0] == table: 31 - self.cursor().execute("DROP TABLE " + self.quote(table)) 32 + cursor.execute("DROP TABLE " + self.quote(table)) 27 33 break 28 34 else: 29 35 - self.cursor().execute("DROP TABLE IF EXISTS " + self.quote(table)) 30 36 - self.commit() 37 + cursor.execute("DROP TABLE IF EXISTS " + self.quote(table)) 31 38 32 39 def _sequence_name(self, table, column): 33 40 return '%s_%s_seq' % (table, column) 34 41 }}} 42 Edit: updated the above patch. Use `cursor` variable. 35 43 36 44 I don't think that `drop_table()` should call `self.commit()`. Caller of the function should use `@with_transaction()`. 37 45 38 Also, transaction in PostgresSQL can contain DDL, e.g. `CREATE TABLE`, `DROP TABLE` and can rollback. However, transaction in MySQL cannot contain DDL. See [https://wiki.postgresql.org/wiki/Transactional_DDL_in_PostgreSQL:_A_Competitive_Analysis Transactional DDL in PostgreSQL: A Competitive Analysis - PostgreSQL wiki].46 Also, transaction in PostgresSQL can contain DDL, e.g. `CREATE TABLE`, `DROP TABLE` and can rollback. However, transaction in MySQL ignores DDL and cannot rollback. See [https://wiki.postgresql.org/wiki/Transactional_DDL_in_PostgreSQL:_A_Competitive_Analysis Transactional DDL in PostgreSQL: A Competitive Analysis - PostgreSQL wiki].