WebReflection / dblite

sqlite for node.js without gyp problems
MIT License
209 stars 34 forks source link

Undefined parameter in SQL string hangs dblite instance #47

Closed miellaby closed 7 years ago

miellaby commented 7 years ago

Everything is in the title.

I had to edit escape(what) function to manage undefined what.

case 'undefined':
    return 'null';

Without this patch, a missing parameter hangs the query queue because of

  throw new Error('unsupported data');
WebReflection commented 7 years ago

why do you send undefined in the first place? what's your use case?

miellaby commented 7 years ago

For example. The 'default' keyword of SQL consists in setting a default value for an INSERT when the user doesn't provide an input value, right? So, if a given value is undefined (that is missing) in a JS user-input object for such an INSERT statement, it would be nice if it works accordingly to the underlying principle, that is like a SQL 'null'.

Practically, managing undefined values in dbLite will allow us to write a very light REST API where we may directly give the request parameters object to dbLite. We consequently relay on SQL to check the request input and enforce type consistency. SQL does it for us, by refusing non-compatible or missing data values.

By the way, the "throw new Error()" breaks dbLite's resilience. It is not caught by the calling function, so the "SELECT secret_stuff" doesn't occur and the query queue gets definitely broken.

WebReflection commented 7 years ago

not sure you're still interested in this bug but I've pushed 0.8 to fix it.