本文整理汇总了Python中cx_Oracle.DATETIME属性的典型用法代码示例。如果您正苦于以下问题:Python cx_Oracle.DATETIME属性的具体用法?Python cx_Oracle.DATETIME怎么用?Python cx_Oracle.DATETIME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cx_Oracle
的用法示例。
在下文中一共展示了cx_Oracle.DATETIME属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mapArgs
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import DATETIME [as 别名]
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
示例2: _rowfactory
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import DATETIME [as 别名]
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)