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 daeb0f7b
authored
May 17, 2020
by
Sushant
Committed by
GitHub
May 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(mssql): dont use OUTPUT INSERTED.* for update without returning (#12260)
1 parent
18dcc7ee
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
9 deletions
lib/dialects/abstract/query-generator.js
lib/dialects/abstract/query-interface.js
lib/dialects/mssql/query.js
lib/instance-validator.js
lib/model.js
test/unit/sql/update.test.js
lib/dialects/abstract/query-generator.js
View file @
daeb0f7
...
@@ -362,7 +362,7 @@ class QueryGenerator {
...
@@ -362,7 +362,7 @@ class QueryGenerator {
}
}
}
}
if
(
this
.
_dialect
.
supports
.
returnValues
&&
(
this
.
_dialect
.
supports
.
returnValues
.
output
||
options
.
returning
)
)
{
if
(
this
.
_dialect
.
supports
.
returnValues
&&
options
.
returning
)
{
const
returnValues
=
this
.
generateReturnValues
(
attributes
,
options
);
const
returnValues
=
this
.
generateReturnValues
(
attributes
,
options
);
suffix
+=
returnValues
.
returningFragment
;
suffix
+=
returnValues
.
returningFragment
;
...
...
lib/dialects/abstract/query-interface.js
View file @
daeb0f7
...
@@ -847,7 +847,7 @@ class QueryInterface {
...
@@ -847,7 +847,7 @@ class QueryInterface {
async
update
(
instance
,
tableName
,
values
,
identifier
,
options
)
{
async
update
(
instance
,
tableName
,
values
,
identifier
,
options
)
{
options
=
{
...
options
};
options
=
{
...
options
};
options
.
hasTrigger
=
!!
(
instance
&&
instance
.
_modelOptions
&&
instance
.
_modelOptions
.
hasTrigger
)
;
options
.
hasTrigger
=
instance
&&
instance
.
constructor
.
options
.
hasTrigger
;
const
sql
=
this
.
queryGenerator
.
updateQuery
(
tableName
,
values
,
identifier
,
options
,
instance
.
constructor
.
rawAttributes
);
const
sql
=
this
.
queryGenerator
.
updateQuery
(
tableName
,
values
,
identifier
,
options
,
instance
.
constructor
.
rawAttributes
);
...
...
lib/dialects/mssql/query.js
View file @
daeb0f7
...
@@ -211,7 +211,7 @@ class Query extends AbstractQuery {
...
@@ -211,7 +211,7 @@ class Query extends AbstractQuery {
return
data
[
0
];
return
data
[
0
];
}
}
if
(
this
.
isBulkUpdateQuery
())
{
if
(
this
.
isBulkUpdateQuery
())
{
return
data
.
length
;
return
rowCount
;
}
}
if
(
this
.
isBulkDeleteQuery
())
{
if
(
this
.
isBulkDeleteQuery
())
{
return
data
[
0
]
&&
data
[
0
].
AFFECTEDROWS
;
return
data
[
0
]
&&
data
[
0
].
AFFECTEDROWS
;
...
...
lib/instance-validator.js
View file @
daeb0f7
...
@@ -160,7 +160,7 @@ class InstanceValidator {
...
@@ -160,7 +160,7 @@ class InstanceValidator {
*/
*/
async
_customValidators
()
{
async
_customValidators
()
{
const
validators
=
[];
const
validators
=
[];
_
.
each
(
this
.
modelInstance
.
_modelO
ptions
.
validate
,
(
validator
,
validatorType
)
=>
{
_
.
each
(
this
.
modelInstance
.
constructor
.
o
ptions
.
validate
,
(
validator
,
validatorType
)
=>
{
if
(
this
.
options
.
skip
.
includes
(
validatorType
))
{
if
(
this
.
options
.
skip
.
includes
(
validatorType
))
{
return
;
return
;
}
}
...
...
lib/model.js
View file @
daeb0f7
...
@@ -105,7 +105,6 @@ class Model {
...
@@ -105,7 +105,6 @@ class Model {
this
.
dataValues
=
{};
this
.
dataValues
=
{};
this
.
_previousDataValues
=
{};
this
.
_previousDataValues
=
{};
this
.
_changed
=
new
Set
();
this
.
_changed
=
new
Set
();
this
.
_modelOptions
=
this
.
constructor
.
options
;
this
.
_options
=
options
||
{};
this
.
_options
=
options
||
{};
/**
/**
...
@@ -3394,7 +3393,7 @@ class Model {
...
@@ -3394,7 +3393,7 @@ class Model {
},
{});
},
{});
if
(
_
.
size
(
where
)
===
0
)
{
if
(
_
.
size
(
where
)
===
0
)
{
return
this
.
_modelO
ptions
.
whereCollection
;
return
this
.
constructor
.
o
ptions
.
whereCollection
;
}
}
const
versionAttr
=
this
.
constructor
.
_versionAttribute
;
const
versionAttr
=
this
.
constructor
.
_versionAttribute
;
if
(
checkVersion
&&
versionAttr
)
{
if
(
checkVersion
&&
versionAttr
)
{
...
...
test/unit/sql/update.test.js
View file @
daeb0f7
...
@@ -10,6 +10,30 @@ const Support = require('../support'),
...
@@ -10,6 +10,30 @@ const Support = require('../support'),
describe
(
Support
.
getTestDialectTeaser
(
'SQL'
),
()
=>
{
describe
(
Support
.
getTestDialectTeaser
(
'SQL'
),
()
=>
{
describe
(
'update'
,
()
=>
{
describe
(
'update'
,
()
=>
{
it
(
'supports returning false'
,
()
=>
{
const
User
=
Support
.
sequelize
.
define
(
'user'
,
{
username
:
{
type
:
DataTypes
.
STRING
,
field
:
'user_name'
}
},
{
timestamps
:
false
});
const
options
=
{
returning
:
false
};
expectsql
(
sql
.
updateQuery
(
User
.
tableName
,
{
user_name
:
'triggertest'
},
{
id
:
2
},
options
,
User
.
rawAttributes
),
{
query
:
{
default
:
'UPDATE [users] SET [user_name]=$1 WHERE [id] = $2'
},
bind
:
{
default
:
[
'triggertest'
,
2
]
}
});
});
it
(
'with temp table for trigger'
,
()
=>
{
it
(
'with temp table for trigger'
,
()
=>
{
const
User
=
Support
.
sequelize
.
define
(
'user'
,
{
const
User
=
Support
.
sequelize
.
define
(
'user'
,
{
username
:
{
username
:
{
...
@@ -38,8 +62,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
...
@@ -38,8 +62,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
});
});
});
});
it
(
'works with limit'
,
()
=>
{
it
(
'Works with limit'
,
()
=>
{
const
User
=
Support
.
sequelize
.
define
(
'User'
,
{
const
User
=
Support
.
sequelize
.
define
(
'User'
,
{
username
:
{
username
:
{
type
:
DataTypes
.
STRING
type
:
DataTypes
.
STRING
...
@@ -53,7 +76,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
...
@@ -53,7 +76,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
expectsql
(
sql
.
updateQuery
(
User
.
tableName
,
{
username
:
'new.username'
},
{
username
:
'username'
},
{
limit
:
1
}),
{
expectsql
(
sql
.
updateQuery
(
User
.
tableName
,
{
username
:
'new.username'
},
{
username
:
'username'
},
{
limit
:
1
}),
{
query
:
{
query
:
{
mssql
:
'UPDATE TOP(1) [Users] SET [username]=$1
OUTPUT INSERTED.*
WHERE [username] = $2'
,
mssql
:
'UPDATE TOP(1) [Users] SET [username]=$1 WHERE [username] = $2'
,
mariadb
:
'UPDATE `Users` SET `username`=$1 WHERE `username` = $2 LIMIT 1'
,
mariadb
:
'UPDATE `Users` SET `username`=$1 WHERE `username` = $2 LIMIT 1'
,
mysql
:
'UPDATE `Users` SET `username`=$1 WHERE `username` = $2 LIMIT 1'
,
mysql
:
'UPDATE `Users` SET `username`=$1 WHERE `username` = $2 LIMIT 1'
,
sqlite
:
'UPDATE `Users` SET `username`=$1 WHERE rowid IN (SELECT rowid FROM `Users` WHERE `username` = $2 LIMIT 1)'
,
sqlite
:
'UPDATE `Users` SET `username`=$1 WHERE rowid IN (SELECT rowid FROM `Users` WHERE `username` = $2 LIMIT 1)'
,
...
...
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