本文整理汇总了Python中MySQLdb.constants.FIELD_TYPE.DATE属性的典型用法代码示例。如果您正苦于以下问题:Python FIELD_TYPE.DATE属性的具体用法?Python FIELD_TYPE.DATE怎么用?Python FIELD_TYPE.DATE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类MySQLdb.constants.FIELD_TYPE
的用法示例。
在下文中一共展示了FIELD_TYPE.DATE属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_type
# 需要导入模块: from MySQLdb.constants import FIELD_TYPE [as 别名]
# 或者: from MySQLdb.constants.FIELD_TYPE import DATE [as 别名]
def convert_type(self, value, schema_type):
"""
Takes a value from MySQLdb, and converts it to a value that's safe for
JSON/Google Cloud Storage/BigQuery.
* Datetimes are converted to UTC seconds.
* Decimals are converted to floats.
* Dates are converted to ISO formatted string if given schema_type is
DATE, or UTC seconds otherwise.
* Binary type fields are converted to integer if given schema_type is
INTEGER, or encoded with base64 otherwise. Imported BYTES data must
be base64-encoded according to BigQuery documentation:
https://cloud.google.com/bigquery/data-types
:param value: MySQLdb column value
:type value: Any
:param schema_type: BigQuery data type
:type schema_type: str
"""
if value is None:
return value
if isinstance(value, datetime):
value = calendar.timegm(value.timetuple())
elif isinstance(value, timedelta):
value = value.total_seconds()
elif isinstance(value, Decimal):
value = float(value)
elif isinstance(value, date):
if schema_type == "DATE":
value = value.isoformat()
else:
value = calendar.timegm(value.timetuple())
elif isinstance(value, bytes):
if schema_type == "INTEGER":
value = int.from_bytes(value, "big")
else:
value = base64.standard_b64encode(value).decode('ascii')
return value
示例2: test_set_inequality_membership
# 需要导入模块: from MySQLdb.constants import FIELD_TYPE [as 别名]
# 或者: from MySQLdb.constants.FIELD_TYPE import DATE [as 别名]
def test_set_inequality_membership(self):
self.assertTrue(FIELD_TYPE.DATE != MySQLdb.STRING)
示例3: test_DBAPISet_set_inequality_membership
# 需要导入模块: from MySQLdb.constants import FIELD_TYPE [as 别名]
# 或者: from MySQLdb.constants.FIELD_TYPE import DATE [as 别名]
def test_DBAPISet_set_inequality_membership():
assert FIELD_TYPE.DATE != STRING