summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMarko Kreen2007-07-20 15:59:58 +0000
committerMarko Kreen2007-07-20 15:59:58 +0000
commit65eb35c30bedb89b57df7c6db6bd5de4eb83056c (patch)
tree453a3781bd7c370d76526a554253b12e56f60032 /python
parent814b70fb096ce1c51718ab728fb777aedcb9e0a0 (diff)
skytools/psycopg2: allow setting row fields
Diffstat (limited to 'python')
-rw-r--r--python/skytools/sqltools.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/python/skytools/sqltools.py b/python/skytools/sqltools.py
index e0d53bf8..11e259af 100644
--- a/python/skytools/sqltools.py
+++ b/python/skytools/sqltools.py
@@ -23,8 +23,20 @@ try:
## only backwards compat thing we need is dict* methods
import psycopg2.extensions, psycopg2.extras
+ class _CompatRow(psycopg2.extras.DictRow):
+ def __setitem__(self, k, v):
+ if type(k) != int:
+ if k not in self._index:
+ self._index[k] = len(self._index)
+ k = self._index[k]
+ while k >= len(self):
+ self.append(None)
+ return list.__setitem__(self, k, v)
class _CompatCursor(psycopg2.extras.DictCursor):
"""Regular psycopg2 DictCursor with dict* methods."""
+ def __init__(self, *args, **kwargs):
+ psycopg2.extras.DictCursor.__init__(self, *args, **kwargs)
+ self.row_factory = _CompatRow
dictfetchone = psycopg2.extras.DictCursor.fetchone
dictfetchall = psycopg2.extras.DictCursor.fetchall
dictfetchmany = psycopg2.extras.DictCursor.fetchmany