不要怂,就是干,撸起袖子干!

Commit 39dfbe3b by Eugene Korbut

sqlite: fix BOOLEAN type bug

1 parent 1513d4b4
Showing with 6 additions and 10 deletions
...@@ -3,11 +3,13 @@ var Utils = require("../../utils") ...@@ -3,11 +3,13 @@ var Utils = require("../../utils")
var escape = function(str) { var escape = function(str) {
if (typeof str === 'string') { if (typeof str === 'string') {
return "'" + str.replace(/'/g, "''") + "'" return "'" + str.replace(/'/g, "''") + "'";
} else if(str === null || str === undefined) { } else if (typeof str === 'boolean') {
return 'NULL' return str ? 1 : 0; // SQLite has no type boolean
} else if (str === null || str === undefined) {
return 'NULL';
} else { } else {
return str return str;
} }
}; };
...@@ -46,12 +48,6 @@ module.exports = (function() { ...@@ -46,12 +48,6 @@ module.exports = (function() {
table: Utils.addTicks(tableName), table: Utils.addTicks(tableName),
attributes: Utils._.keys(attrValueHash).map(function(attr){return Utils.addTicks(attr)}).join(","), attributes: Utils._.keys(attrValueHash).map(function(attr){return Utils.addTicks(attr)}).join(","),
values: Utils._.values(attrValueHash).map(function(value){ values: Utils._.values(attrValueHash).map(function(value){
//SQLite has no type boolean :
if (typeof value === "boolean") {
value = value ? 1 : 0;
}
return escape((value instanceof Date) ? Utils.toSqlDate(value) : value) return escape((value instanceof Date) ? Utils.toSqlDate(value) : value)
}).join(",") }).join(",")
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!