Update a record

@param mixed  $attrs    attributes
@param string $calling  class
@param string $pk       primary key
@param mixed  $pk_value primary key value

@return boolean updated or not
196186
private function _update($attrs,$calling,$pk,$pk_value)
    {
        $escape        = Driver::$escape_char;
        $vals          = array();
        $update_column = self::hasColumn("updated_at");
        $create_column = self::hasColumn("created_at");

        // no way to update a primary key!
        unset($attrs[$pk]);

        $sql = "update $escape".$calling::getTableName()."$escape set ";

        foreach ($attrs as $attr => $value) {
            if (($update_column &&    $attr == $update_column)
                || ($create_column && $attr == $create_column)
            ) {
                continue;
            }

            if (strlen(trim($value)) < 1) {
                $value = null;
            }

            $sql .= "$escape".self::$_mapping[$calling][$attr]."$escape=?,";
            array_push($vals, $value);
        }

        if ($update_column) {
            $sql .= "$escape".self::$_mapping[$calling][$update_column]."$escape=".Driver::$current_timestamp.",";
        }

        $sql  = substr($sql, 0, strlen($sql)-1);
        $sql .= " where $escape".self::getTableName()."$escape.$escape".self::$_mapping[$calling][$pk]."$escape=?";
        array_push($vals, $pk_value);

        return self::executePrepared($sql, $vals)->rowCount()==1;
    }
287697
public function update() {
        $this->isNewRecord = false;
        if ($this->usesTimestamps()) {
            $this->updateTimestamps();
        }
        $this->invoke(self::BEFORE_UPDATE, [$this]);
        if (!$this->validate()) {
            return false;
        }
        $query = $this->getPrimaryKeyQuery();
        if (empty($query)) {
            $this->setError('pk', 'ERROR PK!');
            return false;
        }
        $data = $this->_getRealFields();
        if (empty($data)) {
            return true;
        }
        $row = $query
            ->update($data);
        if (!empty($row)) {
            $this->setOldAttribute();
        } else {
            $this->setError('data', 'Data is not change!');
        }
        $this->invoke(self::AFTER_UPDATE, [$this]);
        return $row;
    }
623179
function(attrs, callback) {
      var t = this;

      // Value is the only thing to set
      if (typeof attrs.value === 'undefined') {
        return callback({code:'NO_VALUE'});
      }

      // Set the model elements.  These cause change events to fire
      if (t.isModel) {
        t.value.set(attrs.value);
      }
      else {
        // Set the variable directly
        var jsonValue = JSON.stringify(attrs.value);
        t._evaluate(t.key + ' = ' + jsonValue);
        t.set('value', attrs.value);
      }
      return callback();
    }
636654
static public function update($id, array $attrs)
    {
        if (is_array($id)) {
            foreach ($id as $k => $i) {
                static::update($i, $attrs[$k]);
            }
        } else {
            $object = static::find($id);
            $object->updateAttributes($attrs);
            return $object;
        }
    }
316454
public function updateOrCreate(array $attributes, array $updateAttributes)
    {
        $model = $this->get($attributes);
        if (null === $model) {
            $model = $this->getModel()->create();
            $model->setIsNewRecord(true);
        }

        $model->setAttributes($updateAttributes);
        if ($model->save()) {
            return $model;
        }

        return false;
    }
738735
public function update(string $index, array $attributes, array $toMany): int
    {
        $updated        = 0;
        $pkName         = $this->getModelSchemas()->getPrimaryKey($this->getModelClass());
        $filters        = [
            $pkName => [
                FilterParameterInterface::OPERATION_EQUALS => [$index],
            ],
        ];
        $allowedChanges = $this->filterAttributesOnUpdate($attributes);
        $saveMain       = $this
            ->createBuilder($this->getModelClass())
            ->updateModels($allowedChanges)
            ->addFiltersWithAndToTable($filters);
        $saveMain       = $this->builderSaveResourceOnUpdate($saveMain);
        $saveMain->getSQL(); // prepare

        $this->clearBuilderParameters()->clearFetchParameters();

        $this->inTransaction(function () use ($saveMain, $toMany, $index, &$updated) {
            $updated = $saveMain->execute();

            $builderHook = Closure::fromCallable([$this, 'builderSaveRelationshipOnUpdate']);
            foreach ($toMany as $relationshipName => $secondaryIds) {
                $connection = $saveMain->getConnection();

                // clear existing
                $this->builderCleanRelationshipOnUpdate(
                    $relationshipName,
                    $this
                        ->createBuilderFromConnection($this->getConnection(), $this->getModelClass())
                        ->clearToManyRelationship($relationshipName, $index)
                )->execute();

                // add new ones
                $updated   += $this->addInToManyRelationship(
                    $connection,
                    $index,
                    $relationshipName,
                    $secondaryIds,
                    $builderHook
                );
            }
        });

        return (int)$updated;
    }
32888
final public function update(array $datas, $noApplyPrimaryKey = false) {
      if (is_array($datas) && count($datas)) {
         if (!is_array(@$datas[0])) {
            $datas = [$datas];
         }

         $this->connection();
         $this->columns();
         
         $this->last_sql = [];
         $this->placeholder_data = [];

         $where = $this->where;
         $whereTemp = str_replace('WHERE', '', $this->where);

         $rowCount = [];
         foreach ($datas as $data) {
            $placeholder = [];
            $isID = NULL;
            foreach($this->columnsData as $column) {
               if(isset($data[$column])) {
                  if($this->primaryKey==$column && $noApplyPrimaryKey===false) {
                     $isID = $data[$column];
                  } 
                  else {
                     $placeholder[$column] = "{$column}=NULL";
                     if ( gettype($data[$column])==='boolean' )
                        $placeholder[$column] = $data[$column] ? "{$column}=TRUE" : "{$column}=FALSE";
                     elseif ( $data[$column]!=='' && $data[$column]!==NULL ) {
                        $placeholder[$column] = "{$column}=?";
                        $this->placeholder_data[] = $data[$column];
                     }
                  }
               }
            }


            if($isID!==NULL) {
               $this->where = '';
               $this->where( $this->primaryKey, '=', $isID );
               if (trim($whereTemp)) {
                  $where = $this->where .' AND '. $whereTemp;
               }
               else {
                  $where = $this->where;
               }
            }

            $schema = '';
            if($this->driver=='pgsql' && $this->schema) {
               if (!preg_match('/\./', $this->table)) {
                  $schema = $this->schema ? $this->schema.'.' : '';	
               }
            }

            $placeholders = implode(",", $placeholder);
            $this->last_sql[] = $this->sql = "UPDATE {$schema}{$this->table} SET {$placeholders} {$where}";

            // $this->fetch(false);
            $this->fetch();

            $rowCount[] = $this->rowCount;

            $this->reset();

            if ( $this->tableOrig!==null ) {
               $this->table = $this->tableOrig;
            }

            $error = $this->error();
            if($error['message']) return false;
         }
         if ( count( $rowCount )===1 ) {
            $this->rowCount = $rowCount[0];
         }
         else {
            $this->rowCount = $rowCount;
         }
         
         return true;
      }
      return false;
   }
1303481
public function setPrimaryKey($value)
    {
        $pk = static::primaryKey()[0];
        if ($this->getIsNewRecord() || $pk != '_id') {
            $this->$pk = $value;
        } else {
            throw new InvalidCallException('Changing the primaryKey of an already saved record is not allowed.');
        }
    }
591841
def update(self, **kwargs):
        
        self.validate(**kwargs)
        for attr, value in kwargs.items():
            setattr(self, attr, value)
        return self
870193
public static function _setValue ($pk, $name, $value, &$db = FALSE)
	{
		
		// Get database master for write

		if ($db === FALSE)
		{
			$db	=& self::_getDbMaster ();
		}
		
		if (!($db instanceof \PDO))
		{
			throw new Exception ('Invalid or no database resource set');
		}
		
		// Prepare query
		
		$query = $db->prepare ('
		UPDATE `' . static::$dbTable . '`
		SET ' . $name . ' = :val 
		WHERE ' . static::$pk . ' = :pk
		');
		
		// Bind values
		
		$query->bindValue (':val',	$value);
		$query->bindValue (':pk',	$pk);
		
		// Execute

		return $query->execute ();
		
	}
1181877
def update(attrs)
      old_attrs = @attributes.dup
      Model.no_change_tracking do
        assign_all_attributes(attrs, false)

        validate!.then do |errs|
          if errs && errs.present?
            # Revert wholesale
            @attributes = old_attrs
            Promise.new.resolve(errs)
          else
            # Persist
            persist_changes(nil)
          end
        end
      end
    end
1052179
public function updateAttributes($attrs)
    {
        if (array_key_exists(self::getPK(), $attrs)) {
            unset($attrs[self::getPK()]);
        }
        foreach ($attrs as $attr => $value) {
            $this->_data[$attr] = $value;
        }
        return $this->save();
    }
1322782
def update_attributes!(attributes)
      attributes.each { |attribute, value| write_attribute(attribute, value) }
      save!
    end
20219
def update_attributes(atts)
      atts.delete('_type')
      atts.each { |att, val| send(:"#{att}=", val) }
    end
824051
public function update(array $sets, $conditions = [])
    {
        if (count($sets)) {
            $primaryKey = isset($this->primaryKey) ? $this->primaryKey : 'id';

            if (empty($conditions)) {
                if (isset($sets[ $primaryKey ])) {
                    $conditions = [$primaryKey => $sets[ $primaryKey ]];
                }
            }

            if (method_exists($this, 'updateRecordSets')) {
                $this->updateRecordSets($sets);
            }

            if (method_exists($this, 'beforeUpdate')) {
                $sets = $this->beforeUpdate($sets);
            }

            if (method_exists($this, 'getRecordOrdering')) {
                if ($this->recordOrdering === true && empty($sets[ 'record_ordering' ])) {
                    $sets[ 'record_ordering' ] = $this->getRecordOrdering($this->table);
                }
            }

            if ($this->qb->table($this->table)->update($sets, $conditions)) {

                if (method_exists($this, 'afterUpdate')) {
                    return $this->afterUpdate();
                }

                return true;
            }
        }

        return false;
    }
627550
public function update(array $attributes = [], $id = null)
    {
        // This allows for update based on the primary key
        if ($id && $this->exists === false) {
            $this->setAttribute($this->getKeyName(), $id);
            $this->exists = true;
        }

        $this->syncOriginal();

        return $this->fill($attributes)->save();
    }
391562
def _update_record(attribute_names = self.attribute_names)
      attribute_names = attributes_for_update(attribute_names)

      if attribute_names.empty?
        affected_rows = 0
        @_trigger_update_callback = true
      else
        affected_rows = _update_row(attribute_names)
        @_trigger_update_callback = affected_rows == 1
      end

      yield(self) if block_given?

      affected_rows
    end