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
不要怂,就是干,撸起袖子干!
You need to sign in or sign up before continuing.
Commit aa13dc6d
authored
Nov 02, 2016
by
Harshith Kashyap
Committed by
Jan Aagaard Meier
Nov 02, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes MSSQL bulkInsertQuery when options and attributes are not passed (#6782)
1 parent
5a266dcb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
3 deletions
changelog.md
lib/dialects/mssql/query-generator.js
test/unit/dialects/mssql/query-generator.test.js
changelog.md
View file @
aa13dc6
# Future
# Future
-
[
FIXED
]
MSSQL bulkInsertQuery when options and attributes are not passed
-
[
FIXED
]
`DATEONLY`
now returns
`YYYY-MM-DD`
date string
[
#4858
]
(
https://github.com/sequelize/sequelize/issues/4858
)
-
[
FIXED
]
`DATEONLY`
now returns
`YYYY-MM-DD`
date string
[
#4858
]
(
https://github.com/sequelize/sequelize/issues/4858
)
-
[
FIXED
]
Issues with
`createFunction`
and
`dropFunction`
(PostgresSQL)
-
[
FIXED
]
Issues with
`createFunction`
and
`dropFunction`
(PostgresSQL)
-
[
FIXED
]
Issue with belongsTo association and foreign keys
[
#6400
](
https://github.com/sequelize/sequelize/issues/6400
)
-
[
FIXED
]
Issue with belongsTo association and foreign keys
[
#6400
](
https://github.com/sequelize/sequelize/issues/6400
)
...
...
lib/dialects/mssql/query-generator.js
View file @
aa13dc6
...
@@ -232,6 +232,8 @@ var QueryGenerator = {
...
@@ -232,6 +232,8 @@ var QueryGenerator = {
},
},
bulkInsertQuery
(
tableName
,
attrValueHashes
,
options
,
attributes
)
{
bulkInsertQuery
(
tableName
,
attrValueHashes
,
options
,
attributes
)
{
options
=
options
||
{};
attributes
=
attributes
||
{};
var
query
=
'INSERT INTO <%= table %> (<%= attributes %>)<%= output %> VALUES <%= tuples %>;'
var
query
=
'INSERT INTO <%= table %> (<%= attributes %>)<%= output %> VALUES <%= tuples %>;'
,
emptyQuery
=
'INSERT INTO <%= table %><%= output %> DEFAULT VALUES'
,
emptyQuery
=
'INSERT INTO <%= table %><%= output %> DEFAULT VALUES'
,
tuples
=
[]
,
tuples
=
[]
...
@@ -247,14 +249,15 @@ var QueryGenerator = {
...
@@ -247,14 +249,15 @@ var QueryGenerator = {
Utils
.
_
.
forEach
(
attrValueHashes
,
function
(
attrValueHash
)
{
Utils
.
_
.
forEach
(
attrValueHashes
,
function
(
attrValueHash
)
{
// special case for empty objects with primary keys
// special case for empty objects with primary keys
var
fields
=
Object
.
keys
(
attrValueHash
);
var
fields
=
Object
.
keys
(
attrValueHash
);
if
(
fields
.
length
===
1
&&
attributes
[
fields
[
0
]].
autoIncrement
&&
attrValueHash
[
fields
[
0
]]
===
null
)
{
var
firstAttr
=
attributes
[
fields
[
0
]];
if
(
fields
.
length
===
1
&&
firstAttr
&&
firstAttr
.
autoIncrement
&&
attrValueHash
[
fields
[
0
]]
===
null
)
{
allQueries
.
push
(
emptyQuery
);
allQueries
.
push
(
emptyQuery
);
return
;
return
;
}
}
// normal case
// normal case
Utils
.
_
.
forOwn
(
attrValueHash
,
function
(
value
,
key
)
{
Utils
.
_
.
forOwn
(
attrValueHash
,
function
(
value
,
key
)
{
if
(
value
!==
null
&&
attributes
[
key
].
autoIncrement
)
{
if
(
value
!==
null
&&
attributes
[
key
]
&&
attributes
[
key
]
.
autoIncrement
)
{
needIdentityInsertWrapper
=
true
;
needIdentityInsertWrapper
=
true
;
}
}
...
@@ -296,7 +299,6 @@ var QueryGenerator = {
...
@@ -296,7 +299,6 @@ var QueryGenerator = {
'SET IDENTITY_INSERT'
,
this
.
quoteTable
(
tableName
),
'OFF;'
'SET IDENTITY_INSERT'
,
this
.
quoteTable
(
tableName
),
'OFF;'
].
join
(
' '
);
].
join
(
' '
);
}
}
return
generatedQuery
;
return
generatedQuery
;
},
},
...
...
test/unit/dialects/mssql/query-generator.test.js
View file @
aa13dc6
...
@@ -24,6 +24,27 @@ if (current.dialect.name === 'mssql') {
...
@@ -24,6 +24,27 @@ if (current.dialect.name === 'mssql') {
});
});
});
});
test
(
'bulkInsertQuery'
,
function
()
{
//normal cases
expectsql
(
QueryGenerator
.
bulkInsertQuery
(
'myTable'
,
[{
name
:
'foo'
},
{
name
:
'bar'
}]),
{
mssql
:
"INSERT INTO [myTable] ([name]) VALUES (N'foo'),(N'bar');"
});
expectsql
(
QueryGenerator
.
bulkInsertQuery
(
'myTable'
,
[{
username
:
'username'
,
firstName
:
'firstName'
,
lastName
:
'lastName'
},
{
firstName
:
'user1FirstName'
,
lastName
:
'user1LastName'
}]),
{
mssql
:
"INSERT INTO [myTable] ([username],[firstName],[lastName]) VALUES (N'username',N'firstName',N'lastName'),(NULL,N'user1FirstName',N'user1LastName');"
});
expectsql
(
QueryGenerator
.
bulkInsertQuery
(
'myTable'
,
[{
firstName
:
'firstName'
,
lastName
:
'lastName'
},
{
firstName
:
'user1FirstName'
,
lastName
:
'user1LastName'
}]),
{
mssql
:
"INSERT INTO [myTable] ([firstName],[lastName]) VALUES (N'firstName',N'lastName'),(N'user1FirstName',N'user1LastName');"
});
//Bulk Insert With autogenerated primary key
var
attributes
=
{
id
:
{
autoIncrement
:
true
}};
expectsql
(
QueryGenerator
.
bulkInsertQuery
(
'myTable'
,
[{
id
:
null
}],
{},
attributes
),
{
mssql
:
"INSERT INTO [myTable] DEFAULT VALUES"
});
});
test
(
'selectFromTableFragment'
,
function
()
{
test
(
'selectFromTableFragment'
,
function
()
{
var
modifiedGen
=
_
.
clone
(
QueryGenerator
);
var
modifiedGen
=
_
.
clone
(
QueryGenerator
);
// Test newer versions first
// Test newer versions first
...
...
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