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 3657f32e
authored
Dec 15, 2017
by
Ratanak Lun
Committed by
Sushant
Dec 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(mssql): improper parameter binding in sql generation (#8782)
1 parent
ccee348c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
15 deletions
lib/dialects/mssql/query.js
test/unit/dialects/mssql/connection-manager.js → test/unit/dialects/mssql/connection-manager.test.js
test/unit/dialects/mssql/query.js → test/unit/dialects/mssql/query.test.js
test/unit/dialects/mssql/resource-lock.test.js
lib/dialects/mssql/query.js
View file @
3657f32
...
...
@@ -144,16 +144,9 @@ class Query extends AbstractQuery {
static
formatBindParameters
(
sql
,
values
,
dialect
)
{
const
bindParam
=
{};
let
i
=
0
;
const
seen
=
{};
const
replacementFunc
=
(
match
,
key
,
values
)
=>
{
if
(
seen
[
key
]
!==
undefined
)
{
return
seen
[
key
];
}
if
(
values
[
key
]
!==
undefined
)
{
i
=
i
+
1
;
bindParam
[
key
]
=
values
[
key
];
seen
[
key
]
=
'$'
+
i
;
return
'@'
+
key
;
}
return
undefined
;
...
...
test/unit/dialects/mssql/connection-manager.js
→
test/unit/dialects/mssql/connection-manager.
test.
js
View file @
3657f32
...
...
@@ -3,13 +3,16 @@
const
chai
=
require
(
'chai'
),
expect
=
chai
.
expect
,
Sequelize
=
require
(
__dirname
+
'/../../../../index'
),
Support
=
require
(
__dirname
+
'/../../support'
),
dialect
=
Support
.
getTestDialect
(),
tedious
=
require
(
'tedious'
),
sinon
=
require
(
'sinon'
),
connectionStub
=
sinon
.
stub
(
tedious
,
'Connection'
);
connectionStub
.
returns
({
on
()
{}});
describe
(
'[MSSQL] Connection Manager'
,
()
=>
{
if
(
dialect
===
'mssql'
)
{
describe
(
'[MSSQL Specific] Connection Manager'
,
()
=>
{
let
instance
,
config
;
beforeEach
(()
=>
{
...
...
@@ -37,4 +40,5 @@ describe('[MSSQL] Connection Manager', () => {
instance
.
dialect
.
connectionManager
.
_connect
(
config
);
expect
(
config
.
dialectOptions
.
domain
).
to
.
equal
(
'TEST.COM'
);
});
});
});
}
test/unit/dialects/mssql/query.js
→
test/unit/dialects/mssql/query.
test.
js
View file @
3657f32
...
...
@@ -2,7 +2,8 @@
const
path
=
require
(
'path'
);
const
Query
=
require
(
path
.
resolve
(
'./lib/dialects/mssql/query.js'
));
const
Support
=
require
(
path
.
resolve
(
'./test/support'
));
const
Support
=
require
(
__dirname
+
'/../../support'
);
const
dialect
=
Support
.
getTestDialect
();
const
sequelize
=
Support
.
sequelize
;
const
sinon
=
require
(
'sinon'
);
const
expect
=
require
(
'chai'
).
expect
;
...
...
@@ -12,7 +13,8 @@ const connectionStub = { beginTransaction: () => {}, lib: tedious };
let
sandbox
,
query
;
describe
(
'[MSSQL]'
,
()
=>
{
if
(
dialect
===
'mssql'
)
{
describe
(
'[MSSQL Specific] Query'
,
()
=>
{
describe
(
'beginTransaction'
,
()
=>
{
beforeEach
(()
=>
{
sandbox
=
sinon
.
sandbox
.
create
();
...
...
@@ -40,4 +42,29 @@ describe('[MSSQL]', () => {
sandbox
.
restore
();
});
});
});
describe
(
'formatBindParameters'
,
()
=>
{
it
(
'should convert Sequelize named binding format to MSSQL format'
,
()
=>
{
const
sql
=
'select $one as a, $two as b, $one as c, $three as d, $one as e'
;
const
values
=
{
one
:
1
,
two
:
2
,
three
:
3
};
const
expected
=
'select @one as a, @two as b, @one as c, @three as d, @one as e'
;
const
result
=
Query
.
formatBindParameters
(
sql
,
values
,
dialect
);
expect
(
result
[
0
]).
to
.
be
.
a
(
'string'
);
expect
(
result
[
0
]).
to
.
equal
(
expected
);
});
it
(
'should convert Sequelize numbered binding format to MSSQL format'
,
()
=>
{
const
sql
=
'select $1 as a, $2 as b, $1 as c, $3 as d, $1 as e'
;
const
values
=
[
1
,
2
,
3
];
const
expected
=
'select @0 as a, @1 as b, @0 as c, @2 as d, @0 as e'
;
const
result
=
Query
.
formatBindParameters
(
sql
,
values
,
dialect
);
expect
(
result
[
0
]).
to
.
be
.
a
(
'string'
);
expect
(
result
[
0
]).
to
.
equal
(
expected
);
});
});
});
}
test/unit/dialects/mssql/resource-lock.test.js
View file @
3657f32
...
...
@@ -2,9 +2,12 @@
const
ResourceLock
=
require
(
'../../../../lib/dialects/mssql/resource-lock'
),
Promise
=
require
(
'../../../../lib/promise'
),
assert
=
require
(
'assert'
);
assert
=
require
(
'assert'
),
Support
=
require
(
__dirname
+
'/../../support'
),
dialect
=
Support
.
getTestDialect
();
describe
(
'[MSSQL Specific] ResourceLock'
,
()
=>
{
if
(
dialect
===
'mssql'
)
{
describe
(
'[MSSQL Specific] ResourceLock'
,
()
=>
{
it
(
'should process requests serially'
,
()
=>
{
const
expected
=
{};
const
lock
=
new
ResourceLock
(
expected
);
...
...
@@ -61,4 +64,5 @@ describe('[MSSQL Specific] ResourceLock', () => {
assert
.
equal
(
lock
.
unwrap
(),
expected
);
});
});
});
}
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