ยปCore Development>Code coverage>Doc/includes/sqlite3/pysqlite_datetime.py

Python code coverage for Doc/includes/sqlite3/pysqlite_datetime.py

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