Skip to content

Commit 89be29f

Browse files
committed
🐛 update CREATE VIEW statements to use quoted SQLite identifiers for view names
1 parent 3af13e2 commit 89be29f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/mysql_to_sqlite3/transporter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,8 @@ def _mysql_viewdef_to_sqlite(self, view_select_sql: str, view_name: str) -> str:
909909
sn = re.escape(self._mysql_database)
910910
for pat in (rf"`{sn}`\.", rf'"{sn}"\.', rf"\b{sn}\."):
911911
stripped_sql = re.sub(pat, "", stripped_sql)
912-
return f'CREATE VIEW IF NOT EXISTS "{view_name}" AS\n{stripped_sql};'
912+
view_ident = self._quote_sqlite_identifier(view_name)
913+
return f"CREATE VIEW IF NOT EXISTS {view_ident} AS\n{stripped_sql};"
913914

914915
# Remove schema qualifiers that match schema_name on tables
915916
for tbl in tree.find_all(exp.Table):
@@ -923,7 +924,8 @@ def _mysql_viewdef_to_sqlite(self, view_select_sql: str, view_name: str) -> str:
923924
col.set("db", None)
924925

925926
sqlite_select = tree.sql(dialect="sqlite")
926-
return f'CREATE VIEW IF NOT EXISTS "{view_name}" AS\n{sqlite_select};'
927+
view_ident = self._quote_sqlite_identifier(view_name)
928+
return f"CREATE VIEW IF NOT EXISTS {view_ident} AS\n{sqlite_select};"
927929

928930
def _build_create_view_sql(self, view_name: str) -> str:
929931
"""Build a CREATE VIEW statement for SQLite from a MySQL VIEW definition."""

0 commit comments

Comments
 (0)