Spaces:
Sleeping
Sleeping
Commit ·
bebb32c
1
Parent(s): bf0ca1d
fix cursor
Browse files- src/database.py +47 -9
src/database.py
CHANGED
|
@@ -85,25 +85,63 @@ class DB:
|
|
| 85 |
# Map transaction control statements
|
| 86 |
if sql_strip.startswith('BEGIN'):
|
| 87 |
self._conn.autocommit = False
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
if sql_strip == 'COMMIT':
|
| 93 |
try:
|
| 94 |
self._conn.commit()
|
| 95 |
finally:
|
| 96 |
self._conn.autocommit = True
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
if sql_strip == 'ROLLBACK':
|
| 101 |
try:
|
| 102 |
self._conn.rollback()
|
| 103 |
finally:
|
| 104 |
self._conn.autocommit = True
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
# Regular statement
|
| 109 |
with self._conn.cursor() as c:
|
|
|
|
| 85 |
# Map transaction control statements
|
| 86 |
if sql_strip.startswith('BEGIN'):
|
| 87 |
self._conn.autocommit = False
|
| 88 |
+
cur = self._conn.cursor()
|
| 89 |
+
try:
|
| 90 |
+
cur.execute('BEGIN;')
|
| 91 |
+
finally:
|
| 92 |
+
cur.close()
|
| 93 |
+
# Return a dummy cursor wrapper
|
| 94 |
+
|
| 95 |
+
class _DummyCursor:
|
| 96 |
+
def fetchone(self):
|
| 97 |
+
return None
|
| 98 |
+
|
| 99 |
+
def fetchall(self):
|
| 100 |
+
return []
|
| 101 |
+
|
| 102 |
+
@property
|
| 103 |
+
def rowcount(self):
|
| 104 |
+
return 0
|
| 105 |
+
|
| 106 |
+
return _DummyCursor()
|
| 107 |
+
|
| 108 |
if sql_strip == 'COMMIT':
|
| 109 |
try:
|
| 110 |
self._conn.commit()
|
| 111 |
finally:
|
| 112 |
self._conn.autocommit = True
|
| 113 |
+
|
| 114 |
+
class _DummyCursor:
|
| 115 |
+
def fetchone(self):
|
| 116 |
+
return None
|
| 117 |
+
|
| 118 |
+
def fetchall(self):
|
| 119 |
+
return []
|
| 120 |
+
|
| 121 |
+
@property
|
| 122 |
+
def rowcount(self):
|
| 123 |
+
return 0
|
| 124 |
+
|
| 125 |
+
return _DummyCursor()
|
| 126 |
+
|
| 127 |
if sql_strip == 'ROLLBACK':
|
| 128 |
try:
|
| 129 |
self._conn.rollback()
|
| 130 |
finally:
|
| 131 |
self._conn.autocommit = True
|
| 132 |
+
|
| 133 |
+
class _DummyCursor:
|
| 134 |
+
def fetchone(self):
|
| 135 |
+
return None
|
| 136 |
+
|
| 137 |
+
def fetchall(self):
|
| 138 |
+
return []
|
| 139 |
+
|
| 140 |
+
@property
|
| 141 |
+
def rowcount(self):
|
| 142 |
+
return 0
|
| 143 |
+
|
| 144 |
+
return _DummyCursor()
|
| 145 |
|
| 146 |
# Regular statement
|
| 147 |
with self._conn.cursor() as c:
|