AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.01k stars 651 forks source link

Using alasql with XLSX syntax errors #523

Open elincognito opened 8 years ago

elincognito commented 8 years ago

I have the following `alasql('SELECT name as Nome, max as Maximo INTO XLSX("email-types.xlsx",{headers:true}) FROM ?', [$scope.data.types]);``

its giving me the the syntax error

Error: Parse error on line 1:

...T name as Nome, max as Maximo INTO XLSX( -----------------------^ Expecting 'LPAR', got 'AS'

elincognito commented 8 years ago

Nevermind frozen brain in the morning, properly escaping max reserved keyword will do the trick :facepunch:

agershun commented 8 years ago

This is one of most frequent syntax problem of AlaSQL. Unfortunately, I do not know how to minimize it effect.

mathiasrw commented 8 years ago

I will try to place it early in readme

Cyberider commented 8 years ago

What about including a list of the reserved key words with the Parse Error msg. Or a link to the reserved words. At least that way a newbie, like me, can than realize that this could be the problem. Because a parse error really could be caused by two major problems: 1) an actual syntax error 2) use of a reserved word (which than causes a syntax error).

mathiasrw commented 8 years ago

@Cyberider I like your idea.

What if the error was structured like this:

Error: Have you used a reserved keyword without `escaping` it? Parse error on line 1:
...T name as Nome, max as Maximo INTO XLSX(
-----------------------^
Expecting 'LPAR', got 'AS'
Cyberider commented 8 years ago

Is this doable?

Error: Parse error on line 1:
...T name as Nome, max as Maximo INTO XLSX(
-----------------------^
Have you used a Reserved Keyword without escaping it with [square_brackets] or `back_quotes`?
Expecting 'LPAR', got 'AS'
mathiasrw commented 8 years ago

Ill look into it. Im looking into how we can intercept the error throwing winthout having too much of a a peformance hit

mathiasrw commented 8 years ago

My first try did not work.

I just found an example: https://gist.github.com/GerHobbelt/e18f2ef8ee575d4ff49d

leaving it here to use it as a template.