Esempio n. 1
0
 public function toDialectString(Dialect $dialect)
 {
     $query = 'INSERT INTO ' . $dialect->quoteTable($this->table) . ' ';
     if ($this->select === null) {
         $query = $this->toDialectStringValues($query, $dialect);
     } else {
         $query = $this->toDialectStringSelect($query, $dialect);
     }
     $query .= parent::toDialectString($dialect);
     return $query;
 }
Esempio n. 2
0
 public function toDialectString(Dialect $dialect)
 {
     $query = 'UPDATE ' . $dialect->quoteTable($this->table) . ' SET ';
     $sets = [];
     foreach ($this->fields as $var => $val) {
         if ($val instanceof DialectString) {
             $sets[] = $dialect->quoteField($var) . ' = (' . $val->toDialectString($dialect) . ')';
         } elseif ($val === null) {
             $sets[] = $dialect->quoteField($var) . ' = ' . $dialect->literalToString(Dialect::LITERAL_NULL);
         } elseif (true === $val) {
             $sets[] = $dialect->quoteField($var) . ' = ' . $dialect->literalToString(Dialect::LITERAL_TRUE);
         } elseif (false === $val) {
             $sets[] = $dialect->quoteField($var) . ' = ' . $dialect->literalToString(Dialect::LITERAL_FALSE);
         } else {
             $sets[] = $dialect->quoteField($var) . ' = ' . $dialect->quoteValue($val);
         }
     }
     return $query . implode(', ', $sets) . $this->joiner->toDialectString($dialect) . parent::toDialectString($dialect);
 }
Esempio n. 3
0
 /**
  * @return InsertOrUpdateQuery
  **/
 public function fillQuery(InsertOrUpdateQuery $query, Prototyped $object, Prototyped $old = null)
 {
     if ($this->relationId || $this->generic) {
         // skip collections
         if ($this->relationId != MetaRelation::ONE_TO_ONE && !$this->generic) {
             return $query;
         }
         $getter = $this->getter;
         if ($this->relationId && $this->strategyId == FetchStrategy::LAZY) {
             $getter = $getter . 'Id';
         }
         $value = $object->{$getter}();
         if ($old) {
             $oldValue = $old->{$getter}();
             if ($oldValue === null && $value === $oldValue) {
                 return $query;
             } elseif ($this->relationId && $this->strategyId == FetchStrategy::LAZY && $value === $oldValue) {
                 return $query;
             } elseif ($value instanceof Identifiable && $oldValue instanceof Identifiable && $value->getId() === $oldValue->getId()) {
                 return $query;
             } elseif (serialize($value) == serialize($oldValue)) {
                 return $query;
             }
         }
         switch ($this->type) {
             case 'binary':
                 $query->set($this->columnName, new DBBinary($value));
                 break;
             case 'json':
                 $query->set($this->columnName, DBArray::create($value)->json());
                 break;
             case 'jsonb':
                 $query->set($this->columnName, DBArray::create($value)->jsonb());
                 break;
             default:
                 $query->lazySet($this->columnName, $value);
                 break;
         }
     }
     return $query;
 }
Esempio n. 4
0
 protected function inject(InsertOrUpdateQuery $query, Identifiable $object)
 {
     $this->checkObjectType($object);
     $this->runTrigger($object, OnBeforeSave::class);
     return $this->doInject($this->setQueryFields($query->setTable($this->getTable()), $object), $object);
 }