[Python-checkins] r78898 - in python/trunk: Lib/sqlite3/test/regression.py Modules/_sqlite/connection.c
victor.stinner
python-checkins at python.org
Sat Mar 13 04:27:07 CET 2010
Author: victor.stinner
Date: Sat Mar 13 04:27:07 2010
New Revision: 78898
Log:
sqlite3: Fix a segfault on calling a connection with something else than a
string. Initialize all attributes to be able to call the statement destructor
on error.
Avoid also a duplicate connection in some tests: setUp() does already open a
connection (":memory:").
Modified:
python/trunk/Lib/sqlite3/test/regression.py
python/trunk/Modules/_sqlite/connection.c
Modified: python/trunk/Lib/sqlite3/test/regression.py
==============================================================================
--- python/trunk/Lib/sqlite3/test/regression.py (original)
+++ python/trunk/Lib/sqlite3/test/regression.py Sat Mar 13 04:27:07 2010
@@ -232,8 +232,7 @@
Verifies that running a PRAGMA statement that does an autocommit does
work. This did not work in 2.5.3/2.5.4.
"""
- con = sqlite.connect(":memory:")
- cur = con.cursor()
+ cur = self.con.cursor()
cur.execute("create table foo(bar)")
cur.execute("insert into foo(bar) values (5)")
@@ -253,11 +252,17 @@
def __hash__(self):
raise TypeError()
var = NotHashable()
- con = sqlite.connect(":memory:")
- self.assertRaises(TypeError, con.create_function, var)
- self.assertRaises(TypeError, con.create_aggregate, var)
- self.assertRaises(TypeError, con.set_authorizer, var)
- self.assertRaises(TypeError, con.set_progress_handler, var)
+ self.assertRaises(TypeError, self.con.create_function, var)
+ self.assertRaises(TypeError, self.con.create_aggregate, var)
+ self.assertRaises(TypeError, self.con.set_authorizer, var)
+ self.assertRaises(TypeError, self.con.set_progress_handler, var)
+
+ def CheckConnectionCall(self):
+ """
+ Call a connection with a non-string SQL request: check error handling
+ of the statement constructor.
+ """
+ self.assertRaises(sqlite.Warning, self.con, 1)
def suite():
regression_suite = unittest.makeSuite(RegressionTests, "Check")
Modified: python/trunk/Modules/_sqlite/connection.c
==============================================================================
--- python/trunk/Modules/_sqlite/connection.c (original)
+++ python/trunk/Modules/_sqlite/connection.c Sat Mar 13 04:27:07 2010
@@ -1197,6 +1197,12 @@
return NULL;
}
+ statement->db = NULL;
+ statement->st = NULL;
+ statement->sql = NULL;
+ statement->in_use = 0;
+ statement->in_weakreflist = NULL;
+
rc = pysqlite_statement_create(statement, self, sql);
if (rc != SQLITE_OK) {
More information about the Python-checkins
mailing list