server/sqlutils.py
branchstable
changeset 5625 6ee2a7b6f194
parent 5605 2604545d7dd9
child 5768 1e73a466aa69
equal deleted inserted replaced
5624:865c1779cc84 5625:6ee2a7b6f194
   200             # should not collide
   200             # should not collide
   201             newargs.update(query_args)
   201             newargs.update(query_args)
   202             return newargs
   202             return newargs
   203         return query_args
   203         return query_args
   204 
   204 
   205     def process_result(self, cursor, column_callbacks=None):
   205     def process_result(self, cursor, column_callbacks=None, session=None):
   206         """return a list of CubicWeb compliant values from data in the given cursor
   206         """return a list of CubicWeb compliant values from data in the given cursor
   207         """
   207         """
   208         # use two different implementations to avoid paying the price of
   208         # use two different implementations to avoid paying the price of
   209         # callback lookup for each *cell* in results when there is nothing to
   209         # callback lookup for each *cell* in results when there is nothing to
   210         # lookup
   210         # lookup
   211         if not column_callbacks:
   211         if not column_callbacks:
   212             return self._process_result(cursor)
   212             return self._process_result(cursor)
   213         return self._cb_process_result(cursor, column_callbacks)
   213         assert session
   214 
   214         return self._cb_process_result(cursor, column_callbacks, session)
   215     def _process_result(self, cursor, column_callbacks=None):
   215 
       
   216     def _process_result(self, cursor):
   216         # begin bind to locals for optimization
   217         # begin bind to locals for optimization
   217         descr = cursor.description
   218         descr = cursor.description
   218         encoding = self._dbencoding
   219         encoding = self._dbencoding
   219         process_value = self._process_value
   220         process_value = self._process_value
   220         binary = Binary
   221         binary = Binary
   228                     continue
   229                     continue
   229                 result.append(process_value(value, descr[col], encoding, binary))
   230                 result.append(process_value(value, descr[col], encoding, binary))
   230             results[i] = result
   231             results[i] = result
   231         return results
   232         return results
   232 
   233 
   233     def _cb_process_result(self, cursor, column_callbacks):
   234     def _cb_process_result(self, cursor, column_callbacks, session):
   234         # begin bind to locals for optimization
   235         # begin bind to locals for optimization
   235         descr = cursor.description
   236         descr = cursor.description
   236         encoding = self._dbencoding
   237         encoding = self._dbencoding
   237         process_value = self._process_value
   238         process_value = self._process_value
   238         binary = Binary
   239         binary = Binary
   247                 cbstack = column_callbacks.get(col, None)
   248                 cbstack = column_callbacks.get(col, None)
   248                 if cbstack is None:
   249                 if cbstack is None:
   249                     value = process_value(value, descr[col], encoding, binary)
   250                     value = process_value(value, descr[col], encoding, binary)
   250                 else:
   251                 else:
   251                     for cb in cbstack:
   252                     for cb in cbstack:
   252                         value = cb(self, value)
   253                         value = cb(self, session, value)
   253                 result.append(value)
   254                 result.append(value)
   254             results[i] = result
   255             results[i] = result
   255         return results
   256         return results
   256 
   257 
   257     def preprocess_entity(self, entity):
   258     def preprocess_entity(self, entity):