Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit f1004bf2
authored
May 06, 2016
by
Lewis Sobotkiewicz
Committed by
Jan Aagaard Meier
May 06, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing MySQL error when inserting fractional datetimes on MySQL versions 5.7+ (#5855)
Closes #5387
1 parent
308bb8c3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
lib/dialects/mysql/data-types.js
test/unit/sql/insert.js
lib/dialects/mysql/data-types.js
View file @
f1004bf
...
@@ -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'
);
};
};
...
...
test/unit/sql/insert.js
View file @
f1004bf
...
@@ -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
()
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment