1 | n/a | import sqlite3 |
---|
2 | n/a | import datetime |
---|
3 | n/a | |
---|
4 | n/a | con = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) |
---|
5 | n/a | cur = con.cursor() |
---|
6 | n/a | cur.execute("create table test(d date, ts timestamp)") |
---|
7 | n/a | |
---|
8 | n/a | today = datetime.date.today() |
---|
9 | n/a | now = datetime.datetime.now() |
---|
10 | n/a | |
---|
11 | n/a | cur.execute("insert into test(d, ts) values (?, ?)", (today, now)) |
---|
12 | n/a | cur.execute("select d, ts from test") |
---|
13 | n/a | row = cur.fetchone() |
---|
14 | n/a | print(today, "=>", row[0], type(row[0])) |
---|
15 | n/a | print(now, "=>", row[1], type(row[1])) |
---|
16 | n/a | |
---|
17 | n/a | cur.execute('select current_date as "d [date]", current_timestamp as "ts [timestamp]"') |
---|
18 | n/a | row = cur.fetchone() |
---|
19 | n/a | print("current_date", row[0], type(row[0])) |
---|
20 | n/a | print("current_timestamp", row[1], type(row[1])) |
---|