summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-10-10 15:37:25 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-10-10 15:50:32 +0300
commit42c34ddd1fee261da43331e855c80bc432d66247 (patch)
treef7ce555367d895540489756cae5a016d846ae01c /src
parentcd62cf6524cbd8764655364ea8a243f69b6020b0 (diff)
downloadsql-parser-42c34ddd1fee261da43331e855c80bc432d66247.zip
sql-parser-42c34ddd1fee261da43331e855c80bc432d66247.tar.gz
sql-parser-42c34ddd1fee261da43331e855c80bc432d66247.tar.bz2
Avoid building a field multiple times if clause has synonyms.v3.0.3
Diffstat (limited to 'src')
-rw-r--r--src/Statement.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Statement.php b/src/Statement.php
index 3fe3f42..b15dc3d 100644
--- a/src/Statement.php
+++ b/src/Statement.php
@@ -108,6 +108,20 @@ abstract class Statement
*/
$query = '';
+ /**
+ * Clauses which were built already.
+ *
+ * It is required to keep track of built clauses because some fields,
+ * for example `join` is used by multiple clauses (`JOIN`, `LEFT JOIN`,
+ * `LEFT OUTER JOIN`, etc.). The same happens for `VALUE` and `VALUES`.
+ *
+ * A clause is considered built just after fields' value
+ * (`$this->field`) was used in building.
+ *
+ * @var array
+ */
+ $built = array();
+
foreach (static::$CLAUSES as $clause) {
/**
* The name of the clause.
@@ -144,6 +158,15 @@ abstract class Statement
continue;
}
+ // Checking if this field was already built.
+ if ($type & 1) {
+ if (!empty($built[$field])) {
+ continue;
+ }
+
+ $built[$field] = true;
+ }
+
// Checking if the name of the clause should be added.
if ($type & 2) {
$query .= $name . ' ';