Updates data on a table using custom SQL syntax

@param string       $table
@param array        $fieldValues
@param string|array $conditions
@param array        $bind

@return    int
@throws \ManaPHP\Db\Exception
197807
public function update($table, $fieldValues, $conditions, $bind = [])
    {
        if (!$fieldValues) {
            throw new InvalidArgumentException(['Unable to update :table table without data', 'table' => $table]);
        }

        if (is_string($conditions)) {
            $conditions = [$conditions];
        }

        $wheres = [];

        /** @noinspection ForeachSourceInspection */
        foreach ($conditions as $k => $v) {
            if (is_int($k)) {
                $wheres[] = stripos($v, ' or ') ? "($v)" : $v;
            } else {
                $wheres[] = "[$k]=:$k";
                $bind[$k] = $v;
            }
        }

        $setFields = [];
        foreach ($fieldValues as $k => $v) {
            if (is_int($k)) {
                $setFields[] = $v;
            } elseif ($v instanceof AssignmentInterface) {
                $v->setFieldName($k);
                $setFields[] = $v->getSql();
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $bind = array_merge($bind, $v->getBind());
            } else {
                $setFields[] = "[$k]=:$k";
                $bind[$k] = $v;
            }
        }

        $sql = 'UPDATE ' . $this->_escapeIdentifier($table) . ' SET ' . implode(',', $setFields) . ' WHERE ' . implode(' AND ', $wheres);

        return $this->_execute('update', $sql, $bind);
    }
440069
protected function _prepareQueryConditions(&$conditions) {
		if (empty($conditions) || !is_array($conditions)) {
			return;
		}

		$bindFields = $this->_getListFieldsUpdateQueryConditions();
		$newConditions = [];
		foreach ($conditions as $field => &$value) {
			if (ctype_digit((string)$field)) {
				$field = $value;
			}

			if (in_array($field, ['AND', 'OR', 'NOT']) && is_array($value)) {
				$this->_prepareQueryConditions($value);
				continue;
			}

			if (!is_string($field)) {
				continue;
			}

			foreach ($bindFields as $bindField => $bindFieldInfo) {
				$fieldName = $field;
				if (strpos($fieldName, ' ') !== false) {
					$fieldName = explode(' ', $fieldName, 2);
					$fieldName = array_shift($fieldName);
				}
				if ($fieldName !== $this->alias . '.' . $bindField) {
					continue;
				}

				unset($conditions[$field]);
				$field = str_replace($this->alias . '.' . $bindField, $bindFieldInfo['replace'], $field);
				if (!isset($bindFieldInfo['subQuery'])) {
					$newConditions[$field] = $value;
					continue;
				}

				$conditionsSubQuery = [$field => $value];
				$db = $this->getDataSource();
				$subQuery = $db->buildStatement(
					[
						'limit' => null,
						'offset' => null,
						'joins' => [],
						'conditions' => $conditionsSubQuery,
						'order' => null,
						'group' => null
					] + $bindFieldInfo['subQuery'],
					$this
				);
				$subQuery = 'Employee.id IN (' . $subQuery . ') ';
				$subQueryExpression = $db->expression($subQuery);

				$newConditions[] = $subQueryExpression;
			}
		}
		$conditions = array_merge($conditions, $newConditions);
	}
1296591
public static function insert(string $table = null, array $rowValues = null): Query\Insert
    {
        return static::getAdapter()->insert($table, $rowValues);
    }
213590
public function update(array $values)
	{
		$bindings = array_values(array_merge($values, $this->bindings));

		$sql = $this->grammar->compileUpdate($this, $values);

		return $this->connection->update($sql, $this->cleanBindings($bindings));
	}
42231
public static function update( $table, $values = array(), $handler = null )
	{
		return Query_Update::create( $table, $handler )->set( $values );
	}
522192
public function update($primaryKeyValue, $fieldsValues)
    {
        $this->connectToDB();
        $this->queryBuilder->table($this->table());
        $this->primaryKeyWhere($primaryKeyValue);
        $this->queryBuilder->update($fieldsValues);
        return $primaryKeyValue;
    }
862504
public function update($fieldValues)
    {
        $filters = [];
        foreach ($this->_filters as $filter) {
            $key = key($filter);
            $value = current($filter);
            if (isset($filters[$key]) || count($filter) !== 1) {
                $filters = ['$and' => $this->_filters];
                break;
            }
            $filters[$key] = $value;
        }

        $expressions = [];
        foreach ($fieldValues as $field => $value) {
            if ($value instanceof ExpressionInterface) {
                $expressions[$field] = $value;
                unset($fieldValues[$field]);
            }
        }

        if ($expressions) {
            if ($fieldValues) {
                $fieldValues = ['$set' => $fieldValues];
            }

            foreach ($expressions as $field => $value) {
                if ($value instanceof Increment) {
                    $fieldValues['$inc'][$field] = $value->step;
                }
            }
        }

        return $this->getConnection()->update($this->getSource(), $fieldValues, $filters);
    }
148297
public function delete($table, $conditions, $bind = [])
    {
        if (is_string($conditions)) {
            $conditions = [$conditions];
        }

        $wheres = [];
        /** @noinspection ForeachSourceInspection */
        foreach ($conditions as $k => $v) {
            if (is_int($k)) {
                $wheres[] = stripos($v, ' or ') ? "($v)" : $v;
            } else {
                $wheres[] = "[$k]=:$k";
                $bind[$k] = $v;
            }
        }

        $sql = 'DELETE' . ' FROM ' . $this->_escapeIdentifier($table) . ' WHERE ' . implode(' AND ', $wheres);
        return $this->_execute('delete', $sql, $bind);
    }
1208941
public function delete($fieldsValues)
    {
        $this->connectToDB();
        $this->queryBuilder->table($this->table());
        $this->queryBuilder->delete($fieldsValues);
    }
1361925
public function bindValues($statement, $bindings)
    {
        foreach ($bindings as $key => $value) {
            $statement->bindParam($key, $bindings[$key]);
        }
    }
1340962
function update( $table, $data, $where = array(), $params = array() ) {

        if ( empty( $data ) ) return;

        $set = array();

        foreach ( $data as $column => $value ) {

            $set[] = $this->quoteIdentifier( $column ) . " = " . $this->quote( $value );

        }

        if ( !is_array( $where ) ) $where = array( $where );
        if ( !is_array( $params ) ) $params = array_slice( func_get_args(), 3 );

        $table = $this->rewriteTable( $table );
        $query = "UPDATE " . $this->quoteIdentifier( $table );
        $query .= " SET " . implode( ", ", $set );
        $query .= $this->getSuffix( $where );

        $this->onQuery( $query, $params );

        $statement = $this->prepare( $query );
        $statement->execute( $params );

        return $statement;

    }
772541
public function update($table, array $values = null)
    {
        $this->table($table);
        if( !empty($values) ) {
            $this->values($values);
        }
        return $this;
    }
296495
protected function updateConditions(array $conditions, $table, $alias) {
		$res = [];

		foreach($conditions as $k=>$v) {
			if(is_array($v))
				$v = $this->updateConditions($v, $table, $alias);
			else
				$v = preg_replace('/(?<![\.a-zA-Z0-9-_`\(\)])'.$table.'\./', $alias.'.', $v);
			$k = preg_replace('/(?<![\.a-zA-Z0-9-_`\(\)])'.$table.'\./', $alias.'.', $k);
			$res[$k] = $v;
		}

		return $res;
	}
1088277
public function insert($table, array $bind)
    {
        $this->_connect();
        $newbind = array();
        if (is_array($bind)) {
            foreach ($bind as $name => $value) {
                if($value !== null) {
                    $newbind[$name] = $value;
                }
            }
        }

        return parent::insert($table, $newbind);
    }
1253117
public function prepareUpdate($table, array $values) {

        // Initialize the SET.
        $set = [];
        foreach ($values as $k => $v) {
            $set[] = "`" . $k . "` = " . $v;
        }

        // Initialize the query.
        $query = [];

        $query[] = "UPDATE ";
        $query[] = $table;
        $query[] = " SET ";
        $query[] = implode(", ", $set);

        // Return the query.
        return implode("", $query);
    }
1314838
public function min($table, $field, $conditions = false)
    {
        return $this->executeAggregate('MIN', $table, $field, $conditions);
    }
1351345
public function insert(string $table = null, array $rowValues = null): Query\Insert
    {
        return new Query\Insert($table, $rowValues, $this->getConfigKey());
    }