»Core Development>Code coverage>Lib/sqlite3/dbapi2.py

Python code coverage for Lib/sqlite3/dbapi2.py

#countcontent
1n/a# pysqlite2/dbapi2.py: the DB-API 2.0 interface
2n/a#
3n/a# Copyright (C) 2004-2005 Gerhard Häring <gh@ghaering.de>
4n/a#
5n/a# This file is part of pysqlite.
6n/a#
7n/a# This software is provided 'as-is', without any express or implied
8n/a# warranty. In no event will the authors be held liable for any damages
9n/a# arising from the use of this software.
10n/a#
11n/a# Permission is granted to anyone to use this software for any purpose,
12n/a# including commercial applications, and to alter it and redistribute it
13n/a# freely, subject to the following restrictions:
14n/a#
15n/a# 1. The origin of this software must not be misrepresented; you must not
16n/a# claim that you wrote the original software. If you use this software
17n/a# in a product, an acknowledgment in the product documentation would be
18n/a# appreciated but is not required.
19n/a# 2. Altered source versions must be plainly marked as such, and must not be
20n/a# misrepresented as being the original software.
21n/a# 3. This notice may not be removed or altered from any source distribution.
22n/a
23n/aimport datetime
24n/aimport time
25n/aimport collections.abc
26n/a
27n/afrom _sqlite3 import *
28n/a
29n/aparamstyle = "qmark"
30n/a
31n/athreadsafety = 1
32n/a
33n/aapilevel = "2.0"
34n/a
35n/aDate = datetime.date
36n/a
37n/aTime = datetime.time
38n/a
39n/aTimestamp = datetime.datetime
40n/a
41n/adef DateFromTicks(ticks):
42n/a return Date(*time.localtime(ticks)[:3])
43n/a
44n/adef TimeFromTicks(ticks):
45n/a return Time(*time.localtime(ticks)[3:6])
46n/a
47n/adef TimestampFromTicks(ticks):
48n/a return Timestamp(*time.localtime(ticks)[:6])
49n/a
50n/aversion_info = tuple([int(x) for x in version.split(".")])
51n/asqlite_version_info = tuple([int(x) for x in sqlite_version.split(".")])
52n/a
53n/aBinary = memoryview
54n/acollections.abc.Sequence.register(Row)
55n/a
56n/adef register_adapters_and_converters():
57n/a def adapt_date(val):
58n/a return val.isoformat()
59n/a
60n/a def adapt_datetime(val):
61n/a return val.isoformat(" ")
62n/a
63n/a def convert_date(val):
64n/a return datetime.date(*map(int, val.split(b"-")))
65n/a
66n/a def convert_timestamp(val):
67n/a datepart, timepart = val.split(b" ")
68n/a year, month, day = map(int, datepart.split(b"-"))
69n/a timepart_full = timepart.split(b".")
70n/a hours, minutes, seconds = map(int, timepart_full[0].split(b":"))
71n/a if len(timepart_full) == 2:
72n/a microseconds = int('{:0<6.6}'.format(timepart_full[1].decode()))
73n/a else:
74n/a microseconds = 0
75n/a
76n/a val = datetime.datetime(year, month, day, hours, minutes, seconds, microseconds)
77n/a return val
78n/a
79n/a
80n/a register_adapter(datetime.date, adapt_date)
81n/a register_adapter(datetime.datetime, adapt_datetime)
82n/a register_converter("date", convert_date)
83n/a register_converter("timestamp", convert_timestamp)
84n/a
85n/aregister_adapters_and_converters()
86n/a
87n/a# Clean up namespace
88n/a
89n/adel(register_adapters_and_converters)