mirror of
https://github.com/python/cpython.git
synced 2025-12-15 21:44:50 +00:00
Merged changes from standalone version 2.3.3. This should probably all be
merged into the 2.5 maintenance branch: - self->statement was not checked while fetching data, which could lead to crashes if you used the pysqlite API in unusual ways. Closing the cursor and continuing to fetch data was enough. - Converters are stored in a converters dictionary. The converter name is uppercased first. The old upper-casing algorithm was wrong and was replaced by a simple call to the Python string's upper() method instead. -Applied patch by Glyph Lefkowitz that fixes the problem with subsequent SQLITE_SCHEMA errors. - Improvement to the row type: rows can now be iterated over and have a keys() method. This improves compatibility with both tuple and dict a lot. - A bugfix for the subsecond resolution in timestamps. - Corrected the way the flags PARSE_DECLTYPES and PARSE_COLNAMES are checked for. Now they work as documented. - gcc on Linux sucks. It exports all symbols by default in shared libraries, so if symbols are not unique it can lead to problems with symbol lookup. pysqlite used to crash under Apache when mod_cache was enabled because both modules had the symbol cache_init. I fixed this by applying the prefix pysqlite_ almost everywhere. Sigh.
This commit is contained in:
parent
b1a8ef6297
commit
0741a60ca7
22 changed files with 572 additions and 488 deletions
|
|
@ -91,7 +91,7 @@ class RowFactoryTests(unittest.TestCase):
|
|||
list),
|
||||
"row is not instance of list")
|
||||
|
||||
def CheckSqliteRow(self):
|
||||
def CheckSqliteRowIndex(self):
|
||||
self.con.row_factory = sqlite.Row
|
||||
row = self.con.execute("select 1 as a, 2 as b").fetchone()
|
||||
self.failUnless(isinstance(row,
|
||||
|
|
@ -110,6 +110,27 @@ class RowFactoryTests(unittest.TestCase):
|
|||
self.failUnless(col1 == 1, "by index: wrong result for column 0")
|
||||
self.failUnless(col2 == 2, "by index: wrong result for column 1")
|
||||
|
||||
def CheckSqliteRowIter(self):
|
||||
"""Checks if the row object is iterable"""
|
||||
self.con.row_factory = sqlite.Row
|
||||
row = self.con.execute("select 1 as a, 2 as b").fetchone()
|
||||
for col in row:
|
||||
pass
|
||||
|
||||
def CheckSqliteRowAsTuple(self):
|
||||
"""Checks if the row object can be converted to a tuple"""
|
||||
self.con.row_factory = sqlite.Row
|
||||
row = self.con.execute("select 1 as a, 2 as b").fetchone()
|
||||
t = tuple(row)
|
||||
|
||||
def CheckSqliteRowAsDict(self):
|
||||
"""Checks if the row object can be correctly converted to a dictionary"""
|
||||
self.con.row_factory = sqlite.Row
|
||||
row = self.con.execute("select 1 as a, 2 as b").fetchone()
|
||||
d = dict(row)
|
||||
self.failUnlessEqual(d["a"], row["a"])
|
||||
self.failUnlessEqual(d["b"], row["b"])
|
||||
|
||||
def tearDown(self):
|
||||
self.con.close()
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,16 @@ class RegressionTests(unittest.TestCase):
|
|||
cur.execute('select 1 as "foo baz"')
|
||||
self.failUnlessEqual(cur.description[0][0], "foo baz")
|
||||
|
||||
def CheckStatementAvailable(self):
|
||||
# pysqlite up to 2.3.2 crashed on this, because the active statement handle was not checked
|
||||
# before trying to fetch data from it. close() destroys the active statement ...
|
||||
con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
|
||||
cur = con.cursor()
|
||||
cur.execute("select 4 union select 5")
|
||||
cur.close()
|
||||
cur.fetchone()
|
||||
cur.fetchone()
|
||||
|
||||
def suite():
|
||||
regression_suite = unittest.makeSuite(RegressionTests, "Check")
|
||||
return unittest.TestSuite((regression_suite,))
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ class DeclTypesTests(unittest.TestCase):
|
|||
# and implement two custom ones
|
||||
sqlite.converters["BOOL"] = lambda x: bool(int(x))
|
||||
sqlite.converters["FOO"] = DeclTypesTests.Foo
|
||||
sqlite.converters["WRONG"] = lambda x: "WRONG"
|
||||
|
||||
def tearDown(self):
|
||||
del sqlite.converters["FLOAT"]
|
||||
|
|
@ -117,7 +118,7 @@ class DeclTypesTests(unittest.TestCase):
|
|||
def CheckString(self):
|
||||
# default
|
||||
self.cur.execute("insert into test(s) values (?)", ("foo",))
|
||||
self.cur.execute("select s from test")
|
||||
self.cur.execute('select s as "s [WRONG]" from test')
|
||||
row = self.cur.fetchone()
|
||||
self.failUnlessEqual(row[0], "foo")
|
||||
|
||||
|
|
@ -204,26 +205,32 @@ class DeclTypesTests(unittest.TestCase):
|
|||
|
||||
class ColNamesTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES|sqlite.PARSE_DECLTYPES)
|
||||
self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)
|
||||
self.cur = self.con.cursor()
|
||||
self.cur.execute("create table test(x foo)")
|
||||
|
||||
sqlite.converters["FOO"] = lambda x: "[%s]" % x
|
||||
sqlite.converters["BAR"] = lambda x: "<%s>" % x
|
||||
sqlite.converters["EXC"] = lambda x: 5/0
|
||||
sqlite.converters["B1B1"] = lambda x: "MARKER"
|
||||
|
||||
def tearDown(self):
|
||||
del sqlite.converters["FOO"]
|
||||
del sqlite.converters["BAR"]
|
||||
del sqlite.converters["EXC"]
|
||||
del sqlite.converters["B1B1"]
|
||||
self.cur.close()
|
||||
self.con.close()
|
||||
|
||||
def CheckDeclType(self):
|
||||
def CheckDeclTypeNotUsed(self):
|
||||
"""
|
||||
Assures that the declared type is not used when PARSE_DECLTYPES
|
||||
is not set.
|
||||
"""
|
||||
self.cur.execute("insert into test(x) values (?)", ("xxx",))
|
||||
self.cur.execute("select x from test")
|
||||
val = self.cur.fetchone()[0]
|
||||
self.failUnlessEqual(val, "[xxx]")
|
||||
self.failUnlessEqual(val, "xxx")
|
||||
|
||||
def CheckNone(self):
|
||||
self.cur.execute("insert into test(x) values (?)", (None,))
|
||||
|
|
@ -241,6 +248,11 @@ class ColNamesTests(unittest.TestCase):
|
|||
# whitespace should be stripped.
|
||||
self.failUnlessEqual(self.cur.description[0][0], "x")
|
||||
|
||||
def CheckCaseInConverterName(self):
|
||||
self.cur.execute("""select 'other' as "x [b1b1]\"""")
|
||||
val = self.cur.fetchone()[0]
|
||||
self.failUnlessEqual(val, "MARKER")
|
||||
|
||||
def CheckCursorDescriptionNoRow(self):
|
||||
"""
|
||||
cursor.description should at least provide the column name(s), even if
|
||||
|
|
@ -334,6 +346,13 @@ class DateTimeTests(unittest.TestCase):
|
|||
ts2 = self.cur.fetchone()[0]
|
||||
self.failUnlessEqual(ts, ts2)
|
||||
|
||||
def CheckDateTimeSubSecondsFloatingPoint(self):
|
||||
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 510241)
|
||||
self.cur.execute("insert into test(ts) values (?)", (ts,))
|
||||
self.cur.execute("select ts from test")
|
||||
ts2 = self.cur.fetchone()[0]
|
||||
self.failUnlessEqual(ts, ts2)
|
||||
|
||||
def suite():
|
||||
sqlite_type_suite = unittest.makeSuite(SqliteTypeTests, "Check")
|
||||
decltypes_type_suite = unittest.makeSuite(DeclTypesTests, "Check")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue