diff --git a/rslib/src/storage/notetype/field_names_for_notes.sql b/rslib/src/storage/notetype/field_names_for_notes.sql index 3aa20c787..ab9b656f0 100644 --- a/rslib/src/storage/notetype/field_names_for_notes.sql +++ b/rslib/src/storage/notetype/field_names_for_notes.sql @@ -1,5 +1,5 @@ SELECT DISTINCT name -FROM FIELDS +FROM fields WHERE ntid IN ( SELECT mid FROM notes diff --git a/rslib/src/storage/notetype/get_fields.sql b/rslib/src/storage/notetype/get_fields.sql index 0213207bf..b0bd97b4a 100644 --- a/rslib/src/storage/notetype/get_fields.sql +++ b/rslib/src/storage/notetype/get_fields.sql @@ -1,6 +1,6 @@ SELECT ord, name, config -FROM FIELDS +FROM fields WHERE ntid = ? ORDER BY ord \ No newline at end of file diff --git a/rslib/src/storage/notetype/update_fields.sql b/rslib/src/storage/notetype/update_fields.sql index 86eeb85b0..ce141936f 100644 --- a/rslib/src/storage/notetype/update_fields.sql +++ b/rslib/src/storage/notetype/update_fields.sql @@ -1,2 +1,2 @@ -INSERT INTO FIELDS (ntid, ord, name, config) +INSERT INTO fields (ntid, ord, name, config) VALUES (?, ?, ?, ?); \ No newline at end of file diff --git a/rslib/src/storage/upgrades/schema11_downgrade.sql b/rslib/src/storage/upgrades/schema11_downgrade.sql index 03b73c5d5..8666e6d5f 100644 --- a/rslib/src/storage/upgrades/schema11_downgrade.sql +++ b/rslib/src/storage/upgrades/schema11_downgrade.sql @@ -1,7 +1,7 @@ DROP TABLE config; DROP TABLE deck_config; DROP TABLE tags; -DROP TABLE FIELDS; +DROP TABLE fields; DROP TABLE templates; DROP TABLE notetypes; DROP TABLE decks; diff --git a/rslib/src/storage/upgrades/schema15_upgrade.sql b/rslib/src/storage/upgrades/schema15_upgrade.sql index 4fa23c8c6..65465b295 100644 --- a/rslib/src/storage/upgrades/schema15_upgrade.sql +++ b/rslib/src/storage/upgrades/schema15_upgrade.sql @@ -1,11 +1,11 @@ -CREATE TABLE FIELDS ( +CREATE TABLE fields ( ntid integer NOT NULL, ord integer NOT NULL, name text NOT NULL COLLATE unicase, config blob NOT NULL, PRIMARY KEY (ntid, ord) ) without rowid; -CREATE UNIQUE INDEX idx_fields_name_ntid ON FIELDS (name, ntid); +CREATE UNIQUE INDEX idx_fields_name_ntid ON fields (name, ntid); CREATE TABLE templates ( ntid integer NOT NULL, ord integer NOT NULL, diff --git a/ts/sql_format.ts b/ts/sql_format.ts index 4e66d8c71..f89253d69 100644 --- a/ts/sql_format.ts +++ b/ts/sql_format.ts @@ -16,13 +16,18 @@ function fixFile(relpath: string, newText: string): void { } function formatText(text: string): string { - const newText: string = sqlFormatter.format(text, { + let newText: string = sqlFormatter.format(text, { indent: " ", reservedWordCase: "upper", }); - // 'type' is treated as a reserved word, but Anki uses it in various sql - // tables, so we don't want it uppercased - return newText.replace(/\bTYPE\b/g, "type"); + // downcase some keywords that Anki uses in tables/columns + for (const keyword of ["type", "fields"]) { + newText = newText.replace( + new RegExp(`\\b${keyword.toUpperCase()}\\b`, "g"), + keyword + ); + } + return newText; } let errorFound = false;