diff --git a/CHANGELOG.md b/CHANGELOG.md index 19e9684..2a8c8d7 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 ([#210](https://github.com/AlexCovizzi/vscode-sqlite/issues/210)) + ## 0.14.0 (06 Nov 2021) Added diff --git a/package-lock.json b/package-lock.json index 8499333..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": { @@ -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", 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", diff --git a/src/resultview/html/package-lock.json b/src/resultview/html/package-lock.json index 003dd7e..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": { @@ -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": { 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