Menu

#265 Helpers._sqlFormat should be improved regarding detecting whether a val === 'number'

open
nobody
None
5
2012-09-27
2012-09-27
Jira Trac
No

Currently in *Helpers._sqlFormat()* it has the following code:

{code}
...
if (typeof val === 'number') {
return val + '';
}

return ' + _escapeString(val) + ';
{code}

It's not very correct to determine whether a value is a number of not this way. The array contain all string values after user JSON.parse() the data received from a Browser request.

So, numbers will also have typeof === 'string'. The correct way is to call the following function:

{code}
function isNumber(n) {
return !isNaN(parseFloat(n)) isFinite(n);
}
{code}

This is not that big of a problem, since 8.4.1 and later have automatic type CASTing for integer. But it's not recommended to rely on that.

Discussion

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.