Package sqlite3 ::
Module dbapi2
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import datetime
25 import time
26
27 from _sqlite3 import *
28
29 paramstyle = "qmark"
30
31 threadsafety = 1
32
33 apilevel = "2.0"
34
35 Date = datetime.date
36
37 Time = datetime.time
38
39 Timestamp = datetime.datetime
40
42 return apply(Date, time.localtime(ticks)[:3])
43
45 return apply(Time, time.localtime(ticks)[3:6])
46
48 return apply(Timestamp, time.localtime(ticks)[:6])
49
50 version_info = tuple([int(x) for x in version.split(".")])
51 sqlite_version_info = tuple([int(x) for x in sqlite_version.split(".")])
52
53 Binary = buffer
54
56 def adapt_date(val):
57 return val.isoformat()
58
59 def adapt_datetime(val):
60 return val.isoformat(" ")
61
62 def convert_date(val):
63 return datetime.date(*map(int, val.split("-")))
64
65 def convert_timestamp(val):
66 datepart, timepart = val.split(" ")
67 year, month, day = map(int, datepart.split("-"))
68 timepart_full = timepart.split(".")
69 hours, minutes, seconds = map(int, timepart_full[0].split(":"))
70 if len(timepart_full) == 2:
71 microseconds = int(float("0." + timepart_full[1]) * 1000000)
72 else:
73 microseconds = 0
74
75 val = datetime.datetime(year, month, day, hours, minutes, seconds, microseconds)
76 return val
77
78
79 register_adapter(datetime.date, adapt_date)
80 register_adapter(datetime.datetime, adapt_datetime)
81 register_converter("date", convert_date)
82 register_converter("timestamp", convert_timestamp)
83
84 register_adapters_and_converters()
85
86
87
88 del(register_adapters_and_converters)
89