Skip to content
This repository
Browse code

Adding a parameter for committing select queries -- psycopg2, unless in

autocommit mode, will open a transaction for any query, including
selects.  If not comitted, leads to idle in transactions -- this fixes
and also addresses #116
  • Loading branch information...
commit 5b93c6f8e599e3b9e1ff89af35ca8c7fed83dbf6 1 parent a5ec7bb
Charles Leifer authored October 12, 2012

Showing 1 changed file with 7 additions and 1 deletion. Show diff stats Hide diff stats

  1. 8  peewee.py
8  peewee.py
@@ -1454,6 +1454,7 @@ def execute(self):
1454 1454
 
1455 1455
 
1456 1456
 class Database(object):
  1457
+    commit_select = False
1457 1458
     compiler_class = QueryCompiler
1458 1459
     expr_overrides = {}
1459 1460
     field_overrides = {}
@@ -1526,7 +1527,11 @@ def get_compiler(self):
1526 1527
 
1527 1528
     def execute(self, query):
1528 1529
         sql, params = query.sql(self.get_compiler())
1529  
-        return self.execute_sql(sql, params, query.require_commit)
  1530
+        if isinstance(query, (SelectQuery, RawQuery)):
  1531
+            commit = self.commit_select
  1532
+        else:
  1533
+            commit = query.require_commit
  1534
+        return self.execute_sql(sql, params, commit)
1530 1535
 
1531 1536
     def execute_sql(self, sql, params=None, require_commit=True):
1532 1537
         cursor = self.get_cursor()
@@ -1632,6 +1637,7 @@ def get_tables(self):
1632 1637
 
1633 1638
 
1634 1639
 class PostgresqlDatabase(Database):
  1640
+    commit_select = True
1635 1641
     field_overrides = {
1636 1642
         'bigint': 'BIGINT',
1637 1643
         'bool': 'BOOLEAN',

0 notes on commit 5b93c6f

Please sign in to comment.
Something went wrong with that request. Please try again.