Python cx_Oracle.DATETIME Examples
The following are 3
code examples of cx_Oracle.DATETIME().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cx_Oracle
, or try the search function
.
Example #1
Source File: dbapiclient.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def mapArgs(self, args): realArgs = [] for arg in args: if isinstance(arg, str): # We use NCLOB everywhere, so cx_Oracle requires a unicode-type # input. But we mostly pass around utf-8 encoded bytes at the # application layer as they consume less memory, so do the # conversion here. arg = arg.decode('utf-8') if isinstance(arg, unicode) and len(arg) > 1024: # This *may* cause a type mismatch, but none of the non-CLOB # strings that we're passing would allow a value this large # anyway. Smaller strings will be automatically converted by # the bindings; larger ones will generate an error. I'm not # sure why cx_Oracle itself doesn't just do the following hack # automatically and internally for larger values too, but, here # it is: v = self.var(cx_Oracle.NCLOB, len(arg) + 1) v.setvalue(0, arg) elif isinstance(arg, datetime.datetime): # By default when cx_Oracle is passed a datetime object it maps it to a # cx_Oracle.DATETIME variable which does not serialize fraction seconds # into the query, or call, arguments. However, for high volume systems, # we really want sub-second resolution for things like the job queue, # so we want to serialize datetime as cx_Oracle.TIMESTAMP. v = self.var(cx_Oracle.TIMESTAMP) v.setvalue(0, arg) else: v = arg realArgs.append(v) return realArgs
Example #2
Source File: base.py From GTDWeb with GNU General Public License v2.0 | 4 votes |
def _rowfactory(row, cursor): # Cast numeric values as the appropriate Python type based upon the # cursor description, and convert strings to unicode. casted = [] for value, desc in zip(row, cursor.description): if value is not None and desc[1] is Database.NUMBER: precision, scale = desc[4:6] if scale == -127: if precision == 0: # NUMBER column: decimal-precision floating point # This will normally be an integer from a sequence, # but it could be a decimal value. if '.' in value: value = decimal.Decimal(value) else: value = int(value) else: # FLOAT column: binary-precision floating point. # This comes from FloatField columns. value = float(value) elif precision > 0: # NUMBER(p,s) column: decimal-precision fixed point. # This comes from IntField and DecimalField columns. if scale == 0: value = int(value) else: value = decimal.Decimal(value) elif '.' in value: # No type information. This normally comes from a # mathematical expression in the SELECT list. Guess int # or Decimal based on whether it has a decimal point. value = decimal.Decimal(value) else: value = int(value) # datetimes are returned as TIMESTAMP, except the results # of "dates" queries, which are returned as DATETIME. elif desc[1] in (Database.TIMESTAMP, Database.DATETIME): # Confirm that dt is naive before overwriting its tzinfo. if settings.USE_TZ and value is not None and timezone.is_naive(value): value = value.replace(tzinfo=timezone.utc) elif desc[1] in (Database.STRING, Database.FIXED_CHAR, Database.LONG_STRING): value = to_unicode(value) casted.append(value) return tuple(casted)
Example #3
Source File: base.py From luscan-devel with GNU General Public License v2.0 | 4 votes |
def _rowfactory(row, cursor): # Cast numeric values as the appropriate Python type based upon the # cursor description, and convert strings to unicode. casted = [] for value, desc in zip(row, cursor.description): if value is not None and desc[1] is Database.NUMBER: precision, scale = desc[4:6] if scale == -127: if precision == 0: # NUMBER column: decimal-precision floating point # This will normally be an integer from a sequence, # but it could be a decimal value. if '.' in value: value = decimal.Decimal(value) else: value = int(value) else: # FLOAT column: binary-precision floating point. # This comes from FloatField columns. value = float(value) elif precision > 0: # NUMBER(p,s) column: decimal-precision fixed point. # This comes from IntField and DecimalField columns. if scale == 0: value = int(value) else: value = decimal.Decimal(value) elif '.' in value: # No type information. This normally comes from a # mathematical expression in the SELECT list. Guess int # or Decimal based on whether it has a decimal point. value = decimal.Decimal(value) else: value = int(value) # datetimes are returned as TIMESTAMP, except the results # of "dates" queries, which are returned as DATETIME. elif desc[1] in (Database.TIMESTAMP, Database.DATETIME): # Confirm that dt is naive before overwriting its tzinfo. if settings.USE_TZ and value is not None and timezone.is_naive(value): value = value.replace(tzinfo=timezone.utc) elif desc[1] in (Database.STRING, Database.FIXED_CHAR, Database.LONG_STRING): value = to_unicode(value) casted.append(value) return tuple(casted)