mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Reverted per Serhiy's request.
This commit is contained in:
parent
2928e5dc65
commit
2a3926fa51
3 changed files with 2 additions and 41 deletions
|
@ -7,10 +7,6 @@
|
||||||
# future enhancements, you should normally quote any identifier that
|
# future enhancements, you should normally quote any identifier that
|
||||||
# is an English language word, even if you do not have to."
|
# is an English language word, even if you do not have to."
|
||||||
|
|
||||||
|
|
||||||
from contextlib import contextmanager
|
|
||||||
|
|
||||||
|
|
||||||
def _quote_name(name):
|
def _quote_name(name):
|
||||||
return '"{0}"'.format(name.replace('"', '""'))
|
return '"{0}"'.format(name.replace('"', '""'))
|
||||||
|
|
||||||
|
@ -19,24 +15,6 @@ def _quote_value(value):
|
||||||
return "'{0}'".format(value.replace("'", "''"))
|
return "'{0}'".format(value.replace("'", "''"))
|
||||||
|
|
||||||
|
|
||||||
def _force_decode(bs, *args, **kwargs):
|
|
||||||
# gh-108590: Don't fail if the database contains invalid Unicode data.
|
|
||||||
try:
|
|
||||||
return bs.decode(*args, **kwargs)
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
return "".join([chr(c) for c in bs])
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def _text_factory(con, factory):
|
|
||||||
saved_factory = con.text_factory
|
|
||||||
con.text_factory = factory
|
|
||||||
try:
|
|
||||||
yield
|
|
||||||
finally:
|
|
||||||
con.text_factory = saved_factory
|
|
||||||
|
|
||||||
|
|
||||||
def _iterdump(connection):
|
def _iterdump(connection):
|
||||||
"""
|
"""
|
||||||
Returns an iterator to the dump of the database in an SQL text format.
|
Returns an iterator to the dump of the database in an SQL text format.
|
||||||
|
@ -96,9 +74,8 @@ def _iterdump(connection):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
query_res = cu.execute(q)
|
query_res = cu.execute(q)
|
||||||
with _text_factory(connection, bytes):
|
for row in query_res:
|
||||||
for row in query_res:
|
yield("{0};".format(row[0]))
|
||||||
yield("{0};".format(_force_decode(row[0])))
|
|
||||||
|
|
||||||
# Now when the type is 'index', 'trigger', or 'view'
|
# Now when the type is 'index', 'trigger', or 'view'
|
||||||
q = """
|
q = """
|
||||||
|
|
|
@ -133,21 +133,6 @@ class DumpTests(MemoryDatabaseMixin, unittest.TestCase):
|
||||||
actual = list(self.cx.iterdump())
|
actual = list(self.cx.iterdump())
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
def test_dump_unicode_invalid(self):
|
|
||||||
# gh-108590
|
|
||||||
expected = [
|
|
||||||
"BEGIN TRANSACTION;",
|
|
||||||
"CREATE TABLE foo (data TEXT);",
|
|
||||||
"INSERT INTO \"foo\" VALUES('a\x9f');",
|
|
||||||
"COMMIT;",
|
|
||||||
]
|
|
||||||
self.cu.executescript("""
|
|
||||||
CREATE TABLE foo (data TEXT);
|
|
||||||
INSERT INTO foo VALUES (CAST(X'619f' AS TEXT));
|
|
||||||
""")
|
|
||||||
actual = list(self.cx.iterdump())
|
|
||||||
self.assertEqual(expected, actual)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Fixed an issue where :meth:`sqlite3.Connection.iterdump` would fail and leave an incomplete SQL dump if a table includes invalid Unicode sequences. Patch by Corvin McPherson
|
|
Loading…
Add table
Add a link
Reference in a new issue