src/Koldy/Db/Query/Update.php
public function getQuery(): Query
    {
        if (count($this->what) == 0) {
            throw new Exception('Can not build UPDATE query, SET is not defined');
        }

        if ($this->table === null) {
            throw new Exception('Can not build UPDATE query when table name is not set');
        }

        $sql = "UPDATE {$this->table}\nSET\n";

        foreach ($this->what as $field => $value) {
            $sql .= "\t{$field} = ";
            if ($value instanceof Expr) {
                $sql .= "{$value},\n";
            } else {
                //$key = $this->bind($field, $value);
	            $key = $this->getBindings()->makeAndSet($field, $value);
                $sql .= ":{$key},\n";
            }
        }

        $sql = substr($sql, 0, -2);

        if ($this->hasWhere()) {
            $sql .= "\nWHERE{$this->getWhereSql()}";
        }

        if (count($this->orderBy) > 0) {
            $sql .= "\nORDER BY";
            foreach ($this->orderBy as $r) {
                $sql .= "\n\t{$r['field']} {$r['direction']},";
            }
            $sql = substr($sql, 0, -1);
        }

        return new Query($sql, $this->getBindings(), $this->getAdapterConnection());
    }
public function getQuery(): Query
    {
        if (count($this->what) == 0) {
            throw new Exception('Can not build UPDATE query, SET is not defined');
        }

        if ($this->table === null) {
            throw new Exception('Can not build UPDATE query when table name is not set');
        }

        $sql = "UPDATE {$this->table}\nSET\n";

        foreach ($this->what as $field => $value) {
            $sql .= "\t{$field} = ";
            if ($value instanceof Expr) {
                $sql .= "{$value},\n";
            } else {
                //$key = $this->bind($field, $value);
	            $key = $this->getBindings()->makeAndSet($field, $value);
                $sql .= ":{$key},\n";
            }
        }

        $sql = substr($sql, 0, -2);

        if ($this->hasWhere()) {
            $sql .= "\nWHERE{$this->getWhereSql()}";
        }

        if (count($this->orderBy) > 0) {
            $sql .= "\nORDER BY";
            foreach ($this->orderBy as $r) {
                $sql .= "\n\t{$r['field']} {$r['direction']},";
            }
            $sql = substr($sql, 0, -1);
        }

        return new Query($sql, $this->getBindings(), $this->getAdapterConnection());
    }
public function getQuery ( ) : Query { if ( count ( $ this -> what ) == 0 ) { throw new Exception ( 'Can not build UPDATE query, SET is not defined' ) ; } if ( $ this -> table === null ) { throw new Exception ( 'Can not build UPDATE query when table name is not set' ) ; } $ sql = "UPDATE {$this->table}\nSET\n" ; foreach ( $ this -> what as $ field => $ value ) { $ sql .= "\t{$field} = " ; if ( $ value instanceof Expr ) { $ sql .= "{$value},\n" ; } else { //$key = $this->bind($field, $value); $ key = $ this -> getBindings ( ) -> makeAndSet ( $ field , $ value ) ; $ sql .= ":{$key},\n" ; } } $ sql = substr ( $ sql , 0 , - 2 ) ; if ( $ this -> hasWhere ( ) ) { $ sql .= "\nWHERE{$this->getWhereSql()}" ; } if ( count ( $ this -> orderBy ) > 0 ) { $ sql .= "\nORDER BY" ; foreach ( $ this -> orderBy as $ r ) { $ sql .= "\n\t{$r['field']} {$r['direction']}," ; } $ sql = substr ( $ sql , 0 , - 1 ) ; } return new Query ( $ sql , $ this -> getBindings ( ) , $ this -> getAdapterConnection ( ) ) ; }
Get the query
@return Query
@throws Exception
@throws \Koldy\Db\Exception
Get the query