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 235b3968
authored
Oct 29, 2015
by
User4martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make Query.formatBindParameters static
1 parent
5eb25bf0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
11 additions
and
9 deletions
lib/dialects/abstract/query.js
lib/dialects/mssql/query.js
lib/dialects/mysql/query.js
lib/dialects/postgres/query.js
lib/dialects/sqlite/query.js
lib/sequelize.js
lib/dialects/abstract/query.js
View file @
235b396
...
@@ -394,7 +394,7 @@ var groupJoinData = function(rows, includeOptions, options) {
...
@@ -394,7 +394,7 @@ var groupJoinData = function(rows, includeOptions, options) {
* skipUnescape: bool, skip unescaping $$
* skipUnescape: bool, skip unescaping $$
* skipValueReplace: bool, do not replace (but do unescape $$). Check correct syntax and if all values are available
* skipValueReplace: bool, do not replace (but do unescape $$). Check correct syntax and if all values are available
*/
*/
AbstractQuery
.
prototype
.
formatBindParameters
=
function
(
sql
,
values
,
dialect
,
replacementFunc
,
options
)
{
AbstractQuery
.
formatBindParameters
=
function
(
sql
,
values
,
dialect
,
replacementFunc
,
options
)
{
if
(
!
values
)
{
if
(
!
values
)
{
return
[
sql
,
[]];
return
[
sql
,
[]];
}
}
...
...
lib/dialects/mssql/query.js
View file @
235b396
...
@@ -24,6 +24,7 @@ Query.prototype.getInsertIdField = function() {
...
@@ -24,6 +24,7 @@ Query.prototype.getInsertIdField = function() {
return
'id'
;
return
'id'
;
};
};
Query
.
formatBindParameters
=
AbstractQuery
.
formatBindParameters
;
Query
.
prototype
.
run
=
function
(
sql
,
parameters
)
{
Query
.
prototype
.
run
=
function
(
sql
,
parameters
)
{
var
self
=
this
;
var
self
=
this
;
this
.
sql
=
sql
;
this
.
sql
=
sql
;
...
...
lib/dialects/mysql/query.js
View file @
235b396
...
@@ -21,6 +21,7 @@ var Query = function(connection, sequelize, options) {
...
@@ -21,6 +21,7 @@ var Query = function(connection, sequelize, options) {
};
};
Utils
.
inherit
(
Query
,
AbstractQuery
);
Utils
.
inherit
(
Query
,
AbstractQuery
);
Query
.
formatBindParameters
=
AbstractQuery
.
formatBindParameters
;
Query
.
prototype
.
run
=
function
(
sql
,
parameters
)
{
Query
.
prototype
.
run
=
function
(
sql
,
parameters
)
{
var
self
=
this
;
var
self
=
this
;
this
.
sql
=
sql
;
this
.
sql
=
sql
;
...
...
lib/dialects/postgres/query.js
View file @
235b396
...
@@ -90,11 +90,11 @@ Query.prototype.parseDialectSpecificFields = parseDialectSpecificFields;
...
@@ -90,11 +90,11 @@ Query.prototype.parseDialectSpecificFields = parseDialectSpecificFields;
/**
/**
* rewrite query with parameters
* rewrite query with parameters
*/
*/
Query
.
prototype
.
formatBindParameters
=
function
(
sql
,
values
,
dialect
)
{
Query
.
formatBindParameters
=
function
(
sql
,
values
,
dialect
)
{
var
bindParam
=
[];
var
bindParam
=
[];
if
(
Array
.
isArray
(
values
))
{
if
(
Array
.
isArray
(
values
))
{
bindParam
=
values
;
bindParam
=
values
;
sql
=
this
.
parent
.
formatBindParameters
(
sql
,
values
,
dialect
,
{
skipValueReplace
:
true
})[
0
];
sql
=
AbstractQuery
.
formatBindParameters
(
sql
,
values
,
dialect
,
{
skipValueReplace
:
true
})[
0
];
}
else
{
}
else
{
var
i
=
0
;
var
i
=
0
;
var
seen
=
{};
var
seen
=
{};
...
@@ -110,7 +110,7 @@ Query.prototype.formatBindParameters = function(sql, values, dialect) {
...
@@ -110,7 +110,7 @@ Query.prototype.formatBindParameters = function(sql, values, dialect) {
}
}
return
undefined
;
return
undefined
;
};
};
sql
=
this
.
parent
.
formatBindParameters
(
sql
,
values
,
dialect
,
replacementFunc
)[
0
];
sql
=
AbstractQuery
.
formatBindParameters
(
sql
,
values
,
dialect
,
replacementFunc
)[
0
];
}
}
return
[
sql
,
bindParam
];
return
[
sql
,
bindParam
];
};
};
...
...
lib/dialects/sqlite/query.js
View file @
235b396
...
@@ -27,14 +27,14 @@ Query.prototype.getInsertIdField = function() {
...
@@ -27,14 +27,14 @@ Query.prototype.getInsertIdField = function() {
/**
/**
* rewrite query with parameters
* rewrite query with parameters
*/
*/
Query
.
prototype
.
formatBindParameters
=
function
(
sql
,
values
,
dialect
)
{
Query
.
formatBindParameters
=
function
(
sql
,
values
,
dialect
)
{
var
bindParam
=
[];
var
bindParam
=
[];
if
(
Array
.
isArray
(
values
))
{
if
(
Array
.
isArray
(
values
))
{
bindParam
=
{};
bindParam
=
{};
values
.
forEach
(
function
(
v
,
i
)
{
values
.
forEach
(
function
(
v
,
i
)
{
bindParam
[
'$'
+
(
i
+
1
)]
=
v
;
bindParam
[
'$'
+
(
i
+
1
)]
=
v
;
});
});
sql
=
this
.
parent
.
formatBindParameters
(
sql
,
values
,
dialect
,
{
skipValueReplace
:
true
})[
0
];
sql
=
AbstractQuery
.
formatBindParameters
(
sql
,
values
,
dialect
,
{
skipValueReplace
:
true
})[
0
];
}
else
{
}
else
{
bindParam
=
{};
bindParam
=
{};
if
(
typeof
values
===
'object'
)
{
if
(
typeof
values
===
'object'
)
{
...
@@ -42,7 +42,7 @@ Query.prototype.formatBindParameters = function(sql, values, dialect) {
...
@@ -42,7 +42,7 @@ Query.prototype.formatBindParameters = function(sql, values, dialect) {
bindParam
[
'$'
+
k
]
=
values
[
k
];
bindParam
[
'$'
+
k
]
=
values
[
k
];
});
});
}
}
sql
=
this
.
parent
.
formatBindParameters
(
sql
,
values
,
dialect
,
{
skipValueReplace
:
true
})[
0
];
sql
=
AbstractQuery
.
formatBindParameters
(
sql
,
values
,
dialect
,
{
skipValueReplace
:
true
})[
0
];
}
}
return
[
sql
,
bindParam
];
return
[
sql
,
bindParam
];
};
};
...
@@ -55,7 +55,7 @@ Query.prototype.run = function(sql, parameters) {
...
@@ -55,7 +55,7 @@ Query.prototype.run = function(sql, parameters) {
var
method
=
self
.
getDatabaseMethod
();
var
method
=
self
.
getDatabaseMethod
();
if
(
method
===
'exec'
)
{
if
(
method
===
'exec'
)
{
// exec does not support bind parameter
// exec does not support bind parameter
sql
=
this
.
parent
.
formatBindParameters
(
sql
,
self
.
options
.
bind
,
self
.
options
.
dialect
,
{
skipUnescape
:
true
})[
0
];
sql
=
AbstractQuery
.
formatBindParameters
(
sql
,
self
.
options
.
bind
,
self
.
options
.
dialect
,
{
skipUnescape
:
true
})[
0
];
this
.
sql
=
sql
;
this
.
sql
=
sql
;
}
}
...
...
lib/sequelize.js
View file @
235b396
...
@@ -739,7 +739,7 @@ Sequelize.prototype.query = function(sql, options) {
...
@@ -739,7 +739,7 @@ Sequelize.prototype.query = function(sql, options) {
}
}
var
bindParameters
;
var
bindParameters
;
if
(
options
.
bind
)
{
if
(
options
.
bind
)
{
var
bindSql
=
self
.
dialect
.
Query
.
prototype
.
formatBindParameters
(
sql
,
options
.
bind
,
this
.
options
.
dialect
);
var
bindSql
=
self
.
dialect
.
Query
.
formatBindParameters
(
sql
,
options
.
bind
,
this
.
options
.
dialect
);
sql
=
bindSql
[
0
];
sql
=
bindSql
[
0
];
bindParameters
=
bindSql
[
1
];
bindParameters
=
bindSql
[
1
];
}
}
...
...
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