diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2021-08-08 05:49:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-08 05:49:44 (GMT) |
commit | 0eec6276fdcdde5221370d92b50ea95851760c72 (patch) | |
tree | 35fa0e56f83f404eb2120ec1963c6b5e15813d34 /Lib/sqlite3/test/regression.py | |
parent | ebecffdb6d5fffa4249f9a813f1fc1915926feb5 (diff) | |
download | cpython-0eec6276fdcdde5221370d92b50ea95851760c72.zip cpython-0eec6276fdcdde5221370d92b50ea95851760c72.tar.gz cpython-0eec6276fdcdde5221370d92b50ea95851760c72.tar.bz2 |
bpo-44859: Improve error handling in sqlite3 and and raise more accurate exceptions. (GH-27654)
* MemoryError is now raised instead of sqlite3.Warning when
memory is not enough for encoding a statement to UTF-8
in Connection.__call__() and Cursor.execute().
* UnicodEncodeError is now raised instead of sqlite3.Warning when
the statement contains surrogate characters
in Connection.__call__() and Cursor.execute().
* TypeError is now raised instead of ValueError for non-string
script argument in Cursor.executescript().
* ValueError is now raised for script containing the null
character instead of truncating it in Cursor.executescript().
* Correctly handle exceptions raised when getting boolean value
of the result of the progress handler.
* Add many tests covering different corner cases.
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Diffstat (limited to 'Lib/sqlite3/test/regression.py')
-rw-r--r-- | Lib/sqlite3/test/regression.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index 6c093d7..ddf36e7 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -21,6 +21,7 @@ # 3. This notice may not be removed or altered from any source distribution. import datetime +import sys import unittest import sqlite3 as sqlite import weakref @@ -273,7 +274,7 @@ class RegressionTests(unittest.TestCase): Call a connection with a non-string SQL request: check error handling of the statement constructor. """ - self.assertRaises(TypeError, self.con, 1) + self.assertRaises(TypeError, self.con, b"select 1") def test_collation(self): def collation_cb(a, b): @@ -344,6 +345,26 @@ class RegressionTests(unittest.TestCase): self.assertRaises(ValueError, cur.execute, " \0select 2") self.assertRaises(ValueError, cur.execute, "select 2\0") + def test_surrogates(self): + con = sqlite.connect(":memory:") + self.assertRaises(UnicodeEncodeError, con, "select '\ud8ff'") + self.assertRaises(UnicodeEncodeError, con, "select '\udcff'") + cur = con.cursor() + self.assertRaises(UnicodeEncodeError, cur.execute, "select '\ud8ff'") + self.assertRaises(UnicodeEncodeError, cur.execute, "select '\udcff'") + + @unittest.skipUnless(sys.maxsize > 2**32, 'requires 64bit platform') + @support.bigmemtest(size=2**31, memuse=4, dry_run=False) + def test_large_sql(self, maxsize): + # Test two cases: size+1 > INT_MAX and size+1 <= INT_MAX. + for size in (2**31, 2**31-2): + con = sqlite.connect(":memory:") + sql = "select 1".ljust(size) + self.assertRaises(sqlite.DataError, con, sql) + cur = con.cursor() + self.assertRaises(sqlite.DataError, cur.execute, sql) + del sql + def test_commit_cursor_reset(self): """ Connection.commit() did reset cursors, which made sqlite3 |