Edgewall Software

Changes between Version 1 and Version 2 of Ticket #11512, comment 24


Ignore:
Timestamp:
Apr 18, 2014, 10:05:06 AM (10 years ago)
Author:
Jun Omae

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #11512, comment 24

    v1 v2  
    11Sorry 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.
    22
    3 {{{#!diff --git a/trac/db/postgres_backend.py b/trac/db/postgres_backend.py
    4 index ad43a0c..4bdab20 100644
     3{{{#!diff
     4diff --git a/trac/db/postgres_backend.py b/trac/db/postgres_backend.py
     5index ad43a0c..a21e7e2 100644
    56--- a/trac/db/postgres_backend.py
    67+++ b/trac/db/postgres_backend.py
     
    1415 from trac.util.translation import _
    1516
    16 @@ -261,7 +261,8 @@ class PostgreSQLConnection(ConnectionWrapper):
     17@@ -261,18 +261,18 @@ class PostgreSQLConnection(ConnectionWrapper):
    1718         return IterableCursor(self.cnx.cursor(), self.log)
    1819
    1920     def drop_table(self, table):
    2021-        if (self._version or '').startswith(('8.0.', '8.1.')):
     22-            cursor = self.cursor()
     23+        cursor = self.cursor()
    2124+        if self._version and any(self._version.startswith(version)
    2225+                                 for version in ('8.0.', '8.1.')):
    23              cursor = self.cursor()
    2426             cursor.execute("""SELECT table_name FROM information_schema.tables
    2527                               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))
    2733                     break
    2834         else:
    29              self.cursor().execute("DROP TABLE IF EXISTS " + self.quote(table))
     35-            self.cursor().execute("DROP TABLE IF EXISTS " + self.quote(table))
    3036-        self.commit()
     37+            cursor.execute("DROP TABLE IF EXISTS " + self.quote(table))
    3138
    3239     def _sequence_name(self, table, column):
    3340         return '%s_%s_seq' % (table, column)
    3441}}}
     42Edit: updated the above patch. Use `cursor` variable.
    3543
    3644I don't think that `drop_table()` should call `self.commit()`. Caller of the function should use `@with_transaction()`.
    3745
    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].
     46Also, 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].