pgtoolkit/pgmanager.py
changeset 54 291473ab847c
parent 48 b82c7c2fb5af
child 55 adc1615d8fc5
equal deleted inserted replaced
53:4a049a5af657 54:291473ab847c
   140         return key in self._dict
   140         return key in self._dict
   141 
   141 
   142     def keys(self):
   142     def keys(self):
   143         return self._dict.keys()
   143         return self._dict.keys()
   144 
   144 
       
   145     def values(self):
       
   146         return self._dict.values()
       
   147 
   145 
   148 
   146 class Cursor(psycopg2.extensions.cursor):
   149 class Cursor(psycopg2.extensions.cursor):
   147 
   150 
   148     def execute(self, query, args=None):
   151     def execute(self, query, args=None):
   149         # log query before executing
   152         # log query before executing
   182         return [self.row_dict(row, lstrip) for row in rows]
   185         return [self.row_dict(row, lstrip) for row in rows]
   183 
   186 
   184     def adapt(self, row):
   187     def adapt(self, row):
   185         if isinstance(row, RowDict):
   188         if isinstance(row, RowDict):
   186             # dict
   189             # dict
   187             adapted = RowDict()
   190             adapted = dict()
   188             for key in row.keys():
   191             for key in row.keys():
   189                 adapted[key] = self.mogrify('%s', [row[key]]).decode('utf8')
   192                 adapted[key] = self.mogrify('%s', [row[key]]).decode('utf8')
       
   193             return RowDict(adapted)
   190         else:
   194         else:
   191             # list
   195             # list
   192             adapted = [self.mogrify('%s', [x]).decode('utf8') for x in row]
   196             return [self.mogrify('%s', [x]).decode('utf8') for x in row]
   193         return adapted
       
   194 
   197 
   195     def fetchone_adapted(self, lstrip=None):
   198     def fetchone_adapted(self, lstrip=None):
   196         '''Like fetchone_dict() but values are quoted for direct inclusion in SQL query.
   199         '''Like fetchone_dict() but values are quoted for direct inclusion in SQL query.
   197 
   200 
   198         This is useful when you need to generate SQL script from data returned
   201         This is useful when you need to generate SQL script from data returned