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 089cedc8
authored
Sep 25, 2014
by
Joel Trost
Committed by
Matt Broadstone
Dec 09, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for lib/instance passing where clause
1 parent
198f3501
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
5 deletions
lib/dialects/mssql/query-generator.js
lib/dialects/mssql/query.js
lib/dialects/mssql/sql-generator.js
lib/instance.js
lib/dialects/mssql/query-generator.js
View file @
089cedc
...
...
@@ -160,7 +160,10 @@ module.exports = (function() {
If you use a string, you have to escape it on your own.
*/
updateQuery
:
function
(
tableName
,
attrValueHash
,
where
,
options
,
attributes
)
{
console
.
log
(
where
);
// if(where){
// throw new Error();
// }
console
.
log
(
'here'
,
where
);
var
query
=
[
SqlGenerator
.
updateSql
(
tableName
,
attrValueHash
,
attributes
),
this
.
getWhereConditions
(
where
)
...
...
lib/dialects/mssql/query.js
View file @
089cedc
...
...
@@ -22,6 +22,11 @@ module.exports = (function() {
};
Utils
.
inherit
(
Query
,
AbstractQuery
);
Query
.
prototype
.
getInsertIdField
=
function
()
{
return
'id'
;
};
Query
.
prototype
.
run
=
function
(
sql
)
{
console
.
log
(
sql
);
var
self
=
this
;
...
...
@@ -65,7 +70,7 @@ module.exports = (function() {
*/
Query
.
prototype
.
formatResults
=
function
(
data
)
{
var
result
=
this
.
callee
;
//console.log(data);
if
(
this
.
isInsertQuery
(
data
))
{
this
.
handleInsertQuery
(
data
);
}
else
if
(
this
.
isShowTableQuery
())
{
...
...
@@ -176,5 +181,16 @@ module.exports = (function() {
});
};
AbstractQuery
.
prototype
.
handleInsertQuery
=
function
(
results
,
metaData
)
{
if
(
this
.
callee
)
{
// add the inserted row id to the instance
var
autoIncrementField
=
this
.
callee
.
Model
.
autoIncrementField
,
id
=
null
;
id
=
id
||
(
results
&&
results
[
0
][
this
.
getInsertIdField
()]);
id
=
id
||
(
metaData
&&
metaData
[
this
.
getInsertIdField
()]);
this
.
callee
[
autoIncrementField
]
=
id
;
}
};
return
Query
;
})();
lib/dialects/mssql/sql-generator.js
View file @
089cedc
...
...
@@ -225,8 +225,10 @@ module.exports = {
valueHash
=
Utils
.
removeNullValuesFromHash
(
valueHash
,
_options
.
omitNull
);
var
selFields
=
[];
var
insertKey
=
false
;
for
(
var
key
in
valueHash
)
{
selFields
.
push
(
'INSERTED.'
+
quoteIdentifier
(
key
));
if
(
modelAttributeMap
[
key
].
autoIncrement
){
insertKey
=
true
;
delete
valueHash
[
key
];
...
...
@@ -236,7 +238,7 @@ module.exports = {
var
replacements
=
{
tableName
:
quoteIdentifier
(
tableName
),
attributes
:
fieldsToSql
(
valueHash
,
false
),
selFields
:
fieldsToSql
(
valueHash
,
true
),
selFields
:
selFields
.
join
(
','
),
values
:
valuesToSql
(
valueHash
,
modelAttributeMap
)
};
...
...
@@ -247,7 +249,32 @@ module.exports = {
// }
return
Utils
.
_
.
template
(
query
)(
replacements
);
},
updateSql
:
function
(
tableName
,
valueHash
,
where
,
options
,
attributes
){
options
=
options
||
{};
valueHash
=
Utils
.
removeNullValuesFromHash
(
valueHash
,
this
.
options
.
omitNull
,
options
);
var
query
,
selFields
=
[]
,
values
=
[];
query
=
'UPDATE <%= tableName %> SET <%= values %> OUTPUT <%= selFields %>'
;
for
(
var
key
in
valueHash
)
{
var
value
=
valueHash
[
key
];
selFields
.
push
(
'INSERTED.'
+
quoteIdentifier
(
key
));
values
.
push
(
quoteIdentifier
(
key
)
+
'='
+
escape
(
value
,
(
!!
attributes
&&
!!
attributes
[
key
]
?
attributes
[
key
]
:
undefined
)));
}
var
replacements
=
{
tableName
:
quoteIdentifier
(
tableName
),
attributes
:
fieldsToSql
(
valueHash
,
false
),
selFields
:
selFields
.
join
(
','
),
values
:
values
.
join
(
','
),
};
return
Utils
.
_
.
template
(
query
)(
replacements
);
},
addColumnSql
:
function
(
key
,
dataType
){
var
attribute
=
Utils
.
_
.
template
(
'<%= key %> <%= definition %>'
)({
key
:
quoteIdentifier
(
key
),
...
...
@@ -515,7 +542,11 @@ module.exports = {
getWhereClause
:
function
(
where
,
tableName
){
var
query
=
[
'WHERE'
];
for
(
var
key
in
where
){
query
.
push
(
quoteIdentifier
(
tableName
)
+
'.'
+
quoteIdentifier
(
key
));
if
(
tableName
){
query
.
push
(
quoteIdentifier
(
tableName
)
+
'.'
+
quoteIdentifier
(
key
));
}
else
{
query
.
push
(
quoteIdentifier
(
key
));
}
query
.
push
(
'='
);
query
.
push
(
where
[
key
]);
}
...
...
lib/instance.js
View file @
089cedc
...
...
@@ -562,7 +562,6 @@ module.exports = (function() {
}
}
}
if
(
identifier
===
null
&&
self
.
__options
.
whereCollection
!==
null
)
{
identifier
=
self
.
__options
.
whereCollection
;
}
...
...
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