#15109: revert '%'->'format' changes in 4b105d328fe7 to fix regression.
authorR David Murray <rdmurray@bitdance.com>
Fri, 11 Jan 2013 02:10:40 +0000 (21:10 -0500)
committerR David Murray <rdmurray@bitdance.com>
Fri, 11 Jan 2013 02:10:40 +0000 (21:10 -0500)
With '%', non-ascii worked because the '%' automatically got promoted to
unicode.  With format that doesn't happen, which led to encoding errors.  This
fix goes back to using %, and adds a test to make sure non-ascii string values
work in iterdump.

Lib/sqlite3/dump.py
Lib/sqlite3/test/dump.py
Misc/NEWS

index de9c368be3014e7e55f56a69457a003854381629..e5c5ef226db01d2adce37c76c3c96a148fcb392d 100644 (file)
@@ -43,7 +43,7 @@ def _iterdump(connection):
         #        qtable,
         #        sql.replace("''")))
         else:
-            yield('{0};'.format(sql))
+            yield('%s;' % sql)
 
         # Build the insert statement for each row of the current table
         table_name_ident = table_name.replace('"', '""')
@@ -54,7 +54,7 @@ def _iterdump(connection):
             ",".join("""'||quote("{0}")||'""".format(col.replace('"', '""')) for col in column_names))
         query_res = cu.execute(q)
         for row in query_res:
-            yield("{0};".format(row[0]))
+            yield("%s;" % row[0])
 
     # Now when the type is 'index', 'trigger', or 'view'
     q = """
@@ -65,6 +65,6 @@ def _iterdump(connection):
         """
     schema_res = cu.execute(q)
     for name, type, sql in schema_res.fetchall():
-        yield('{0};'.format(sql))
+        yield('%s;' % sql)
 
     yield('COMMIT;')
index 195c13942a018a94e2bc88b08ec32966bc7860e5..b7de810c7a54c06983b154b47d743946112047e8 100644 (file)
@@ -29,6 +29,8 @@ class DumpTests(unittest.TestCase):
                 ,
                 "INSERT INTO \"t1\" VALUES(2,'foo2',30,30);"
                 ,
+                u"INSERT INTO \"t1\" VALUES(3,'f\xc3\xb6',40,10);"
+                ,
                 "CREATE TABLE t2(id integer, t2_i1 integer, " \
                 "t2_i2 integer, primary key (id)," \
                 "foreign key(t2_i1) references t1(t1_i1));"
index 6bb2549a124268d59bced4401ef0d3ddd5aecc31..469ca8b2fa3f4c5220a6825fbb99be68aee191bb 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -186,6 +186,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #15109: Fix regression in sqlite3's iterdump method where it would
+  die with an encoding error if the database contained string values
+  containing non-ASCII.  (Regression was introduced by fix for 9750).
+
 - Issue #15545: Fix regression in sqlite3's iterdump method where it was
   failing if the connection used a row factory (such as sqlite3.Row) that
   produced unsortable objects. (Regression was introduced by fix for 9750).