taozhi8833998 / node-sql-parser

Parse simple SQL statements into an abstract syntax tree (AST) with the visited tableList and convert it back to SQL
https://taozhi8833998.github.io/node-sql-parser/
Apache License 2.0
780 stars 174 forks source link

Error if trying to parse 'SELECT * FROM table' #1863

Closed ob-julian closed 4 months ago

ob-julian commented 4 months ago

Describe the bug I get a terminal error consisting of line 1 of the code from \node_modules\node-sql-parser\index.js:1 so all of it and this appended:


s [SyntaxError]: Expected [A-Za-z0-9_$\x80-￿] but end of input found.
    at fi (D:\AAA_Uni\datenmanagement_ps\Aufgabe 1\node_modules\node-sql-parser\index.js:1:641021)
    at Object.parse [as mysql] (D:\AAA_Uni\datenmanagement_ps\Aufgabe 1\node_modules\node-sql-parser\index.js:1:823651)
    at r.value (D:\AAA_Uni\datenmanagement_ps\Aufgabe 1\node_modules\node-sql-parser\index.js:1:2330322)
    at r.value (D:\AAA_Uni\datenmanagement_ps\Aufgabe 1\node_modules\node-sql-parser\index.js:1:2329876)
    at Object.<anonymous> (D:\AAA_Uni\datenmanagement_ps\Aufgabe 1\src\test.js:4:20)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12) {
  expected: [
    {
      type: 'class',
      parts: [
        [ 'A', 'Z' ],
        [ 'a', 'z' ],
        [ '0', '9' ],
        '_',
        '$',
        [ '\x80', '￿' ]
      ],
      inverted: false,
      ignoreCase: false
    }
  ],
  found: null,
  location: {
    start: { offset: 19, line: 1, column: 20 },
    end: { offset: 19, line: 1, column: 20 }
  }
}

Node.js v21.7.2

To Reproduce Just this code:

const { Parser } = require('node-sql-parser');
const parser = new Parser();
const ast = parser.astify('SELECT * FROM table');

Expected behavior I expect it to parse 'table' as a name for the table I want to get the data from.

taozhi8833998 commented 4 months ago

table is a reserved word, you should wrap it or change another table name

taozhi8833998 commented 4 months ago
select * from `table`