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

Commit 0514149f by Jan Aagaard Meier

Merge pull request #5045 from sushantdhiman/fix-4953

MySQL Geometry throw unhandled exception when buffer is null
2 parents 433e25f6 4fcdf7eb
# Future
- [FIXED] MySQL throws error when null GEOMETRY data results in empty buffer [#4953](https://github.com/sequelize/sequelize/issues/4953)
# 3.16.0 # 3.16.0
- [ADDED] PostgreSQL tsrange (Range of timestamp without time zone) data type support. - [ADDED] PostgreSQL tsrange (Range of timestamp without time zone) data type support.
- [ADDED] hasOne scope support [#5113](https://github.com/sequelize/sequelize/pull/5113) - [ADDED] hasOne scope support [#5113](https://github.com/sequelize/sequelize/pull/5113)
- [FIXED] attributes from multiple scopes does not merge [#4856](https://github.com/sequelize/sequelize/issues/4856) - [FIXED] attributes from multiple scopes does not merge [#4856](https://github.com/sequelize/sequelize/issues/4856)
- [FIXED] Support Unicode strings in mssql [#3752](https://github.com/sequelize/sequelize/issues/3752) - [FIXED] Support Unicode strings in mssql [#3752](https://github.com/sequelize/sequelize/issues/3752)
- [FIXED] Do not inject include twice in `options.include` [#5106](https://github.com/sequelize/sequelize/pull/5106) - [FIXED] Do not inject include twice in `options.include` [#5106](https://github.com/sequelize/sequelize/pull/5106)
- [FIXED] Expand and validate include in `aggregate` [#5106](https://github.com/sequelize/sequelize/pull/5106) - [FIXED] Expand and validate include in `aggregate`
# 3.15.1 # 3.15.1
- [FIXED] calling Model.update() modifies passed values [#4520](https://github.com/sequelize/sequelize/issues/4520) - [FIXED] calling Model.update() modifies passed values [#4520](https://github.com/sequelize/sequelize/issues/4520)
......
...@@ -398,13 +398,13 @@ AbstractQuery.formatBindParameters = function(sql, values, dialect, replacementF ...@@ -398,13 +398,13 @@ AbstractQuery.formatBindParameters = function(sql, values, dialect, replacementF
if (!values) { if (!values) {
return [sql, []]; return [sql, []];
} }
options = options || {}; options = options || {};
if (typeof replacementFunc !== 'function') { if (typeof replacementFunc !== 'function') {
options = replacementFunc || {}; options = replacementFunc || {};
replacementFunc = undefined; replacementFunc = undefined;
} }
if (!replacementFunc) { if (!replacementFunc) {
if (options.skipValueReplace) { if (options.skipValueReplace) {
replacementFunc = function(match, key, values, timeZone, dialect, options) { replacementFunc = function(match, key, values, timeZone, dialect, options) {
...@@ -432,15 +432,15 @@ AbstractQuery.formatBindParameters = function(sql, values, dialect, replacementF ...@@ -432,15 +432,15 @@ AbstractQuery.formatBindParameters = function(sql, values, dialect, replacementF
}; };
} }
} }
var timeZone = null; var timeZone = null;
var list = Array.isArray(values); var list = Array.isArray(values);
sql = sql.replace(/\$(\$|\w+)/g, function(match, key) { sql = sql.replace(/\$(\$|\w+)/g, function(match, key) {
if ('$' === key) { if ('$' === key) {
return options.skipUnescape ? match : key; return options.skipUnescape ? match : key;
} }
var replVal; var replVal;
if (list) { if (list) {
if (key.match(/^[1-9]\d*$/)) { if (key.match(/^[1-9]\d*$/)) {
......
...@@ -60,8 +60,15 @@ module.exports = function (BaseTypes) { ...@@ -60,8 +60,15 @@ module.exports = function (BaseTypes) {
}); });
GEOMETRY.parse = GEOMETRY.prototype.parse = function(value) { GEOMETRY.parse = GEOMETRY.prototype.parse = function(value) {
value = value.buffer();
//MySQL doesn't support POINT EMPTY, https://dev.mysql.com/worklog/task/?id=2381
if (value === null) {
return null;
}
// For some reason, discard the first 4 bytes // For some reason, discard the first 4 bytes
value = value.buffer().slice(4); value = value.slice(4);
return wkx.Geometry.parse(value).toGeoJSON(); return wkx.Geometry.parse(value).toGeoJSON();
}; };
......
...@@ -273,4 +273,35 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() { ...@@ -273,4 +273,35 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
// No dialects actually allow us to identify that we get an enum back.. // No dialects actually allow us to identify that we get an enum back..
testFailure(Type); testFailure(Type);
}); });
it('should parse an empty GEOMETRY field', function () {
var Type = new Sequelize.GEOMETRY();
if (current.dialect.supports.GEOMETRY) {
current.refreshTypes();
var User = current.define('user', { field: Type }, { timestamps: false });
var point = { type: "Point", coordinates: [] };
return current.sync({ force: true }).then(function () {
return User.create({
//insert a null GEOMETRY type
field: point
});
}).then(function () {
//This case throw unhandled exception
return User.findAll();
}).then(function(users){
if (Support.dialectIsMySQL()) {
// MySQL will return NULL, becuase they lack EMPTY geometry data support.
expect(users[0].field).to.be.eql(null);
} else if (dialect === 'postgres' || dialect === 'postgres-native') {
//Empty Geometry data [0,0] as per https://trac.osgeo.org/postgis/ticket/1996
expect(users[0].field).to.be.deep.eql({ type: "Point", coordinates: [0,0] });
} else {
expect(users[0].field).to.be.deep.eql(point);
}
});
}
});
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!