@@ -15,7 +15,7 @@ def _quote_value(value):
1515 return "'{0}'" .format (value .replace ("'" , "''" ))
1616
1717
18- def _iterdump (connection ):
18+ def _iterdump (connection , * , filter = None ):
1919 """
2020 Returns an iterator to the dump of the database in an SQL text format.
2121
@@ -32,15 +32,23 @@ def _iterdump(connection):
3232 yield ('PRAGMA foreign_keys=OFF;' )
3333 yield ('BEGIN TRANSACTION;' )
3434
35+ if filter :
36+ # Return database objects which match the filter pattern.
37+ filter_name_clause = 'AND "name" LIKE %s'
38+ params = [filter ]
39+ else :
40+ filter_name_clause = ""
41+ params = []
3542 # sqlite_master table contains the SQL CREATE statements for the database.
36- q = """
43+ q = f """
3744 SELECT "name", "type", "sql"
3845 FROM "sqlite_master"
3946 WHERE "sql" NOT NULL AND
4047 "type" == 'table'
48+ { filter_name_clause }
4149 ORDER BY "name"
4250 """
43- schema_res = cu .execute (q )
51+ schema_res = cu .execute (q , params )
4452 sqlite_sequence = []
4553 for table_name , type , sql in schema_res .fetchall ():
4654 if table_name == 'sqlite_sequence' :
@@ -82,11 +90,12 @@ def _iterdump(connection):
8290 yield ("{0};" .format (row [0 ]))
8391
8492 # Now when the type is 'index', 'trigger', or 'view'
85- q = """
93+ q = f """
8694 SELECT "name", "type", "sql"
8795 FROM "sqlite_master"
8896 WHERE "sql" NOT NULL AND
8997 "type" IN ('index', 'trigger', 'view')
98+ { filter_name_clause }
9099 """
91100 schema_res = cu .execute (q )
92101 for name , type , sql in schema_res .fetchall ():
0 commit comments