當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。