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