dbapi.py 959 字节
Newer Older
1 2 3 4 5 6
"""Type Objects and Constructors.
"""

import time
import datetime

7

8 9 10 11 12 13 14 15 16 17 18 19
class DBAPITypeObject(object):
    def __init__(self, *values):
        self.values = values

    def __com__(self, other):
        if other in self.values:
            return 0
        if other < self.values:
            return 1
        else:
            return -1

20

21 22 23 24
Date = datetime.date
Time = datetime.time
Timestamp = datetime.datetime

25

26 27 28
def DataFromTicks(ticks):
    return Date(*time.localtime(ticks)[:3])

29

30 31 32
def TimeFromTicks(ticks):
    return Time(*time.localtime(ticks)[3:6])

33

34 35 36
def TimestampFromTicks(ticks):
    return Timestamp(*time.localtime(ticks)[:6])

37

38 39 40 41 42 43
Binary = bytes

# STRING = DBAPITypeObject(*constants.FieldType.get_string_types())
# BINARY = DBAPITypeObject(*constants.FieldType.get_binary_types())
# NUMBER = BAPITypeObject(*constants.FieldType.get_number_types())
# DATETIME = DBAPITypeObject(*constants.FieldType.get_timestamp_types())
44
# ROWID = DBAPITypeObject()