Skip to content

Commit

Permalink
Merge pull request #2068 from taozhi8833998/fix-key-reserved-sqlite
Browse files Browse the repository at this point in the history
fix: key reserved word in sqlite
  • Loading branch information
taozhi8833998 authored Aug 18, 2024
2 parents 64245e3 + cf8b110 commit 571b652
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pegjs/sqlite.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'JOIN': true,
// 'JSON': true,

'KEY': true,
// 'KEY': true,

'LEFT': true,
'LIKE': true,
Expand Down
4 changes: 3 additions & 1 deletion test/sqlite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,13 @@ describe('sqlite', () => {
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM "a" UNION DISTINCT SELECT * FROM "b"')
})

it('should support keyword as column name in create table sql', () => {
it('should support keyword as column name in sql', () => {
let sql = 'CREATE TABLE IF NOT EXISTS "Test" (Id INTEGER NOT NULL PRIMARY KEY UNIQUE, like TEXT NOT NULL, Difficulty TEXT, percent real, PRIMARY KEY(Id));'
expect(getParsedSql(sql)).to.be.equal('CREATE TABLE IF NOT EXISTS "Test" ("Id" INTEGER NOT NULL PRIMARY KEY UNIQUE, "like" TEXT NOT NULL, "Difficulty" TEXT, "percent" REAL, PRIMARY KEY ("Id"))')
sql = "SELECT * from tb WHERE NOT EXISTS (SELECT * FROM tb WHERE field1 = 'c' AND field2 = d)"
expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "tb" WHERE NOT EXISTS (SELECT * FROM "tb" WHERE "field1" = 'c' AND "field2" = "d")`)
sql = 'SELECT * FROM tb WHERE key="foo"'
expect(getParsedSql(sql)).to.be.equal('SELECT * FROM "tb" WHERE "key" = "foo"')
})

it('should support sqlify autoincrement to other db', () => {
Expand Down

0 comments on commit 571b652

Please sign in to comment.