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 75f48a23
authored
Nov 04, 2018
by
Takashi Sasaki
Committed by
Sushant
Nov 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(query): correctly quote identifier for attributes (#9964) (#10118)
1 parent
25071392
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
1 deletions
lib/dialects/abstract/query-generator.js
test/integration/model/attributes.test.js
test/unit/dialects/mysql/query-generator.test.js
lib/dialects/abstract/query-generator.js
View file @
75f48a2
...
@@ -885,6 +885,14 @@ class QueryGenerator {
...
@@ -885,6 +885,14 @@ class QueryGenerator {
return
this
.
quoteIdentifier
(
identifiers
);
return
this
.
quoteIdentifier
(
identifiers
);
}
}
quoteAttribute
(
attribute
,
model
)
{
if
(
model
&&
attribute
in
model
.
rawAttributes
)
{
return
this
.
quoteIdentifier
(
attribute
);
}
else
{
return
this
.
quoteIdentifiers
(
attribute
);
}
}
/**
/**
* Quote table name with optional alias and schema attribution
* Quote table name with optional alias and schema attribution
*
*
...
@@ -1389,7 +1397,7 @@ class QueryGenerator {
...
@@ -1389,7 +1397,7 @@ class QueryGenerator {
attr = [attr[0], this.quoteIdentifier(attr[1])].join(' AS ');
attr = [attr[0], this.quoteIdentifier(attr[1])].join(' AS ');
} else {
} else {
attr = !attr.includes(Utils.TICK_CHAR) && !attr.includes('"')
attr = !attr.includes(Utils.TICK_CHAR) && !attr.includes('"')
? this.quote
Identifiers(attr
)
? this.quote
Attribute(attr, options.model
)
: this.escape(attr);
: this.escape(attr);
}
}
if (!_.isEmpty(options.include) && !attr.includes('.') && addTable) {
if (!_.isEmpty(options.include) && !attr.includes('.') && addTable) {
...
...
test/integration/model/attributes.test.js
View file @
75f48a2
...
@@ -131,5 +131,19 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -131,5 +131,19 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
});
});
});
describe
(
'quote'
,
()
=>
{
it
(
'allows for an attribute with dots'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'user'
,
{
'foo.bar.baz'
:
Sequelize
.
TEXT
});
return
this
.
sequelize
.
sync
({
force
:
true
})
.
then
(()
=>
User
.
findAll
())
.
then
(
result
=>
{
expect
(
result
.
length
).
to
.
equal
(
0
);
});
});
});
});
});
});
});
test/unit/dialects/mysql/query-generator.test.js
View file @
75f48a2
...
@@ -468,6 +468,18 @@ if (dialect === 'mysql') {
...
@@ -468,6 +468,18 @@ if (dialect === 'mysql') {
expectation
:
'SELECT `test`.* FROM (SELECT * FROM `myTable` AS `test` HAVING `creationYear` > 2002) AS `test`;'
,
expectation
:
'SELECT `test`.* FROM (SELECT * FROM `myTable` AS `test` HAVING `creationYear` > 2002) AS `test`;'
,
context
:
QueryGenerator
,
context
:
QueryGenerator
,
needsSequelize
:
true
needsSequelize
:
true
},
{
title
:
'Contains fields with "." characters.'
,
arguments
:
[
'myTable'
,
{
attributes
:
[
'foo.bar.baz'
],
model
:
{
rawAttributes
:
{
'foo.bar.baz'
:
{}
}
}
}],
expectation
:
'SELECT `foo.bar.baz` FROM `myTable`;'
,
context
:
QueryGenerator
}
}
],
],
...
...
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