public function build(Breakdown $breakDown, $tabs) { $breakDown->append(' ( CASE '); if ($this->value !== null) { $this->value->build($breakDown, $tabs); } foreach ($this->whenThen as $whenThen) { if (count($whenThen) != 2) { throw new \Exception('invalid when/then pair'); } /** @var SQL|ClauseInterface $when */ list($when, $then) = $whenThen; $breakDown->append(' WHEN'); $when->build($breakDown, $tabs); $breakDown->append(' THEN'); if ($then instanceof SQL) { $breakDown->append(' ( '); $then->build($breakDown, $tabs); $breakDown->append(' )'); } else { $breakDown->append(' ?'); $breakDown->addParameter($then); } } if ($this->else instanceof SQL) { $breakDown->append(' ( '); $this->else->build($breakDown, $tabs); $breakDown->append(' )'); } elseif ($this->else !== null) { $breakDown->append(' ELSE ?'); $breakDown->addParameter($this->else); } $breakDown->append(' END )'); }
public function build(Breakdown $bk, $tabs) { $fieldFunctionOpenedParenthesis = false; if ($this->function != null) { $bk->append(" " . $this->function); $bk->append("("); $fieldFunctionOpenedParenthesis = true; } $doCommaField = false; foreach ($this->functionFields as $field) { if ($field === null) { continue; } if ($doCommaField) { $bk->append(","); } else { $doCommaField = true; } $field->build($bk, $tabs); } if ($fieldFunctionOpenedParenthesis) { $bk->append(" )"); $fieldFunctionOpenedParenthesis = false; } $bk->appendAs($this->as_()); }
public function build(Breakdown $bk, $tabs) { $bk->append(" " . $this->column); if (!$this->asc) { $bk->append(" DESC"); } }
public function build(Breakdown $bk, $tabs) { $bk->append(" INTERSECT"); if ($this->all) { $bk->append(" ALL"); } $this->sql->build($bk, $tabs); }
public function build(Breakdown $bk, $tabs) { $bk->line($tabs + 2); $bk->append(" " . $this->column1); if ($this->column2) { $bk->append(" = "); $bk->append(" " . $this->column2); } }
public function build(Breakdown $bk, $tabs) { if ($this->sql instanceof SQL) { $bk->append(" ("); $this->sql->build($bk, $tabs); $bk->append(" )"); } else { $bk->append(" ?"); $bk->addParameter($this->sql); } }
public function build(Breakdown $bk, $tabs) { $bk->line($tabs + 1); $bk->append(' ON DUPLICATE KEY UPDATE '); $columnCount = count($this->columns); $columnIndex = 1; /** @var Set $columnSet */ foreach ($this->columns as $columnSet) { $columnSet->build($bk, $tabs); if ($columnIndex++ < $columnCount) { $bk->append(','); } } }
public function build(Breakdown $bk, $tabs) { if (!$this->in) { $bk->append(" NOT"); } $bk->append(" IN"); $bk->append(" ("); if ($this->values instanceof SQL) { $this->values->build($bk, $tabs); } else { $bk->append(explode(',', $this->values)); } $bk->append(" )"); }
public function buildUsing(Breakdown $bk, $tabs) { $doUsingClause = true; $doCommaUsing = false; foreach ($this->using as $using) { /** @var Using $using */ if ($doUsingClause) { $bk->line($tabs + 2); $bk->append(" USING ("); $doUsingClause = false; } if ($doCommaUsing) { $bk->append(", "); } else { $doCommaUsing = true; } $using->build($bk, $tabs); } if ($doUsingClause == false) { $bk->append(")"); } }
public function build(Breakdown $bk, $tabs) { $bk->line($tabs + 1); $bk->append(" INTO"); $bk->append(" " . $this->table); if ($this->columns != null) { $bk->append(' ('); $bk->append(implode(', ', $this->columns)); $bk->append(') VALUES'); } }
public function build(Breakdown $bk, $tabs) { $bk->append(" " . $this->name); $bk->append(" AS "); if ($this->sql != null) { $bk->append(" ("); $bk->line($tabs); $bk->tabs($tabs + 1); $this->sql->build($bk, $tabs); $bk->line($tabs); $bk->append(" )"); $bk->line(0); } }
public function build(Breakdown $bk, $tabs) { $bk->append(" " . $this->column); $bk->append(" = "); if ($this->isSql) { $bk->append($this->value); } else { $bk->append("?"); $bk->addParameter($this->value); } }
public function build(Breakdown $bk, $tabs) { $doWhere = true; /** @var Condition $condition */ foreach ($this->conditions as $condition) { if ($doWhere) { $bk->line($tabs + 1); $bk->append(" {$this->keyword}"); $doWhere = false; } else { $bk->line($tabs + 1); $bk->append(" " . $condition->connector()); } $condition->build($bk, $tabs); } }
public function injectParams($db, Breakdown $breakDown) { $sql = $breakDown->getSql(); $params = $breakDown->getParameters(); foreach ($params as $p) { $sql = preg_replace('/\\?/', "'" . addslashes($p) . "'", $sql, 1); } return $sql; }
public function build(Breakdown $bk, $tabs) { $bk->append(" " . $this->table); }
public function build(Breakdown $bk, $tabs) { $bk->append(" OFFSET"); $bk->append(" " . $this->offset); }
public function build(Breakdown $bk, $tabs) { $bk->append(" LIMIT"); $bk->append(" " . $this->limit); }
public function build(Breakdown $bk, $tabs) { $bk->append(" FROM"); $bk->append(" " . $this->table); $bk->appendAs($this->as_()); }
/** * @param DatabaseBase $db * @param sql\Breakdown $breakDown * @return mixed */ public function injectParams($db, sql\Breakdown $breakDown) { return $db->fillPrepared($breakDown->getSql(), $breakDown->getParameters()); }
public function build(Breakdown $bk, $tabs) { $bk->append(join(", ", $this->columns)); }
public function generateKey(Breakdown $breakDown) { return md5($breakDown->getSql() . implode(',', $breakDown->getParameters())); }