_update example

/** * Compiles an update query and returns the sql * * @return bool|string */
    public function getCompiledUpdate(bool $reset = true)
    {
        if ($this->validateUpdate() === false) {
            return false;
        }

        $sql = $this->_update($this->QBFrom[0]$this->QBSet);

        if ($reset === true) {
            $this->resetWrite();
        }

        return $this->compileFinalQuery($sql);
    }

    /** * Compiles an update string and runs the query. * * @param array|object|null $set * @param array|RawSql|string|null $where * * @throws DatabaseException */


        /** * Get expressions for a WHERE clause * based on the primary key value(s). */
        $where = $this->_getWhereQuery(false);

        /** * Run pre-UPDATE logic */
        $this->_update();

        /** * Compare the data to the modified fields array to discover * which columns have been changed. */
        $diffData = array_intersect_key($this->_data, $this->_modifiedFields);

        /** * Were any of the changed columns part of the primary key? */
        $pkDiffData = array_intersect_key($diffDataarray_flip((array)$this->_primary));

        
/** * Increments a numeric column by the specified value. * * @return mixed * * @throws DatabaseException */
    public function increment(string $column, int $value = 1)
    {
        $column = $this->db->protectIdentifiers($column);

        $sql = $this->_update($this->QBFrom[0][$column => "to_number({$column}, '9999999') + {$value}"]);

        if ($this->testMode) {
            $this->resetWrite();

            return $this->db->query($sql$this->binds, false);
        }

        return true;
    }

    /** * Decrements a numeric column by the specified value. * * @return mixed * * @throws DatabaseException */

    public function increment(string $column, int $value = 1)
    {
        $column = $this->db->protectIdentifiers($column);

        if ($this->castTextToInt) {
            $values = [$column => "CONVERT(VARCHAR(MAX),CONVERT(INT,CONVERT(VARCHAR(MAX), {$column})) + {$value})"];
        } else {
            $values = [$column => "{$column} + {$value}"];
        }

        $sql = $this->_update($this->QBFrom[0]$values);

        if ($this->testMode) {
            $this->resetWrite();

            return $this->db->query($sql$this->binds, false);
        }

        return true;
    }

    /** * Decrements a numeric column by the specified value. * * @return bool */
Home | Imprint | This part of the site doesn't use cookies.