google / lovefield

Lovefield is a relational database for web apps. Written in JavaScript, works cross-browser. Provides SQL-like APIs that are fast, safe, and easy to use.
https://google.github.io/lovefield/
Apache License 2.0
6.81k stars 366 forks source link

WebSQL error when creating table with name "Group". #112

Closed freshp86 closed 9 years ago

freshp86 commented 9 years ago

Copied from https://github.com/google/lovefield/issues/111 and reported by codeBelt:

I get a [object SQLError] error if I create a table with the name 'Group'. Renaming it fixes the issues. Check it out:

Website: http://codebelt.github.io/lovefield/ Repo: https://github.com/codeBelt/lovefield

schemaBuilder.createTable('Group').
                    addColumn('id',                         lf.Type.INTEGER).
                    addColumn('qty',                        lf.Type.INTEGER).
                    addColumn('fk_productId',               lf.Type.INTEGER).
                    addPrimaryKey(['id'], true);

On Chrome this results to the following error, Uncaught #<SQLError>

freshp86 commented 9 years ago

Managed to extract some more information from this error, SQLError {}code: 5message: "could not prepare statement (1 near "Group": syntax error)"__proto__: SQLError

It seems that the problem lies at https://github.com/google/lovefield/blob/master/lib/backstore/web_sql.js#L273. I am guessing that "Group" is a reserved name in WebSQL which causes the syntax error.

freshp86 commented 9 years ago

This should be fixed by https://github.com/google/lovefield/commit/e1bc4a70f80140015757cc7b5afa045334809217. Please re-open if that is not the case.