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 6c9b993c
authored
Jan 18, 2019
by
zhangshichun
Committed by
Sushant
Jan 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(mariadb): unique constraint error message parsing (#10362)
1 parent
178b495a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
3 deletions
lib/dialects/mariadb/query.js
test/unit/dialects/mariadb/errors.test.js
lib/dialects/mariadb/query.js
View file @
6c9b993
...
@@ -261,7 +261,7 @@ class Query extends AbstractQuery {
...
@@ -261,7 +261,7 @@ class Query extends AbstractQuery {
switch
(
err
.
errno
)
{
switch
(
err
.
errno
)
{
case
ER_DUP_ENTRY
:
{
case
ER_DUP_ENTRY
:
{
const
match
=
err
.
message
.
match
(
const
match
=
err
.
message
.
match
(
/Duplicate entry '
([\s\S]
*
)
' for key '
?((
.|
\s)
*
?)
'
?
[\s
.*
]?
$/
);
/Duplicate entry '
([\s\S]
*
)
' for key '
?((
.|
\s)
*
?)
'
?
\s
.*
$/
);
let
fields
=
{};
let
fields
=
{};
let
message
=
'Validation error'
;
let
message
=
'Validation error'
;
...
...
test/unit/dialects/mariadb/errors.test.js
View file @
6c9b993
...
@@ -42,7 +42,7 @@ if (dialect === 'mariadb') {
...
@@ -42,7 +42,7 @@ if (dialect === 'mariadb') {
});
});
it
(
'newlines contained in err message are parsed correctly'
,
()
=>
{
it
(
'newlines contained in err message are parsed correctly'
,
()
=>
{
const
fakeErr
=
new
Error
(
"Duplicate entry 'test\r' for key 'num'"
);
const
fakeErr
=
new
Error
(
'(conn=43, no: 1062, SQLState: 23000) Duplicate entry \'unique name one\r\' for key \'models_uniqueName2_unique\'\nsql: INSERT INTO `models` (`id`,`uniqueName1`,`uniqueName2`,`createdAt`,`updatedAt`) VALUES (DEFAULT,?,?,?,?); - parameters:[\'this is ok\',\'unique name one\',\'2019-01-18 09:05:28.496\',\'2019-01-18 09:05:28.496\']'
);
fakeErr
.
errno
=
1062
;
fakeErr
.
errno
=
1062
;
...
@@ -50,7 +50,7 @@ if (dialect === 'mariadb') {
...
@@ -50,7 +50,7 @@ if (dialect === 'mariadb') {
expect
(
parsedErr
).
to
.
be
.
instanceOf
(
Sequelize
.
UniqueConstraintError
);
expect
(
parsedErr
).
to
.
be
.
instanceOf
(
Sequelize
.
UniqueConstraintError
);
expect
(
parsedErr
.
parent
).
to
.
equal
(
fakeErr
);
expect
(
parsedErr
.
parent
).
to
.
equal
(
fakeErr
);
expect
(
parsedErr
.
fields
.
num
).
to
.
equal
(
'test
\r'
);
expect
(
parsedErr
.
fields
.
models_uniqueName2_unique
).
to
.
equal
(
'unique name one
\r'
);
});
});
});
});
}
}
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