summaryrefslogtreecommitdiffstats
path: root/Lib/sqlite3/dump.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/sqlite3/dump.py')
-rw-r--r--Lib/sqlite3/dump.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/Lib/sqlite3/dump.py b/Lib/sqlite3/dump.py
index 719dfc8..9dcce7d 100644
--- a/Lib/sqlite3/dump.py
+++ b/Lib/sqlite3/dump.py
@@ -15,7 +15,7 @@ def _quote_value(value):
return "'{0}'".format(value.replace("'", "''"))
-def _iterdump(connection):
+def _iterdump(connection, *, filter=None):
"""
Returns an iterator to the dump of the database in an SQL text format.
@@ -32,15 +32,23 @@ def _iterdump(connection):
yield('PRAGMA foreign_keys=OFF;')
yield('BEGIN TRANSACTION;')
+ if filter:
+ # Return database objects which match the filter pattern.
+ filter_name_clause = 'AND "name" LIKE ?'
+ params = [filter]
+ else:
+ filter_name_clause = ""
+ params = []
# sqlite_master table contains the SQL CREATE statements for the database.
- q = """
+ q = f"""
SELECT "name", "type", "sql"
FROM "sqlite_master"
WHERE "sql" NOT NULL AND
"type" == 'table'
+ {filter_name_clause}
ORDER BY "name"
"""
- schema_res = cu.execute(q)
+ schema_res = cu.execute(q, params)
sqlite_sequence = []
for table_name, type, sql in schema_res.fetchall():
if table_name == 'sqlite_sequence':
@@ -82,13 +90,14 @@ def _iterdump(connection):
yield("{0};".format(row[0]))
# Now when the type is 'index', 'trigger', or 'view'
- q = """
+ q = f"""
SELECT "name", "type", "sql"
FROM "sqlite_master"
WHERE "sql" NOT NULL AND
"type" IN ('index', 'trigger', 'view')
+ {filter_name_clause}
"""
- schema_res = cu.execute(q)
+ schema_res = cu.execute(q, params)
for name, type, sql in schema_res.fetchall():
yield('{0};'.format(sql))