diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Statement.php | 23 |
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 . ' '; |