-
Notifications
You must be signed in to change notification settings - Fork 523
Turn javascript arrays into SQL lists #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -489,7 +489,7 @@ SQLitePluginTransaction.prototype.executeSql = function(sql, values, success, er | |
}; | ||
|
||
SQLitePluginTransaction.prototype.addStatement = function(sql, values, success, error) { | ||
var j, len1, params, sqlStatement, t, v; | ||
var j, len1, len2, params, sqlStatement, t, v, i, s; | ||
sqlStatement = typeof sql === 'string' ? sql : sql.toString(); | ||
params = []; | ||
if (!!values && values.constructor === Array) { | ||
|
@@ -501,6 +501,16 @@ SQLitePluginTransaction.prototype.addStatement = function(sql, values, success, | |
} else if (t === 'boolean') { | ||
//Convert true -> 1 / false -> 0 | ||
params.push(~~v); | ||
} else if (Array.isArray(v)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps you can used values.constructor === Array for consistency since it is already used on line 495 ? |
||
s = '('; | ||
for (i = 0, len2 = v.length; len2 > 1 && i < len2 - 1; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This loop is overly complicated for a simple thing it is trying to do. I would suggest to use the following standard loop format
|
||
s = s + v[i].toString() + ','; | ||
} | ||
if (len2 > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is no longer necessary if the suggested loop is used. |
||
s = s + v[len2 - 1]; | ||
} | ||
s = s + ')'; | ||
params.push(s); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so a couple of things.
|
||
} | ||
else if (t !== 'function') { | ||
params.push(v.toString()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
len2 is not necessary if a simpler loop is used