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

Commit 750817c5 by Daniel Durante

Merge branch 'master' of git://github.com/wyplay/sequelize into wyplay-master

2 parents c78b7396 773b2b6c
# v1.7.0 # # v1.7.0 #
- [BUG] Fix string escape with postgresql on raw SQL queries/ [#586](https://github.com/sequelize/sequelize/pull/586). thanks to zanamixx
- [BUG] "order by" is now after "group by". [#585](https://github.com/sequelize/sequelize/pull/585). thanks to mekanics - [BUG] "order by" is now after "group by". [#585](https://github.com/sequelize/sequelize/pull/585). thanks to mekanics
- [BUG] Added decimal support for min/max. [#583](https://github.com/sequelize/sequelize/pull/583). thanks to durango - [BUG] Added decimal support for min/max. [#583](https://github.com/sequelize/sequelize/pull/583). thanks to durango
- [FEATURE] Schematics. [#564](https://github.com/sequelize/sequelize/pull/564). thanks to durango - [FEATURE] Schematics. [#564](https://github.com/sequelize/sequelize/pull/564). thanks to durango
......
...@@ -202,7 +202,7 @@ module.exports = (function() { ...@@ -202,7 +202,7 @@ module.exports = (function() {
Sequelize.prototype.query = function(sql, callee, options, replacements) { Sequelize.prototype.query = function(sql, callee, options, replacements) {
if (arguments.length === 4) { if (arguments.length === 4) {
sql = Utils.format([sql].concat(replacements)) sql = Utils.format([sql].concat(replacements), this.options.dialect)
} else if (arguments.length === 3) { } else if (arguments.length === 3) {
options = options options = options
} else if (arguments.length === 2) { } else if (arguments.length === 2) {
......
...@@ -7,7 +7,7 @@ SqlString.escapeId = function (val, forbidQualified) { ...@@ -7,7 +7,7 @@ SqlString.escapeId = function (val, forbidQualified) {
return '`' + val.replace(/`/g, '``').replace(/\./g, '`.`') + '`'; return '`' + val.replace(/`/g, '``').replace(/\./g, '`.`') + '`';
}; };
SqlString.escape = function(val, stringifyObjects, timeZone) { SqlString.escape = function(val, stringifyObjects, timeZone, dialect) {
if (val === undefined || val === null) { if (val === undefined || val === null) {
return 'NULL'; return 'NULL';
} }
...@@ -37,17 +37,22 @@ SqlString.escape = function(val, stringifyObjects, timeZone) { ...@@ -37,17 +37,22 @@ SqlString.escape = function(val, stringifyObjects, timeZone) {
} }
} }
val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function(s) { if (dialect == "postgres") {
switch(s) { // http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS
case "\0": return "\\0"; val = val.replace(/'/g, "''");
case "\n": return "\\n"; } else {
case "\r": return "\\r"; val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function(s) {
case "\b": return "\\b"; switch(s) {
case "\t": return "\\t"; case "\0": return "\\0";
case "\x1a": return "\\Z"; case "\n": return "\\n";
default: return "\\"+s; case "\r": return "\\r";
} case "\b": return "\\b";
}); case "\t": return "\\t";
case "\x1a": return "\\Z";
default: return "\\"+s;
}
});
}
return "'"+val+"'"; return "'"+val+"'";
}; };
...@@ -58,7 +63,7 @@ SqlString.arrayToList = function(array, timeZone) { ...@@ -58,7 +63,7 @@ SqlString.arrayToList = function(array, timeZone) {
}).join(', '); }).join(', ');
}; };
SqlString.format = function(sql, values, timeZone) { SqlString.format = function(sql, values, timeZone, dialect) {
values = [].concat(values); values = [].concat(values);
return sql.replace(/\?/g, function(match) { return sql.replace(/\?/g, function(match) {
...@@ -66,7 +71,7 @@ SqlString.format = function(sql, values, timeZone) { ...@@ -66,7 +71,7 @@ SqlString.format = function(sql, values, timeZone) {
return match; return match;
} }
return SqlString.escape(values.shift(), false, timeZone); return SqlString.escape(values.shift(), false, timeZone, dialect);
}); });
}; };
......
...@@ -47,8 +47,9 @@ var Utils = module.exports = { ...@@ -47,8 +47,9 @@ var Utils = module.exports = {
escape: function(s) { escape: function(s) {
return SqlString.escape(s, true, "local").replace(/\\"/g, '"') return SqlString.escape(s, true, "local").replace(/\\"/g, '"')
}, },
format: function(arr) { format: function(arr, dialect) {
return SqlString.format(arr.shift(), arr) var timeZone = null;
return SqlString.format(arr.shift(), arr, timeZone, dialect)
}, },
isHash: function(obj) { isHash: function(obj) {
return Utils._.isObject(obj) && !Array.isArray(obj); return Utils._.isObject(obj) && !Array.isArray(obj);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!