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 2eb25d6b
authored
May 22, 2013
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #636 from mweibel/fix-sqlite-addquotes
SQLite addQuotes is not correct
2 parents
b9e335d6
a524aeae
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
2 deletions
lib/dialects/sqlite/query-generator.js
spec/dao-factory.spec.js
lib/dialects/sqlite/query-generator.js
View file @
2eb25d6
...
@@ -24,8 +24,17 @@ module.exports = (function() {
...
@@ -24,8 +24,17 @@ module.exports = (function() {
var
QueryGenerator
=
{
var
QueryGenerator
=
{
options
:
{},
options
:
{},
addQuotes
:
function
(
s
,
quoteChar
)
{
removeQuotes
:
function
(
s
,
quoteChar
)
{
return
Utils
.
addTicks
(
s
,
quoteChar
)
quoteChar
=
quoteChar
||
'`'
return
s
.
replace
(
new
RegExp
(
quoteChar
,
'g'
),
''
)
},
addQuotes
:
function
(
s
,
quoteChar
)
{
quoteChar
=
quoteChar
||
'`'
return
QueryGenerator
.
removeQuotes
(
s
,
quoteChar
)
.
split
(
'.'
)
.
map
(
function
(
e
)
{
return
quoteChar
+
String
(
e
)
+
quoteChar
})
.
join
(
'.'
)
},
},
addSchema
:
function
(
opts
)
{
addSchema
:
function
(
opts
)
{
...
@@ -149,6 +158,74 @@ module.exports = (function() {
...
@@ -149,6 +158,74 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
replacements
)
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
},
selectQuery
:
function
(
tableName
,
options
)
{
var
table
=
null
,
joinQuery
=
""
options
=
options
||
{}
options
.
table
=
table
=
Array
.
isArray
(
tableName
)
?
tableName
.
map
(
function
(
tbl
){
return
QueryGenerator
.
addQuotes
(
tbl
)
}).
join
(
", "
)
:
QueryGenerator
.
addQuotes
(
tableName
)
options
.
attributes
=
options
.
attributes
&&
options
.
attributes
.
map
(
function
(
attr
){
if
(
Array
.
isArray
(
attr
)
&&
attr
.
length
==
2
)
{
return
[
attr
[
0
],
QueryGenerator
.
addQuotes
(
attr
[
1
])].
join
(
' as '
)
}
else
{
return
attr
.
indexOf
(
Utils
.
TICK_CHAR
)
<
0
?
QueryGenerator
.
addQuotes
(
attr
)
:
attr
}
}).
join
(
", "
)
options
.
attributes
=
options
.
attributes
||
'*'
if
(
options
.
include
)
{
var
optAttributes
=
options
.
attributes
===
'*'
?
[
options
.
table
+
'.*'
]
:
[
options
.
attributes
]
options
.
include
.
forEach
(
function
(
include
)
{
var
attributes
=
Object
.
keys
(
include
.
daoFactory
.
attributes
).
map
(
function
(
attr
)
{
return
"`"
+
include
.
as
+
"`.`"
+
attr
+
"` AS `"
+
include
.
as
+
"."
+
attr
+
"`"
})
optAttributes
=
optAttributes
.
concat
(
attributes
)
var
table
=
include
.
daoFactory
.
tableName
var
as
=
include
.
as
var
tableLeft
=
((
include
.
association
.
associationType
===
'BelongsTo'
)
?
include
.
as
:
tableName
)
var
attrLeft
=
'id'
var
tableRight
=
((
include
.
association
.
associationType
===
'BelongsTo'
)
?
tableName
:
include
.
as
)
var
attrRight
=
include
.
association
.
identifier
joinQuery
+=
" LEFT OUTER JOIN `"
+
table
+
"` AS `"
+
as
+
"` ON `"
+
tableLeft
+
"`.`"
+
attrLeft
+
"` = `"
+
tableRight
+
"`.`"
+
attrRight
+
"`"
})
options
.
attributes
=
optAttributes
.
join
(
', '
)
}
var
query
=
"SELECT "
+
options
.
attributes
+
" FROM "
+
options
.
table
query
+=
joinQuery
if
(
options
.
hasOwnProperty
(
'where'
))
{
options
.
where
=
this
.
getWhereConditions
(
options
.
where
,
tableName
)
query
+=
" WHERE "
+
options
.
where
}
if
(
options
.
group
)
{
options
.
group
=
Array
.
isArray
(
options
.
group
)
?
options
.
group
.
map
(
function
(
grp
){
return
QueryGenerator
.
addQuotes
(
grp
)}).
join
(
', '
)
:
QueryGenerator
.
addQuotes
(
options
.
group
)
query
+=
" GROUP BY "
+
options
.
group
}
if
(
options
.
order
)
{
query
+=
" ORDER BY "
+
options
.
order
}
if
(
options
.
limit
&&
!
(
options
.
include
&&
(
options
.
limit
===
1
)))
{
if
(
options
.
offset
)
{
query
+=
" LIMIT "
+
options
.
offset
+
", "
+
options
.
limit
}
else
{
query
+=
" LIMIT "
+
options
.
limit
}
}
query
+=
";"
return
query
},
updateQuery
:
function
(
tableName
,
attrValueHash
,
where
)
{
updateQuery
:
function
(
tableName
,
attrValueHash
,
where
)
{
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
...
...
spec/dao-factory.spec.js
View file @
2eb25d6
...
@@ -1563,6 +1563,10 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
...
@@ -1563,6 +1563,10 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
expect
(
self
.
UserSpecialSync
.
getTableName
()).
toEqual
(
'"special"."UserSpecials"'
);
expect
(
self
.
UserSpecialSync
.
getTableName
()).
toEqual
(
'"special"."UserSpecials"'
);
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO "special"."UserSpecials"'
)).
toBeGreaterThan
(
-
1
)
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO "special"."UserSpecials"'
)).
toBeGreaterThan
(
-
1
)
expect
(
UserPublic
.
indexOf
(
'INSERT INTO "UserPublics"'
)).
toBeGreaterThan
(
-
1
)
expect
(
UserPublic
.
indexOf
(
'INSERT INTO "UserPublics"'
)).
toBeGreaterThan
(
-
1
)
}
else
if
(
dialect
===
"sqlite"
)
{
expect
(
self
.
UserSpecialSync
.
getTableName
()).
toEqual
(
'`special`.`UserSpecials`'
);
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO `special.UserSpecials`'
)).
toBeGreaterThan
(
-
1
)
expect
(
UserPublic
.
indexOf
(
'INSERT INTO `UserPublics`'
)).
toBeGreaterThan
(
-
1
)
}
else
{
}
else
{
expect
(
self
.
UserSpecialSync
.
getTableName
()).
toEqual
(
'`special.UserSpecials`'
);
expect
(
self
.
UserSpecialSync
.
getTableName
()).
toEqual
(
'`special.UserSpecials`'
);
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO `special.UserSpecials`'
)).
toBeGreaterThan
(
-
1
)
expect
(
UserSpecial
.
indexOf
(
'INSERT INTO `special.UserSpecials`'
)).
toBeGreaterThan
(
-
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