From 2dcced1895a69f4d7cf1d130498fa4dbd68c75ef Mon Sep 17 00:00:00 2001 From: Alex Covizzi Date: Sat, 4 Jun 2022 15:40:26 +0200 Subject: [PATCH 1/6] #211 Fix trigger query parsing (#213) --- src/sqlite/queryParser.ts | 10 +++++++++- tests/unit/sqlite/queryParser.test.ts | 28 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/sqlite/queryParser.ts b/src/sqlite/queryParser.ts index ef054fb..16cd1b1 100644 --- a/src/sqlite/queryParser.ts +++ b/src/sqlite/queryParser.ts @@ -5,6 +5,7 @@ export function extractStatements(query: string): Statement[] { let statement: Statement|undefined; let isStmt = false; + let isInternalBlock = false; let isString = false; let isComment = false; let isCommand = false; @@ -18,6 +19,7 @@ export function extractStatements(query: string): Statement[] { let char = line[charIndex]; let prevChar = charIndex>0? line[charIndex-1] : undefined; let nextChar = charIndex line.substring(charIndex-n+1, charIndex+1) if (isStmt) { if (statement) statement.sql += char; @@ -28,7 +30,13 @@ export function extractStatements(query: string): Statement[] { } else if (!isString && char === '/' && nextChar === '*') { isComment = true; commentChar = '/'; - } else if (!isString && !isComment && char === ';') { + } else if (!isString && !isComment && lastWord(5).toLowerCase() === "begin") { + isInternalBlock = true; + } else if (!isString && !isComment && lastWord(3).toLowerCase() === "end") { + isInternalBlock = false; + } else if (!isString && !isComment && isInternalBlock && lastWord(11).toLowerCase() === "transaction") { + isInternalBlock = false; + } else if (!isString && !isComment && !isInternalBlock && char === ';') { isStmt = false; if (statement) { statement.position.end = [lineIndex, charIndex]; diff --git a/tests/unit/sqlite/queryParser.test.ts b/tests/unit/sqlite/queryParser.test.ts index ed212ba..0a4e763 100644 --- a/tests/unit/sqlite/queryParser.test.ts +++ b/tests/unit/sqlite/queryParser.test.ts @@ -110,5 +110,33 @@ describe("QueryParser Tests", function () { expect(actual.map(s => s.sql)).toEqual(expected); }); + test("should parse query with TRIGGER and SELECT (issue #210)", function() { + let query = `CREATE TRIGGER newWidgetSale BEFORE UPDATE ON widgetSale + BEGIN + SELECT RAISE(ROLLBACK, 'cannot update table "widget sale"') FROM widgetSale WHERE id = NEW.id and reconciled = 1; + END + ;` + + let actual = queryParser.extractStatements(query); + let expected = [query]; + + expect(actual.map(s => s.sql)).toEqual(expected); + }); + + test("should parse query with transaction", function() { + let query = `BEGIN TRANSACTION; -- start + SELECT RAISE(ROLLBACK, 'cannot update table "widget sale"') FROM widgetSale WHERE id = NEW.id and reconciled = 1; + END TRANSACTION;` + + let actual = queryParser.extractStatements(query); + let expected = [ + "BEGIN TRANSACTION;", + "SELECT RAISE(ROLLBACK, 'cannot update table \"widget sale\"') FROM widgetSale WHERE id = NEW.id and reconciled = 1;", + "END TRANSACTION;" + ]; + + expect(actual.map(s => s.sql)).toEqual(expected); + }); + }); \ No newline at end of file From b98d9cd0b687825cd25283d4a07425ca3167bfc8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:44:59 +0200 Subject: [PATCH 2/6] Bump minimist from 1.2.5 to 1.2.6 (#205) Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 62 +++-------------------------------------------- 1 file changed, 3 insertions(+), 59 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8499333..86cd59a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -509,14 +509,6 @@ "requires": { "exec-sh": "^0.3.2", "minimist": "^1.2.0" - }, - "dependencies": { - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - } } }, "@istanbuljs/load-nyc-config": { @@ -2666,13 +2658,6 @@ "requires": { "minimist": "^1.2.0", "through2": "^3.0.1" - }, - "dependencies": { - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" - } } }, "csv-stringify": { @@ -5932,14 +5917,6 @@ "dev": true, "requires": { "minimist": "^1.2.5" - }, - "dependencies": { - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - } } }, "kind-of": { @@ -6010,12 +5987,6 @@ "requires": { "minimist": "^1.2.0" } - }, - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true } } }, @@ -6247,10 +6218,9 @@ } }, "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" }, "minipass": { "version": "2.9.0", @@ -7263,14 +7233,6 @@ "ini": "~1.3.0", "minimist": "^1.2.0", "strip-json-comments": "~2.0.1" - }, - "dependencies": { - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - } } }, "react-is": { @@ -7613,12 +7575,6 @@ "to-regex": "^3.0.2" } }, - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, "normalize-path": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", @@ -8605,12 +8561,6 @@ "tsutils": "^2.29.0" }, "dependencies": { - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, "mkdirp": { "version": "0.5.5", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", @@ -9398,12 +9348,6 @@ "to-regex": "^3.0.2" } }, - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, "mkdirp": { "version": "0.5.5", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", From 501e26ea28f3710e56f1837878d846e122cc2c0f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:49:23 +0200 Subject: [PATCH 3/6] Bump minimist from 1.2.5 to 1.2.6 in /src/resultview/html (#203) Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- src/resultview/html/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/resultview/html/package-lock.json b/src/resultview/html/package-lock.json index 003dd7e..12c261b 100644 --- a/src/resultview/html/package-lock.json +++ b/src/resultview/html/package-lock.json @@ -2182,9 +2182,9 @@ } }, "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "dev": true }, "mississippi": { From 93f21b286d7725c008798cdc78892235e6df111b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 4 Jun 2022 16:44:08 +0200 Subject: [PATCH 4/6] Bump ansi-regex from 4.1.0 to 4.1.1 in /src/resultview/html (#214) Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- src/resultview/html/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/resultview/html/package-lock.json b/src/resultview/html/package-lock.json index 12c261b..c1aa451 100644 --- a/src/resultview/html/package-lock.json +++ b/src/resultview/html/package-lock.json @@ -293,9 +293,9 @@ "dev": true }, "ansi-regex": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", - "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", + "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", "dev": true }, "ansi-styles": { From 07805060c004e83b04bbe45752aae738eac25cda Mon Sep 17 00:00:00 2001 From: Alex Covizzi Date: Sat, 4 Jun 2022 17:46:29 +0200 Subject: [PATCH 5/6] Update version to 0.14.1, update changelog --- CHANGELOG.md | 6 ++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19e9684..e749fff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 0.14.1 (04 Jun 2022) + +Fixed + +1. Fixed bug in the SQL parser that caused queries with `CREATE TRIGGER` to be parsed incorrectely ([#211](https://github.com/AlexCovizzi/vscode-sqlite/issues/211)) + ## 0.14.0 (06 Nov 2021) Added diff --git a/package-lock.json b/package-lock.json index 86cd59a..828eebc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vscode-sqlite", - "version": "0.14.0", + "version": "0.14.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 08bc031..6b2c5c8 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "icon": "resources/icon/icon_128x128.png", "displayName": "SQLite", "description": "Explore and query SQLite databases.", - "version": "0.14.0", + "version": "0.14.1", "publisher": "alexcvzz", "repository": { "url": "https://github.com/AlexCovizzi/vscode-sqlite", From c09e34880e5cb34cf7960bca908e56a52e67207d Mon Sep 17 00:00:00 2001 From: Alex Covizzi Date: Sun, 5 Jun 2022 12:37:40 +0200 Subject: [PATCH 6/6] Fix issue reference on 0.14.1 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e749fff..2a8c8d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Fixed -1. Fixed bug in the SQL parser that caused queries with `CREATE TRIGGER` to be parsed incorrectely ([#211](https://github.com/AlexCovizzi/vscode-sqlite/issues/211)) +1. Fixed bug in the SQL parser that caused queries with `CREATE TRIGGER` to be parsed incorrectely ([#210](https://github.com/AlexCovizzi/vscode-sqlite/issues/210)) ## 0.14.0 (06 Nov 2021)