final public function update($extraWhereClause = '')
    {
        // check the current mode is on ADDNEW or EDIT
        if (self::RSMODE_CONNECTED_ADDNEW !== $this->mode && self::RSMODE_CONNECTED_EDIT !== $this->mode) {
            throw new \LogicException(
                "Recordset: The recordset is not on edit or addnew mode [current: {$this->mode}]"
            );
        }
        // check the entity is not empty
        if ('' === $this->entity) {
            throw new \LogicException('Recordset: The recordset does not have a valid unique entity');
        }
        $sql = '';
        if (self::RSMODE_CONNECTED_ADDNEW == $this->mode) {
            $sql = $this->sqlInsert();
        }
        if (self::RSMODE_CONNECTED_EDIT == $this->mode) {
            if ('' === $sql = $this->sqlUpdate($extraWhereClause)) {
                return 0;
            }
        }
        $altered = $this->dbal->execute($sql);
        if (0 === $altered) {
            $diffs = [];
            if (is_array($this->originalValues)) {
                foreach ($this->originalValues as $name => $value) {
                    if (! $this->valueIsDifferent($value, $this->values[$name])) {
                        continue;
                    }
                    $diffs[] = $name;
                }
            }
            $this->logger->warning(print_r([
                'message' => "Recordset: The statement $sql return zero affected rows but the values are different",
                'entity' => $this->entity,
                'extraWhereClause' => $extraWhereClause,
                'original' => $this->originalValues,
                'current' => $this->values,
                'diffs' => $diffs,
            ], true));
        }
        return $altered;
    }
final public function update($extraWhereClause = '')
    {
        // check the current mode is on ADDNEW or EDIT
        if (self::RSMODE_CONNECTED_ADDNEW !== $this->mode && self::RSMODE_CONNECTED_EDIT !== $this->mode) {
            throw new \LogicException(
                "Recordset: The recordset is not on edit or addnew mode [current: {$this->mode}]"
            );
        }
        // check the entity is not empty
        if ('' === $this->entity) {
            throw new \LogicException('Recordset: The recordset does not have a valid unique entity');
        }
        $sql = '';
        if (self::RSMODE_CONNECTED_ADDNEW == $this->mode) {
            $sql = $this->sqlInsert();
        }
        if (self::RSMODE_CONNECTED_EDIT == $this->mode) {
            if ('' === $sql = $this->sqlUpdate($extraWhereClause)) {
                return 0;
            }
        }
        $altered = $this->dbal->execute($sql);
        if (0 === $altered) {
            $diffs = [];
            if (is_array($this->originalValues)) {
                foreach ($this->originalValues as $name => $value) {
                    if (! $this->valueIsDifferent($value, $this->values[$name])) {
                        continue;
                    }
                    $diffs[] = $name;
                }
            }
            $this->logger->warning(print_r([
                'message' => "Recordset: The statement $sql return zero affected rows but the values are different",
                'entity' => $this->entity,
                'extraWhereClause' => $extraWhereClause,
                'original' => $this->originalValues,
                'current' => $this->values,
                'diffs' => $diffs,
            ], true));
        }
        return $altered;
    }
final public function update ( $ extraWhereClause = '' ) { // check the current mode is on ADDNEW or EDIT if ( self :: RSMODE_CONNECTED_ADDNEW !== $ this -> mode && self :: RSMODE_CONNECTED_EDIT !== $ this -> mode ) { throw new \ LogicException ( "Recordset: The recordset is not on edit or addnew mode [current: {$this->mode}]" ) ; } // check the entity is not empty if ( '' === $ this -> entity ) { throw new \ LogicException ( 'Recordset: The recordset does not have a valid unique entity' ) ; } $ sql = '' ; if ( self :: RSMODE_CONNECTED_ADDNEW == $ this -> mode ) { $ sql = $ this -> sqlInsert ( ) ; } if ( self :: RSMODE_CONNECTED_EDIT == $ this -> mode ) { if ( '' === $ sql = $ this -> sqlUpdate ( $ extraWhereClause ) ) { return 0 ; } } $ altered = $ this -> dbal -> execute ( $ sql ) ; if ( 0 === $ altered ) { $ diffs = [ ] ; if ( is_array ( $ this -> originalValues ) ) { foreach ( $ this -> originalValues as $ name => $ value ) { if ( ! $ this -> valueIsDifferent ( $ value , $ this -> values [ $ name ] ) ) { continue ; } $ diffs [ ] = $ name ; } } $ this -> logger -> warning ( print_r ( [ 'message' => "Recordset: The statement $sql return zero affected rows but the values are different" , 'entity' => $ this -> entity , 'extraWhereClause' => $ extraWhereClause , 'original' => $ this -> originalValues , 'current' => $ this -> values , 'diffs' => $ diffs , ] , true ) ) ; } return $ altered ; }
Build and execute an SQL UPDATE or INSERT sentence
Return how many rows where altered, if an update does not change any value then it return zero
Return false in case of error execution
@param string $extraWhereClause where clause to be append into sql on UPDATE (not insert)
@return int|false
Build and execute an SQL UPDATE or INSERT sentence Return how many rows where altered if an update does not change any value then it return zero Return false in case of error execution