本文整理匯總了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