protected function sqlUpdate(string $extraWhereClause): string
    {
        // get the conditions to alter the current record
        $conditions = $this->sqlWhereConditions($extraWhereClause);
        // if no conditions then log error and return false
        if (! count($conditions)) {
            throw new \LogicException('Recordset: The current record does not have any conditions to update');
        }
        // get the fields that have changed compared to originalValues
        $updates = [];
        foreach ($this->datafields as $fieldname => $field) {
            if (! array_key_exists($fieldname, $this->values)) {
                $this->values[$fieldname] = null;
            }
            if ($this->valueIsDifferent($this->originalValues[$fieldname], $this->values[$fieldname])) {
                $updates[] = $this->dbal->sqlFieldEscape($fieldname) . ' = '
                    . $this->dbal->sqlQuote($this->values[$fieldname], $field['commontype'], true);
            }
        }
        // if nothing to update, log error and return empty string
        if (! count($updates)) {
            return '';
        }
        // return the update statement
        return 'UPDATE'
            . ' ' . $this->dbal->sqlTableEscape($this->entity)
            . ' SET ' . implode(', ', $updates)
            . ' WHERE ' . implode(' AND ', $conditions)
            . ';';
    }
protected function sqlUpdate(string $extraWhereClause): string
    {
        // get the conditions to alter the current record
        $conditions = $this->sqlWhereConditions($extraWhereClause);
        // if no conditions then log error and return false
        if (! count($conditions)) {
            throw new \LogicException('Recordset: The current record does not have any conditions to update');
        }
        // get the fields that have changed compared to originalValues
        $updates = [];
        foreach ($this->datafields as $fieldname => $field) {
            if (! array_key_exists($fieldname, $this->values)) {
                $this->values[$fieldname] = null;
            }
            if ($this->valueIsDifferent($this->originalValues[$fieldname], $this->values[$fieldname])) {
                $updates[] = $this->dbal->sqlFieldEscape($fieldname) . ' = '
                    . $this->dbal->sqlQuote($this->values[$fieldname], $field['commontype'], true);
            }
        }
        // if nothing to update, log error and return empty string
        if (! count($updates)) {
            return '';
        }
        // return the update statement
        return 'UPDATE'
            . ' ' . $this->dbal->sqlTableEscape($this->entity)
            . ' SET ' . implode(', ', $updates)
            . ' WHERE ' . implode(' AND ', $conditions)
            . ';';
    }
protected function sqlUpdate ( string $ extraWhereClause ) : string { // get the conditions to alter the current record $ conditions = $ this -> sqlWhereConditions ( $ extraWhereClause ) ; // if no conditions then log error and return false if ( ! count ( $ conditions ) ) { throw new \ LogicException ( 'Recordset: The current record does not have any conditions to update' ) ; } // get the fields that have changed compared to originalValues $ updates = [ ] ; foreach ( $ this -> datafields as $ fieldname => $ field ) { if ( ! array_key_exists ( $ fieldname , $ this -> values ) ) { $ this -> values [ $ fieldname ] = null ; } if ( $ this -> valueIsDifferent ( $ this -> originalValues [ $ fieldname ] , $ this -> values [ $ fieldname ] ) ) { $ updates [ ] = $ this -> dbal -> sqlFieldEscape ( $ fieldname ) . ' = ' . $ this -> dbal -> sqlQuote ( $ this -> values [ $ fieldname ] , $ field [ 'commontype' ] , true ) ; } } // if nothing to update, log error and return empty string if ( ! count ( $ updates ) ) { return '' ; } // return the update statement return 'UPDATE' . ' ' . $ this -> dbal -> sqlTableEscape ( $ this -> entity ) . ' SET ' . implode ( ', ' , $ updates ) . ' WHERE ' . implode ( ' AND ' , $ conditions ) . ';' ; }
Create the sql statement for UPDATE
If nothing to update then will return an empty string
@param string $extraWhereClause
@return string
Create the sql statement for UPDATE If nothing to update then will return an empty string