373 # should not collide |
373 # should not collide |
374 newargs.update(query_args) |
374 newargs.update(query_args) |
375 return newargs |
375 return newargs |
376 return query_args |
376 return query_args |
377 |
377 |
378 def process_result(self, cursor, column_callbacks=None, session=None): |
378 def process_result(self, cursor, cnx=None, column_callbacks=None): |
379 """return a list of CubicWeb compliant values from data in the given cursor |
379 """return a list of CubicWeb compliant values from data in the given cursor |
380 """ |
380 """ |
381 return list(self.iter_process_result(cursor, column_callbacks, session)) |
381 return list(self.iter_process_result(cursor, cnx, column_callbacks)) |
382 |
382 |
383 def iter_process_result(self, cursor, column_callbacks=None, session=None): |
383 def iter_process_result(self, cursor, cnx, column_callbacks=None): |
384 """return a iterator on tuples of CubicWeb compliant values from data |
384 """return a iterator on tuples of CubicWeb compliant values from data |
385 in the given cursor |
385 in the given cursor |
386 """ |
386 """ |
387 # use two different implementations to avoid paying the price of |
387 # use two different implementations to avoid paying the price of |
388 # callback lookup for each *cell* in results when there is nothing to |
388 # callback lookup for each *cell* in results when there is nothing to |
389 # lookup |
389 # lookup |
390 if not column_callbacks: |
390 if not column_callbacks: |
391 return self.dbhelper.dbapi_module.process_cursor(cursor, self._dbencoding, |
391 return self.dbhelper.dbapi_module.process_cursor(cursor, self._dbencoding, |
392 Binary) |
392 Binary) |
393 assert session |
393 assert cnx |
394 return self._cb_process_result(cursor, column_callbacks, session) |
394 return self._cb_process_result(cursor, column_callbacks, cnx) |
395 |
395 |
396 def _cb_process_result(self, cursor, column_callbacks, session): |
396 def _cb_process_result(self, cursor, column_callbacks, cnx): |
397 # begin bind to locals for optimization |
397 # begin bind to locals for optimization |
398 descr = cursor.description |
398 descr = cursor.description |
399 encoding = self._dbencoding |
399 encoding = self._dbencoding |
400 process_value = self._process_value |
400 process_value = self._process_value |
401 binary = Binary |
401 binary = Binary |
414 cbstack = column_callbacks.get(col, None) |
414 cbstack = column_callbacks.get(col, None) |
415 if cbstack is None: |
415 if cbstack is None: |
416 value = process_value(value, descr[col], encoding, binary) |
416 value = process_value(value, descr[col], encoding, binary) |
417 else: |
417 else: |
418 for cb in cbstack: |
418 for cb in cbstack: |
419 value = cb(self, session, value) |
419 value = cb(self, cnx, value) |
420 result.append(value) |
420 result.append(value) |
421 yield result |
421 yield result |
422 |
422 |
423 def preprocess_entity(self, entity): |
423 def preprocess_entity(self, entity): |
424 """return a dictionary to use as extra argument to cursor.execute |
424 """return a dictionary to use as extra argument to cursor.execute |