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

Commit f1004bf2 by Lewis Sobotkiewicz Committed by Jan Aagaard Meier

Fixing MySQL error when inserting fractional datetimes on MySQL versions 5.7+ (#5855)

Closes #5387
1 parent 308bb8c3
...@@ -31,12 +31,12 @@ module.exports = function (BaseTypes) { ...@@ -31,12 +31,12 @@ module.exports = function (BaseTypes) {
}; };
DATE.prototype.$stringify = function (date, options) { DATE.prototype.$stringify = function (date, options) {
date = BaseTypes.DATE.prototype.$applyTimezone(date, options);
// Fractional DATETIMEs only supported on MySQL 5.6.4+ // Fractional DATETIMEs only supported on MySQL 5.6.4+
if (this._length) { if (this._length) {
return BaseTypes.DATE.prototype.$stringify(date, options); return date.format('YYYY-MM-DD HH:mm:ss.SSS');
} }
date = BaseTypes.DATE.prototype.$applyTimezone(date, options);
return date.format('YYYY-MM-DD HH:mm:ss'); return date.format('YYYY-MM-DD HH:mm:ss');
}; };
......
...@@ -58,6 +58,28 @@ describe(Support.getTestDialectTeaser('SQL'), function() { ...@@ -58,6 +58,28 @@ describe(Support.getTestDialectTeaser('SQL'), function() {
mysql: "INSERT INTO `users` (`date`) VALUES ('2015-01-20 01:00:00');" mysql: "INSERT INTO `users` (`date`) VALUES ('2015-01-20 01:00:00');"
}); });
}); });
it('formats date correctly when sub-second precision is explicitly specified', function () {
var timezoneSequelize = Support.createSequelizeInstance({
timezone: Support.getTestDialect() === 'sqlite' ? '+00:00' : 'CET'
});
var User = timezoneSequelize.define('user', {
date: {
type: DataTypes.DATE(3)
}
},{
timestamps:false
});
expectsql(timezoneSequelize.dialect.QueryGenerator.insertQuery(User.tableName, {date: new Date(Date.UTC(2015, 0, 20, 1, 2, 3, 89))}, User.rawAttributes, {}),
{
postgres: 'INSERT INTO "users" ("date") VALUES (\'2015-01-20 02:02:03.089 +01:00\');',
sqlite: 'INSERT INTO `users` (`date`) VALUES (\'2015-01-20 01:02:03.089 +00:00\');',
mssql: 'INSERT INTO [users] ([date]) VALUES (N\'2015-01-20 02:02:03.089\');',
mysql: "INSERT INTO `users` (`date`) VALUES ('2015-01-20 02:02:03.089');"
});
});
}); });
describe('bulkCreate', function () { describe('bulkCreate', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!