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 4d75caf4
authored
May 16, 2020
by
Sushant
Committed by
GitHub
May 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(mssql): duplicate order in FETCH/NEXT queries (#12257)
1 parent
9a95e727
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
2 deletions
lib/dialects/mssql/query-generator.js
test/integration/dialects/mssql/regressions.test.js
lib/dialects/mssql/query-generator.js
View file @
4d75caf
...
@@ -917,8 +917,18 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator {
...
@@ -917,8 +917,18 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator {
if
(
options
.
limit
||
options
.
offset
)
{
if
(
options
.
limit
||
options
.
offset
)
{
if
(
!
options
.
order
||
options
.
include
&&
!
orders
.
subQueryOrder
.
length
)
{
if
(
!
options
.
order
||
options
.
include
&&
!
orders
.
subQueryOrder
.
length
)
{
const
tablePkFragment
=
`
${
this
.
quoteTable
(
options
.
tableAs
||
model
.
name
)}
.
${
this
.
quoteIdentifier
(
model
.
primaryKeyField
)}
`
;
if
(
!
options
.
order
)
{
fragment
+=
` ORDER BY
${
tablePkFragment
}
`
;
}
else
{
const
orderFieldNames
=
_
.
map
(
options
.
order
,
order
=>
order
[
0
]);
const
primaryKeyFieldAlreadyPresent
=
_
.
includes
(
orderFieldNames
,
model
.
primaryKeyField
);
if
(
!
primaryKeyFieldAlreadyPresent
)
{
fragment
+=
options
.
order
&&
!
isSubQuery
?
', '
:
' ORDER BY '
;
fragment
+=
options
.
order
&&
!
isSubQuery
?
', '
:
' ORDER BY '
;
fragment
+=
`
${
this
.
quoteTable
(
options
.
tableAs
||
model
.
name
)}
.
${
this
.
quoteIdentifier
(
model
.
primaryKeyField
)}
`
;
fragment
+=
tablePkFragment
;
}
}
}
}
if
(
options
.
offset
||
options
.
limit
)
{
if
(
options
.
offset
||
options
.
limit
)
{
...
...
test/integration/dialects/mssql/regressions.test.js
View file @
4d75caf
...
@@ -8,7 +8,7 @@ const chai = require('chai'),
...
@@ -8,7 +8,7 @@ const chai = require('chai'),
dialect
=
Support
.
getTestDialect
();
dialect
=
Support
.
getTestDialect
();
if
(
dialect
.
match
(
/^mssql/
))
{
if
(
dialect
.
match
(
/^mssql/
))
{
describe
(
'[MSSQL Specific] Regressions'
,
()
=>
{
describe
(
Support
.
getTestDialectTeaser
(
'Regressions'
)
,
()
=>
{
it
(
'does not duplicate columns in ORDER BY statement, #9008'
,
async
function
()
{
it
(
'does not duplicate columns in ORDER BY statement, #9008'
,
async
function
()
{
const
LoginLog
=
this
.
sequelize
.
define
(
'LoginLog'
,
{
const
LoginLog
=
this
.
sequelize
.
define
(
'LoginLog'
,
{
ID
:
{
ID
:
{
...
@@ -80,7 +80,54 @@ if (dialect.match(/^mssql/)) {
...
@@ -80,7 +80,54 @@ if (dialect.match(/^mssql/)) {
expect
(
logs
).
to
.
have
.
length
(
2
);
expect
(
logs
).
to
.
have
.
length
(
2
);
expect
(
logs
[
0
].
User
.
get
(
'UserName'
)).
to
.
equal
(
'Shaktimaan'
);
expect
(
logs
[
0
].
User
.
get
(
'UserName'
)).
to
.
equal
(
'Shaktimaan'
);
expect
(
logs
[
1
].
User
.
get
(
'UserName'
)).
to
.
equal
(
'Aryamaan'
);
expect
(
logs
[
1
].
User
.
get
(
'UserName'
)).
to
.
equal
(
'Aryamaan'
);
// #11258 and similar
const
otherLogs
=
await
LoginLog
.
findAll
({
include
:
[
{
model
:
User
,
where
:
{
UserName
:
{
[
Op
.
like
]:
'%maan%'
}
}
}
],
order
:
[[
'id'
,
'DESC'
]],
offset
:
0
,
limit
:
10
});
});
expect
(
otherLogs
).
to
.
have
.
length
(
2
);
expect
(
otherLogs
[
0
].
User
.
get
(
'UserName'
)).
to
.
equal
(
'Aryamaan'
);
expect
(
otherLogs
[
1
].
User
.
get
(
'UserName'
)).
to
.
equal
(
'Shaktimaan'
);
// Separate queries can apply order freely
const
separateUsers
=
await
User
.
findAll
({
include
:
[
{
model
:
LoginLog
,
separate
:
true
,
order
:
[
'id'
]
}
],
where
:
{
UserName
:
{
[
Op
.
like
]:
'%maan%'
}
},
order
:
[
'UserName'
,
[
'UserID'
,
'DESC'
]],
offset
:
0
,
limit
:
10
});
expect
(
separateUsers
).
to
.
have
.
length
(
2
);
expect
(
separateUsers
[
0
].
get
(
'UserName'
)).
to
.
equal
(
'Aryamaan'
);
expect
(
separateUsers
[
0
].
get
(
'LoginLogs'
)).
to
.
have
.
length
(
1
);
expect
(
separateUsers
[
1
].
get
(
'UserName'
)).
to
.
equal
(
'Shaktimaan'
);
expect
(
separateUsers
[
1
].
get
(
'LoginLogs'
)).
to
.
have
.
length
(
1
);
});
});
it
(
'sets the varchar(max) length correctly on describeTable'
,
async
function
()
{
it
(
'sets the varchar(max) length correctly on describeTable'
,
async
function
()
{
...
@@ -148,4 +195,5 @@ if (dialect.match(/^mssql/)) {
...
@@ -148,4 +195,5 @@ if (dialect.match(/^mssql/)) {
const
record
=
await
BooleanTable
.
findOne
();
const
record
=
await
BooleanTable
.
findOne
();
expect
(
record
.
status
).
to
.
equals
(
value
);
expect
(
record
.
status
).
to
.
equals
(
value
);
});
});
});
}
}
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