Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AlexCovizzi/vscode-sqlite
Browse files Browse the repository at this point in the history
…into master
  • Loading branch information
AlexCovizzi committed Jan 20, 2024
2 parents 12fcc12 + c09e348 commit 24b0ba3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 68 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
64 changes: 4 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/resultview/html/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/sqlite/queryParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.length-1? line[charIndex+1] : undefined;
let lastWord = (n: number) => line.substring(charIndex-n+1, charIndex+1)

if (isStmt) {
if (statement) statement.sql += char;
Expand All @@ -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];
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/sqlite/queryParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});


});

0 comments on commit 24b0ba3

Please sign in to comment.