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 1bcb67ce
authored
Oct 22, 2014
by
Joel Trost
Committed by
Matt Broadstone
Dec 09, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added check for incorrect constraints for mssql
1 parent
7949f932
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
17 deletions
lib/dialects/mssql/query-generator.js
lib/dialects/mssql/query.js
lib/dialects/mssql/sql-generator.js
test/include/findAll.test.js
lib/dialects/mssql/query-generator.js
View file @
1bcb67c
...
@@ -322,8 +322,41 @@ module.exports = (function() {
...
@@ -322,8 +322,41 @@ module.exports = (function() {
,
key
,
key
,
attribute
;
,
attribute
;
for
(
key
in
attributes
)
{
//detect multiple cascades associated with the same id
var
cascadeCheck
=
[];
for
(
key
in
attributes
){
attribute
=
attributes
[
key
];
attribute
=
attributes
[
key
];
if
(
attribute
.
onDelete
||
attribute
.
onUpdate
){
//handles self referencial keys, first it doesnt make sense, second, what?
if
(
attribute
.
Model
&&
attribute
.
Model
.
tableName
===
attribute
.
references
){
console
.
warn
(
'MSSQL does not support self referencial constraints, '
+
'we will remove it but we recommend restructuring your query'
);
attribute
.
onDelete
=
''
;
attribute
.
onUpdate
=
''
;
}
else
{
cascadeCheck
.
push
(
key
);
}
}
}
for
(
var
i
=
0
;
i
<
cascadeCheck
.
length
-
1
;
i
++
){
var
casKey
=
cascadeCheck
[
i
];
for
(
var
j
=
i
+
1
;
j
<
cascadeCheck
.
length
;
j
++
){
var
casKey2
=
cascadeCheck
[
j
];
if
(
attributes
[
casKey
].
references
===
attributes
[
casKey2
].
references
&&
attributes
[
casKey
].
referencesKey
===
attributes
[
casKey2
].
referencesKey
){
console
.
warn
(
'MSSQL does not support multiple cascade keys on the same reference, '
+
'we will removing them to make this work but we recommend restructuring your query.'
);
attributes
[
casKey
].
onDelete
=
''
;
attributes
[
casKey
].
onUpdate
=
''
;
attributes
[
casKey2
].
onDelete
=
''
;
attributes
[
casKey2
].
onUpdate
=
''
;
}
}
}
for
(
key
in
attributes
)
{
attribute
=
attributes
[
key
];
//console.log(attribute);
if
(
key
&&
!
attribute
.
field
)
if
(
key
&&
!
attribute
.
field
)
attribute
.
field
=
key
;
attribute
.
field
=
key
;
result
[
attribute
.
field
||
key
]
=
SqlGenerator
.
attributeToSQL
(
attribute
,
options
);
result
[
attribute
.
field
||
key
]
=
SqlGenerator
.
attributeToSQL
(
attribute
,
options
);
...
@@ -1002,8 +1035,8 @@ module.exports = (function() {
...
@@ -1002,8 +1035,8 @@ module.exports = (function() {
if
(
options
.
parent
)
{
if
(
options
.
parent
)
{
return
;
return
;
}
}
return
;
return
'SET TRANSACTION ISOLATION LEVEL '
+
value
+
';'
;
//
return 'SET TRANSACTION ISOLATION LEVEL ' + value + ';';
},
},
/**
/**
* Returns a query that starts a transaction.
* Returns a query that starts a transaction.
...
...
lib/dialects/mssql/query.js
View file @
1bcb67c
...
@@ -53,7 +53,9 @@ module.exports = (function() {
...
@@ -53,7 +53,9 @@ module.exports = (function() {
});
});
}
else
{
}
else
{
var
request
,
transCommand
;
var
request
,
transCommand
;
if
(
self
.
connection
.
lib
.
_transaction
&&
self
.
connection
.
uuid
)
{
if
(
self
.
connection
.
lib
.
_transaction
&&
self
.
connection
.
uuid
){
request
=
new
self
.
connection
.
lib
.
Request
(
self
.
connection
.
lib
.
_transaction
);
request
=
new
self
.
connection
.
lib
.
Request
(
self
.
connection
.
lib
.
_transaction
);
if
(
self
.
sql
===
'COMMIT TRANSACTION;'
)
{
if
(
self
.
sql
===
'COMMIT TRANSACTION;'
)
{
...
@@ -78,7 +80,6 @@ module.exports = (function() {
...
@@ -78,7 +80,6 @@ module.exports = (function() {
}
else
{
}
else
{
request
=
new
self
.
connection
.
lib
.
Request
(
self
.
connection
.
context
);
request
=
new
self
.
connection
.
lib
.
Request
(
self
.
connection
.
context
);
}
}
request
.
query
(
self
.
sql
,
function
(
err
,
recordset
)
{
request
.
query
(
self
.
sql
,
function
(
err
,
recordset
)
{
if
(
promise
){
if
(
promise
){
promise
.
emit
(
'sql'
,
self
.
sql
,
self
.
connection
.
uuid
);
promise
.
emit
(
'sql'
,
self
.
sql
,
self
.
connection
.
uuid
);
...
@@ -143,7 +144,7 @@ module.exports = (function() {
...
@@ -143,7 +144,7 @@ module.exports = (function() {
result
=
data
.
length
;
result
=
data
.
length
;
}
else
if
(
this
.
isBulkDeleteQuery
()){
}
else
if
(
this
.
isBulkDeleteQuery
()){
result
=
data
[
0
].
AFFECTEDROWS
;
result
=
data
[
0
].
AFFECTEDROWS
;
}
else
if
(
result
.
dataValues
){}
}
else
if
(
result
&&
result
.
dataValues
){}
else
{
else
{
result
=
this
.
handleSelectQuery
(
data
);
result
=
this
.
handleSelectQuery
(
data
);
}
}
...
...
lib/dialects/mssql/sql-generator.js
View file @
1bcb67c
...
@@ -615,18 +615,16 @@ module.exports = {
...
@@ -615,18 +615,16 @@ module.exports = {
}
}
//PROBLEM WITH THIS IS MSSQL DOES NOT ALLOW MULTIPLE PER KEY
//PROBLEM WITH THIS IS MSSQL DOES NOT ALLOW MULTIPLE PER KEY
if
((
attribute
.
onDelete
&&
!
attribute
.
onUpdate
)
||
(
!
attribute
.
onDelete
&&
attribute
.
onUpdate
)){
if
(
attribute
.
onDelete
)
{
if
(
attribute
.
onDelete
)
{
if
(
attribute
.
onDelete
.
toUpperCase
()
!==
'RESTRICT'
){
if
(
attribute
.
onDelete
.
toUpperCase
()
!==
'RESTRICT'
){
template
.
push
(
attributeMap
.
onDelete
);
template
.
push
(
attributeMap
.
onDelete
);
template
.
push
(
attribute
.
onDelete
.
toUpperCase
());
template
.
push
(
attribute
.
onDelete
.
toUpperCase
());
}
}
}
}
if
(
attribute
.
onUpdate
)
{
if
(
attribute
.
onUpdate
&&
!
attribute
.
onDelete
)
{
template
.
push
(
attributeMap
.
onUpdate
);
template
.
push
(
attributeMap
.
onUpdate
);
template
.
push
(
attribute
.
onUpdate
.
toUpperCase
());
template
.
push
(
attribute
.
onUpdate
.
toUpperCase
());
}
}
}
}
}
...
...
test/include/findAll.test.js
View file @
1bcb67c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
var
chai
=
require
(
'chai'
)
var
chai
=
require
(
'chai'
)
,
Sequelize
=
require
(
'../../index'
)
,
Sequelize
=
require
(
'../../index'
)
,
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
)
,
Support
=
require
(
__dirname
+
'/../support'
)
,
dialect
=
Support
.
getTestDialect
()
,
DataTypes
=
require
(
__dirname
+
"/../../lib/data-types"
)
,
DataTypes
=
require
(
__dirname
+
"/../../lib/data-types"
)
,
datetime
=
require
(
'chai-datetime'
)
,
datetime
=
require
(
'chai-datetime'
)
,
async
=
require
(
'async'
)
,
async
=
require
(
'async'
)
...
@@ -17,6 +18,7 @@ var sortById = function(a, b) {
...
@@ -17,6 +18,7 @@ var sortById = function(a, b) {
}
}
describe
(
Support
.
getTestDialectTeaser
(
"Include"
),
function
()
{
describe
(
Support
.
getTestDialectTeaser
(
"Include"
),
function
()
{
describe
(
'findAll'
,
function
()
{
describe
(
'findAll'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
fixtureA
=
function
(
done
)
{
this
.
fixtureA
=
function
(
done
)
{
...
...
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