コード例 #1
0
ファイル: adapters.py プロジェクト: warvariuc/wic
 def _execute(self, *a, **b):
     query = a[0]
     logger.debug('DB query: %s' % query)
     t0 = time.time()
     try:
         result = self.cursor.execute(*a, **b)
     except Exception:
         logger.warning(query)
         raise
     self._timings.append((query, round(time.time() - t0, 4)))
     return result
コード例 #2
0
ファイル: adapters.py プロジェクト: warvariuc/wic
 def render(cls, value, castField = None):
     """Render of a value (Expression, Field or simple (scalar?) value) in a format suitable for
     operations with castField in the DB.
     """
     if isinstance(value, orm.Expression): # it's an Expression or Field
         if isinstance(value, orm.DateTimeField):
             pass
         return value.__str__(cls) # render sub-expression
     else: # it's a value for a DB column
         if value is not None and castField is not None:
             assert isinstance(castField, orm.Expression), 'Cast field must be an Expression.'
             if castField.__class__ is orm.Expression: # Field - subclass of Expression
                 castField = castField.type # expression right operand type
             value = castField.cast(value)
             try:
                 return cls._render(value, castField.column)
             except Exception:
                 logger.warning('Check %r._cast().' % castField)
                 raise
         return cls._render(value)