mirror of https://github.com/python/cpython.git
The sqlite3 module did cut off data from the SQLite database at the first null
character before sending it to a custom converter. This has been fixed now.
This commit is contained in:
parent
6ffe499397
commit
762fbd3485
|
@ -21,7 +21,7 @@
|
||||||
# misrepresented as being the original software.
|
# misrepresented as being the original software.
|
||||||
# 3. This notice may not be removed or altered from any source distribution.
|
# 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
import datetime
|
import bz2, datetime
|
||||||
import unittest
|
import unittest
|
||||||
import sqlite3 as sqlite
|
import sqlite3 as sqlite
|
||||||
|
|
||||||
|
@ -273,6 +273,23 @@ def CheckCasterIsUsed(self):
|
||||||
val = self.cur.fetchone()[0]
|
val = self.cur.fetchone()[0]
|
||||||
self.failUnlessEqual(type(val), float)
|
self.failUnlessEqual(type(val), float)
|
||||||
|
|
||||||
|
class BinaryConverterTests(unittest.TestCase):
|
||||||
|
def convert(s):
|
||||||
|
return bz2.decompress(s)
|
||||||
|
convert = staticmethod(convert)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)
|
||||||
|
sqlite.register_converter("bin", BinaryConverterTests.convert)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.con.close()
|
||||||
|
|
||||||
|
def CheckBinaryInputForConverter(self):
|
||||||
|
testdata = "abcdefg" * 10
|
||||||
|
result = self.con.execute('select ? as "x [bin]"', (buffer(bz2.compress(testdata)),)).fetchone()[0]
|
||||||
|
self.failUnlessEqual(testdata, result)
|
||||||
|
|
||||||
class DateTimeTests(unittest.TestCase):
|
class DateTimeTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
|
self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
|
||||||
|
@ -322,8 +339,9 @@ def suite():
|
||||||
decltypes_type_suite = unittest.makeSuite(DeclTypesTests, "Check")
|
decltypes_type_suite = unittest.makeSuite(DeclTypesTests, "Check")
|
||||||
colnames_type_suite = unittest.makeSuite(ColNamesTests, "Check")
|
colnames_type_suite = unittest.makeSuite(ColNamesTests, "Check")
|
||||||
adaptation_suite = unittest.makeSuite(ObjectAdaptationTests, "Check")
|
adaptation_suite = unittest.makeSuite(ObjectAdaptationTests, "Check")
|
||||||
|
bin_suite = unittest.makeSuite(BinaryConverterTests, "Check")
|
||||||
date_suite = unittest.makeSuite(DateTimeTests, "Check")
|
date_suite = unittest.makeSuite(DateTimeTests, "Check")
|
||||||
return unittest.TestSuite((sqlite_type_suite, decltypes_type_suite, colnames_type_suite, adaptation_suite, date_suite))
|
return unittest.TestSuite((sqlite_type_suite, decltypes_type_suite, colnames_type_suite, adaptation_suite, bin_suite, date_suite))
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
runner = unittest.TextTestRunner()
|
runner = unittest.TextTestRunner()
|
||||||
|
|
|
@ -45,6 +45,10 @@ Library
|
||||||
- A bug was fixed in logging.config.fileConfig() which caused a crash on
|
- A bug was fixed in logging.config.fileConfig() which caused a crash on
|
||||||
shutdown when fileConfig() was called multiple times.
|
shutdown when fileConfig() was called multiple times.
|
||||||
|
|
||||||
|
- The sqlite3 module did cut off data from the SQLite database at the first
|
||||||
|
null character before sending it to a custom converter. This has been fixed
|
||||||
|
now.
|
||||||
|
|
||||||
Extension Modules
|
Extension Modules
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
|
|
@ -321,12 +321,13 @@ PyObject* _fetch_one_row(Cursor* self)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (converter != Py_None) {
|
if (converter != Py_None) {
|
||||||
val_str = (const char*)sqlite3_column_text(self->statement->st, i);
|
nbytes = sqlite3_column_bytes(self->statement->st, i);
|
||||||
|
val_str = (const char*)sqlite3_column_blob(self->statement->st, i);
|
||||||
if (!val_str) {
|
if (!val_str) {
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
converted = Py_None;
|
converted = Py_None;
|
||||||
} else {
|
} else {
|
||||||
item = PyString_FromString(val_str);
|
item = PyString_FromStringAndSize(val_str, nbytes);
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#define PYSQLITE_MODULE_H
|
#define PYSQLITE_MODULE_H
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
|
||||||
#define PYSQLITE_VERSION "2.3.1"
|
#define PYSQLITE_VERSION "2.3.2"
|
||||||
|
|
||||||
extern PyObject* Error;
|
extern PyObject* Error;
|
||||||
extern PyObject* Warning;
|
extern PyObject* Warning;
|
||||||
|
|
Loading…
Reference in New Issue