mschwartz / SilkJS

V8 Based JavaScript Swiss Army Knife (and HTTP Server!)
https://github.com/decafjs/decaf
Other
323 stars 37 forks source link

JavaScript keywords cause exceptions #18

Closed moduscreate closed 12 years ago

moduscreate commented 12 years ago

Test case:

Config.documentRoot = 'docroot';
Config.numChildren = 1;

Config.mysql = {
    host   : 'localhost',
    user   : 'root',
    passwd : '',
    db     : 'testdb'
};

SQL = new MySQL();
SQL.connect();

//Include libraries
include('lib/Server.js');
include('lib/Schema.js');

Schema.add({
    name       : 'Test',
    primaryKey : 'id',
    fields : [
        {
            name          : 'id',
            type          : 'int',
            autoIncrement : true
        },
        {
            name : 'key' , // <-- this somehow causes the exception!
            type : 'varchar',
            size : 32
       }
    ]
});

Exception:

JMBP-2:silk jgarcia$ httpd-silk.js ./x.js
/usr/share/silkjs/modules/MySQL.js:282: <string conversion failed>
            throw new SQLException(e, sql);
                  ^
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(32),
    Primary Key(id)
) Engine=InnoDB' at line 3
    at [object Object].update (/usr/share/silkjs/modules/MySQL.js:282:19)
    at Object.create (/usr/share/silkjs/lib/Schema.js:569:8)
    at Object.add (/usr/share/silkjs/lib/Schema.js:211:12)
    at ./x.js:19:8
    at includeFile (builtin/include.js:55:6)
    at builtin/include.js:61:4
    at Object.<anonymous> (/usr/local/bin/httpd-silk.js:48:13)
    at Object.each (builtin/extensions.js:10:12)
    at main (/usr/local/bin/httpd-silk.js:46:15)
mschwartz commented 12 years ago

"key" is a MySQL reserved word.

See http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

On Mar 28, 2012, at 11:23 AM, Modus Create wrote:

Test case: Config.documentRoot = 'docroot'; Config.numChildren = 1;

Config.mysql = { host : 'localhost', user : 'root', passwd : '', db : 'testdb' };

SQL = new MySQL(); SQL.connect();

//Include libraries include('lib/Server.js'); include('lib/Schema.js');

Schema.add({ name : 'Test', primaryKey : 'id', fields : [ { name : 'id', type : 'int', autoIncrement : true }, { name : 'key' , // <-- this somehow causes the exception! type : 'varchar', size : 32 } ] });

Exception:

JMBP-2:silk jgarcia$ httpd-silk.js ./x.js /usr/share/silkjs/modules/MySQL.js:282: throw new SQLException(e, sql); ^ Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(32), Primary Key(id) ) Engine=InnoDB' at line 3 at [object Object].update (/usr/share/silkjs/modules/MySQL.js:282:19) at Object.create (/usr/share/silkjs/lib/Schema.js:569:8) at Object.add (/usr/share/silkjs/lib/Schema.js:211:12) at ./x.js:19:8 at includeFile (builtin/include.js:55:6) at builtin/include.js:61:4 at Object. (/usr/local/bin/httpd-silk.js:48:13) at Object.each (builtin/extensions.js:10:12) at main (/usr/local/bin/httpd-silk.js:46:15)


Reply to this email directly or view it on GitHub: https://github.com/mschwartz/SilkJS/issues/18

moduscreate commented 12 years ago

Yeah. I figured that a few minutes after I posted this. i'm an idiot.