dbapi.py 959 字节
Newer Older
S
slguan 已提交
1 2 3 4 5 6
"""Type Objects and Constructors.
"""

import time
import datetime

7

S
slguan 已提交
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

S
slguan 已提交
21 22 23 24
Date = datetime.date
Time = datetime.time
Timestamp = datetime.datetime

25

S
slguan 已提交
26 27 28
def DataFromTicks(ticks):
    return Date(*time.localtime(ticks)[:3])

29

S
slguan 已提交
30 31 32
def TimeFromTicks(ticks):
    return Time(*time.localtime(ticks)[3:6])

33

S
slguan 已提交
34 35 36
def TimestampFromTicks(ticks):
    return Timestamp(*time.localtime(ticks)[:6])

37

S
slguan 已提交
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()