From efd111ec2f27694332da5e65a43a613115f16b86 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Fri, 26 Aug 2022 16:04:34 -0400 Subject: [PATCH 1/2] Fix identifying queries with lowercase block openers --- src/parser.ts | 2 +- test/identifier/single-statement.spec.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/parser.ts b/src/parser.ts index db5acfc..552cc3b 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -673,7 +673,7 @@ function stateMachineStatementParser( if ( token.type === 'keyword' && - blockOpeners[dialect].includes(token.value) && + blockOpeners[dialect].includes(token.value.toUpperCase()) && prevNonWhitespaceToken?.value.toUpperCase() !== 'END' && (token.value.toUpperCase() !== 'BEGIN' || (token.value.toUpperCase() === 'BEGIN' && diff --git a/test/identifier/single-statement.spec.ts b/test/identifier/single-statement.spec.ts index 65b28fa..18c110b 100644 --- a/test/identifier/single-statement.spec.ts +++ b/test/identifier/single-statement.spec.ts @@ -1380,5 +1380,29 @@ describe('identifier', () => { expect(actual).to.eql(expected); }); + + it('Should parse lower case block opener in query correctly', () => { + const sql = `CREATE OR REPLACE PROCEDURE foo.bar (col string) + BEGIN + if foo is not null then + SET foo = 'bar'; + end if; + + SELECT 1; + END;`; + const actual = identify(sql, { dialect: 'bigquery', strict: false }); + const expected = [ + { + start: 0, + end: 170, + text: sql, + type: 'CREATE_PROCEDURE', + executionType: 'MODIFICATION', + parameters: [], + }, + ]; + + expect(actual).to.eql(expected); + }); }); }); From 8769fc480a28109585ca26edd242c052e6f3b12b Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 29 Aug 2022 11:33:05 -0400 Subject: [PATCH 2/2] Update single-statement.spec.ts --- test/identifier/single-statement.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/identifier/single-statement.spec.ts b/test/identifier/single-statement.spec.ts index aa7822f..b652937 100644 --- a/test/identifier/single-statement.spec.ts +++ b/test/identifier/single-statement.spec.ts @@ -1398,7 +1398,7 @@ describe('identifier', () => { text: sql, type: 'CREATE_PROCEDURE', executionType: 'MODIFICATION', - parameters: [], + parameters: [], }, ];