|
6 | 6 | import pathlib |
7 | 7 | from runpy import run_module |
8 | 8 | import sqlite_utils |
9 | | -from sqlite_utils.db import AlterError, BadMultiValues, DescIndex, NoTable |
| 9 | +from sqlite_utils.db import ( |
| 10 | + AlterError, |
| 11 | + BadMultiValues, |
| 12 | + DescIndex, |
| 13 | + NoTable, |
| 14 | + quote_identifier, |
| 15 | +) |
10 | 16 | from sqlite_utils.plugins import pm, get_plugins |
11 | 17 | from sqlite_utils.utils import maximize_csv_field_size_limit |
12 | 18 | from sqlite_utils import recipes |
@@ -1967,7 +1973,9 @@ def memory( |
1967 | 1973 | view_names.append("t") |
1968 | 1974 | for view_name in view_names: |
1969 | 1975 | if not db[view_name].exists(): |
1970 | | - db.create_view(view_name, "select * from [{}]".format(file_table)) |
| 1976 | + db.create_view( |
| 1977 | + view_name, "select * from {}".format(quote_identifier(file_table)) |
| 1978 | + ) |
1971 | 1979 |
|
1972 | 1980 | if fp: |
1973 | 1981 | fp.close() |
@@ -2230,8 +2238,8 @@ def rows( |
2230 | 2238 | """ |
2231 | 2239 | columns = "*" |
2232 | 2240 | if column: |
2233 | | - columns = ", ".join("[{}]".format(c) for c in column) |
2234 | | - sql = "select {} from [{}]".format(columns, dbtable) |
| 2241 | + columns = ", ".join(quote_identifier(c) for c in column) |
| 2242 | + sql = "select {} from {}".format(columns, quote_identifier(dbtable)) |
2235 | 2243 | if where: |
2236 | 2244 | sql += " where " + where |
2237 | 2245 | if order: |
@@ -2288,10 +2296,10 @@ def triggers( |
2288 | 2296 | \b |
2289 | 2297 | sqlite-utils triggers trees.db |
2290 | 2298 | """ |
2291 | | - sql = "select name, tbl_name as [table], sql from sqlite_master where type = 'trigger'" |
| 2299 | + sql = "select name, tbl_name as \"table\", sql from sqlite_master where type = 'trigger'" |
2292 | 2300 | if tables: |
2293 | 2301 | quote = sqlite_utils.Database(memory=True).quote |
2294 | | - sql += " and [table] in ({})".format( |
| 2302 | + sql += ' and "table" in ({})'.format( |
2295 | 2303 | ", ".join(quote(table) for table in tables) |
2296 | 2304 | ) |
2297 | 2305 | ctx.invoke( |
|
0 commit comments