Skip to content

Instantly share code, notes, and snippets.

@mateusz
Created August 13, 2014 04:57
Show Gist options
  • Save mateusz/7aa356b6c87ce8a347e2 to your computer and use it in GitHub Desktop.
Save mateusz/7aa356b6c87ce8a347e2 to your computer and use it in GitHub Desktop.
---DOWNSTREAM---
commit df6a8b6fb630a7065c0066a3dae288ff23ddddf4
Author: Senorgeno <genedower@gmail.com>
Date: Thu Jul 17 13:27:28 2014 +1200
BUG #3282: Added ability to subselect with in left or inner join
diff --git a/model/SQLQuery.php b/model/SQLQuery.php
index 79ddb57..c4a12ca 100644
--- a/model/SQLQuery.php
+++ b/model/SQLQuery.php
@@ -903,9 +903,11 @@ class SQLQuery {
else if(sizeof($join['filter']) == 1) $filter = $join['filter'][0];
else $filter = "(" . implode(") AND (", $join['filter']) . ")";
+ $table = strpos(strtoupper($join['table']), 'SELECT') ? $join['table'] : "\""
+ . $join['table'] . "\"";
$aliasClause = ($alias != $join['table']) ? " AS \"" . Convert::raw2sql($alias) . "\"" : "";
- $this->from[$alias] = strtoupper($join['type']) . " JOIN \""
- . $join['table'] . "\"$aliasClause ON $filter";
+ $this->from[$alias] = strtoupper($join['type']) . " JOIN "
+ . $table . "$aliasClause ON $filter";
}
}
---MATEUSZ PROPOSES---
diff --git a/model/queries/SQLConditionalExpression.php b/model/queries/SQLConditionalExpression.php
index 521a6c5..be50ed9 100644
--- a/model/queries/SQLConditionalExpression.php
+++ b/model/queries/SQLConditionalExpression.php
@@ -280,8 +280,9 @@ abstract class SQLConditionalExpression extends SQLExpression {
$filter = "(" . implode(") AND (", $join['filter']) . ")";
}
+ $table = strpos(strtoupper($join['table']), 'SELECT') ? $join['table'] : "\"" . $join['table'] . "\"";
$aliasClause = ($alias != $join['table']) ? " AS \"$alias\"" : "";
- $joins[$alias] = strtoupper($join['type']) . ' JOIN "' . $join['table'] . "\"$aliasClause ON $filter";
+ $joins[$alias] = strtoupper($join['type']) . " JOIN " . $table . "$aliasClause ON $filter";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment