不要怂,就是干,撸起袖子干!

Commit 4f1c03c4 by Mick Hansen

Merge pull request #1493 from joshm/schema_qna

Add pg schema specific test sets
2 parents 50fea7b0 934bfa09
...@@ -638,7 +638,7 @@ module.exports = (function() { ...@@ -638,7 +638,7 @@ module.exports = (function() {
if (options.include) { if (options.include) {
var generateJoinQueries = function(include, parentTable) { var generateJoinQueries = function(include, parentTable) {
var table = include.daoFactory.tableName var table = include.daoFactory.getTableName()
, as = include.as , as = include.as
, joinQueryItem = "" , joinQueryItem = ""
, joinQueries = { , joinQueries = {
...@@ -672,7 +672,7 @@ module.exports = (function() { ...@@ -672,7 +672,7 @@ module.exports = (function() {
} }
if (through) { if (through) {
var throughTable = through.daoFactory.tableName var throughTable = through.daoFactory.getTableName()
, throughAs = as + "." + through.as , throughAs = as + "." + through.as
, throughAttributes = through.attributes.map(function(attr) { , throughAttributes = through.attributes.map(function(attr) {
return self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(attr) + " AS " + self.quoteIdentifier(throughAs + "." + attr) return self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(attr) + " AS " + self.quoteIdentifier(throughAs + "." + attr)
...@@ -699,7 +699,7 @@ module.exports = (function() { ...@@ -699,7 +699,7 @@ module.exports = (function() {
// Filter statement for left side of through // Filter statement for left side of through
// Used by both join and subquery where // Used by both join and subquery where
sourceJoinOn = self.quoteIdentifier(tableSource) + "." + self.quoteIdentifier(attrSource) + " = " sourceJoinOn = self.quoteTable(tableSource) + "." + self.quoteIdentifier(attrSource) + " = "
sourceJoinOn += self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(identSource) sourceJoinOn += self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(identSource)
// Filter statement for right side of through // Filter statement for right side of through
...@@ -708,7 +708,7 @@ module.exports = (function() { ...@@ -708,7 +708,7 @@ module.exports = (function() {
targetJoinOn += self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(identTarget) targetJoinOn += self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(identTarget)
// Generate join SQL for left side of through // Generate join SQL for left side of through
joinQueryItem += joinType + self.quoteIdentifier(throughTable) + " AS " + self.quoteIdentifier(throughAs) + " ON " joinQueryItem += joinType + self.quoteTable(throughTable) + " AS " + self.quoteIdentifier(throughAs) + " ON "
joinQueryItem += sourceJoinOn joinQueryItem += sourceJoinOn
// Generate join SQL for right side of through // Generate join SQL for right side of through
...@@ -724,7 +724,7 @@ module.exports = (function() { ...@@ -724,7 +724,7 @@ module.exports = (function() {
// Creating the as-is where for the subQuery, checks that the required association exists // Creating the as-is where for the subQuery, checks that the required association exists
var _where = "("; var _where = "(";
_where += "SELECT "+self.quoteIdentifier(identSource)+" FROM " + self.quoteIdentifier(throughTable) + " AS " + self.quoteIdentifier(throughAs); _where += "SELECT "+self.quoteIdentifier(identSource)+" FROM " + self.quoteTable(throughTable) + " AS " + self.quoteIdentifier(throughAs);
_where += joinType + self.quoteTable(table) + " AS " + self.quoteIdentifier(as) + " ON "+targetJoinOn; _where += joinType + self.quoteTable(table) + " AS " + self.quoteIdentifier(as) + " ON "+targetJoinOn;
_where += " WHERE " + sourceJoinOn + " AND " + targetWhere + " LIMIT 1" _where += " WHERE " + sourceJoinOn + " AND " + targetWhere + " LIMIT 1"
_where += ")"; _where += ")";
...@@ -876,9 +876,33 @@ module.exports = (function() { ...@@ -876,9 +876,33 @@ module.exports = (function() {
// If using subQuery, select attributes from wrapped subQuery and join out join tables // If using subQuery, select attributes from wrapped subQuery and join out join tables
if (subQuery) { if (subQuery) {
//the subquery "AS" uses the tableName at the front of the SELECT (out of the subquery)
//as the "AS", when this is the case, force quoting on the mainAttributes "options.table"
//that will be used in the "AS".
var asTable = options.table
var aliasAttrs = mainAttributes[0].split('.')
if(aliasAttrs.length > 1) {
var baseName = aliasAttrs[0]+'.'+aliasAttrs[1]
//here is the match from subquery to mainAttributes
if(baseName === options.table) {
var aliasAttrs = mainAttributes[0].split('.')
var remainingVals = Utils._.rest(aliasAttrs, 2)
//only add back the rest if it exists
if(remainingVals.length) {
mainAttributes[0] = self.quoteIdentifier(baseName, true)+'.'+remainingVals.join('.')
} else {
mainAttributes[0] = self.quoteIdentifier(baseName, true)
}
//quote the "as"
asTable = self.quoteIdentifier(options.table, true)
}
}
query = "SELECT " + mainAttributes.join(', ') + " FROM (" query = "SELECT " + mainAttributes.join(', ') + " FROM ("
query += subQueryItems.join('') query += subQueryItems.join('')
query += ") AS "+options.table query += ") AS "+asTable
query += mainJoinQueries.join('') query += mainJoinQueries.join('')
query += mainQueryItems.join('') query += mainQueryItems.join('')
} else { } else {
......
...@@ -279,7 +279,7 @@ module.exports = (function() { ...@@ -279,7 +279,7 @@ module.exports = (function() {
}.bind(this)) }.bind(this))
var replacements = { var replacements = {
table: this.quoteIdentifiers(tableName) table: this.quoteTable(tableName)
, attributes: allAttributes.map(function(attr){ , attributes: allAttributes.map(function(attr){
return this.quoteIdentifier(attr) return this.quoteIdentifier(attr)
}.bind(this)).join(",") }.bind(this)).join(",")
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!