当前位置: 首页>>代码示例>>Python>>正文


Python FIELD_TYPE.DATE属性代码示例

本文整理汇总了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 
开发者ID:apache,项目名称:airflow,代码行数:40,代码来源:mysql_to_gcs.py

示例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) 
开发者ID:PyMySQL,项目名称:mysqlclient-python,代码行数:4,代码来源:test_MySQLdb_nonstandard.py

示例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 
开发者ID:PyMySQL,项目名称:mysqlclient-python,代码行数:4,代码来源:__init__.py


注:本文中的MySQLdb.constants.FIELD_TYPE.DATE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。