Пример #1
0
 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 )');
 }
Пример #2
0
 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_());
 }
Пример #3
0
 public function build(Breakdown $bk, $tabs)
 {
     $bk->append(" " . $this->column);
     if (!$this->asc) {
         $bk->append(" DESC");
     }
 }
Пример #4
0
 public function build(Breakdown $bk, $tabs)
 {
     $bk->append(" INTERSECT");
     if ($this->all) {
         $bk->append(" ALL");
     }
     $this->sql->build($bk, $tabs);
 }
Пример #5
0
 public function build(Breakdown $bk, $tabs)
 {
     $bk->line($tabs + 2);
     $bk->append(" " . $this->column1);
     if ($this->column2) {
         $bk->append(" = ");
         $bk->append(" " . $this->column2);
     }
 }
Пример #6
0
 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);
     }
 }
Пример #7
0
 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(',');
         }
     }
 }
Пример #8
0
 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(" )");
 }
Пример #9
0
 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(")");
     }
 }
Пример #10
0
 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');
     }
 }
Пример #11
0
 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);
     }
 }
Пример #12
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);
     }
 }
Пример #13
0
 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);
     }
 }
Пример #14
0
 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;
 }
Пример #15
0
 public function build(Breakdown $bk, $tabs)
 {
     $bk->append(" " . $this->table);
 }
Пример #16
0
 public function build(Breakdown $bk, $tabs)
 {
     $bk->append(" OFFSET");
     $bk->append(" " . $this->offset);
 }
Пример #17
0
 public function build(Breakdown $bk, $tabs)
 {
     $bk->append(" LIMIT");
     $bk->append(" " . $this->limit);
 }
Пример #18
0
 public function build(Breakdown $bk, $tabs)
 {
     $bk->append(" FROM");
     $bk->append(" " . $this->table);
     $bk->appendAs($this->as_());
 }
Пример #19
0
 /**
  * @param DatabaseBase $db
  * @param sql\Breakdown $breakDown
  * @return mixed
  */
 public function injectParams($db, sql\Breakdown $breakDown)
 {
     return $db->fillPrepared($breakDown->getSql(), $breakDown->getParameters());
 }
Пример #20
0
 public function build(Breakdown $bk, $tabs)
 {
     $bk->append(join(", ", $this->columns));
 }
Пример #21
0
 public function generateKey(Breakdown $breakDown)
 {
     return md5($breakDown->getSql() . implode(',', $breakDown->getParameters()));
 }