Skip to content
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

Bugfix: define plugin.error and reject any unknow type parameter in addStatement #450

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/sqlite.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ let nextTick = setImmediate || function(fun) {
if (global.window) {
nextTick = window.setImmediate || function(fun) {
window.setTimeout(fun, 0);
};
};
}

/*
Expand Down Expand Up @@ -94,6 +94,12 @@ plugin.log = function(...messages) {
}
}

plugin.error = function(...message) {
if (plugin.sqlitePlugin.DEBUG) {
console.error(...message);
}
}

SQLitePlugin = function(openargs, openSuccess, openError) {
var dbname;
if (!(openargs && openargs['name'])) {
Expand Down Expand Up @@ -501,10 +507,6 @@ SQLitePluginTransaction.prototype.addStatement = function(sql, values, success,
} else if (t === 'boolean') {
//Convert true -> 1 / false -> 0
params.push(~~v);
}
Copy link
Owner

@andpor andpor Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@halaei why did you remove this conditional block? wouldn't it suffice to implement warn function instead...it appears that warn function is the one that is missing...

Also, the missing plugin method was warn rather than error ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andpor Maybe I was thinking of backward compatibility or to keep the behavior as strict as possible to minimize possible errors. I don't see any value to silently save {x: {}} as "[object Object]". It just makes things more complicated in handling errors. I don't know what will happen when we save symbols or any other types.
Maybe both error and warn was missing, but warn wasn't used anywhere except the code that I removed.
I did this PR a while ago and don't remember all the details. I guess you have already fixed the issue in some other way.

else if (t !== 'function') {
params.push(v.toString());
plugin.warn('addStatement - parameter of type <'+t+'> converted to string using toString()')
} else {
let errorMsg = 'Unsupported parameter type <'+t+'> found in addStatement()';
plugin.error(errorMsg);
Expand Down Expand Up @@ -598,7 +600,7 @@ SQLitePluginTransaction.prototype.run = function() {
}
};
};

i = 0;
callbacks = [];
while (i < batchExecutes.length) {
Expand Down