Beispiel #1
0
 protected function _setModelSaved($model)
 {
     reflection::invokeArgs('freestyle\\model', '_setFromDb', $model, [true]);
     //$model->setFromDb(true);
     reflection::invokeArgs('freestyle\\model', '_resetChangedKeys', $model, []);
     //$model->resetChangedKeys();
 }
Beispiel #2
0
 public function update($storage, $model)
 {
     $a = $model->toArray();
     $tableName = $storage->getTableName();
     $keyMap = $storage->getKeyMap();
     $pka = $keyMap->getPrimary();
     $changedKeys = reflection::invokeArgs('freestyle\\model', '_getChangedKeys', $model, []);
     $stKey = 'update/' . $tableName . '/' . \implode(',', $changedKeys);
     $n = 0;
     $values = [];
     $sql = 'UPDATE ' . $tableName . '';
     $seta = [];
     foreach ($changedKeys as $k) {
         $seta[] = $k . ' = ?';
         //.(++$n);
         $values[] = $a[$k];
     }
     $sql .= ' SET ' . \implode(', ', $seta);
     $wa = [];
     foreach ($pka as $k) {
         $wa[] = $k . ' = ?';
         //.(++$n);
         $values[] = $a[$k];
     }
     $sql .= ' WHERE ' . \implode(' AND ', $wa);
     $stmt = $this->getLink()->prepare($sql, [\PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY]);
     if ($stmt->execute($values)) {
         $this->_setModelSaved($model);
         return true;
     }
     return false;
 }
Beispiel #3
0
 public function update($storage, $model)
 {
     $a = $model->toArray();
     $tableName = $storage->getTableName();
     $keyMap = $storage->getKeyMap();
     $pka = $keyMap->getPrimary();
     $changedKeys = reflection::invokeArgs('freestyle\\model', '_getChangedKeys', $model, []);
     $stKey = 'update/' . $tableName . '/' . \implode(',', $changedKeys);
     $n = 0;
     $values = [];
     $sql = 'UPDATE ' . $tableName . '';
     $seta = [];
     foreach ($changedKeys as $k) {
         $seta[] = $k . ' = $' . ++$n;
         $values[] = $a[$k];
     }
     $sql .= ' SET ' . \implode(', ', $seta);
     $wa = [];
     foreach ($pka as $k) {
         $wa[] = $k . ' = $' . ++$n;
         $values[] = $a[$k];
     }
     $sql .= ' WHERE ' . \implode(' AND ', $wa);
     if (!isset(self::$_prepared[$stKey])) {
         \pg_prepare($this->getLink(), $stKey, $sql);
     }
     $q = \pg_execute($this->getLink(), $stKey, $values);
     if ($q) {
         $this->_setModelSaved($model);
         return true;
     }
     return false;
 }