Build field list to update (only field with different value from db)

@param  DataAbstract $data
@param  bool         $forceCheck If force check (do not force for insert query)
@return string
357636
public function getQueryFieldsSet(DataAbstract $data, $forceCheck = true)
    {
        //~ List of fields to update.
        $queryFields = array();

        //~ Check for updated fields.
        foreach ($this->fields as $field) {

            //~ Skip fields that are not updated
            if ($forceCheck && !$this->isDataUpdated($data, $field)) {
                continue;
            }

            $queryFields[] = $field . ' = :' . strtolower($field);

            $this->binds[':' . strtolower($field)] = $this->getDataValue($data, $field);
        }

        $set = '';
        if (!empty($queryFields)) {
            $set = 'SET ' . implode(', ', $queryFields);
        }

        return $set;
    }
70672
protected function _compareData($dataToCheck, $key, $originalData, $comparator)
    {
        if (is_callable($dataToCheck)) {
            return call_user_func_array($dataToCheck, [$key, $originalData, $this]);
        }

        return $this->_comparator($originalData, $dataToCheck, $comparator);
    }
329321
public function getData ($forceRefresh = false) {
        if ($forceRefresh || $this->_data === null) {
            $this->_data = $this->getConnection ()->getSlave ()->zrange ($this->name , 0 , -1 , true);
        }
        return $this->_data;
    }
1185502
public function update($id, array $data)
    {
        $this->validateId($id);

        $entity = $this->getById($id);
        $form   = $this->getEditForm();

        $form->bind($entity);
        $form->setData($data);

        if (!$valid = $form->isValid()) {
            return false;
        }

        $this->updateFromNode($entity);

        $this->getMapper()->save($entity);

        return $entity;
    }
257082
public function getData ($forceRefresh = false) {
        if ($forceRefresh || $this->_data === null) {
            $this->_data = $this->getConnection ()->getSlave ()->smembers ($this->name);
        }
        return $this->_data;
    }
1129765
public function buildUpdateQuery($table, $data, $where, $limit)
    {
        $sql = "UPDATE " . $this->quoteSpecialName($table) . " SET ";

        $values = '';

        foreach ($data as $key => $value) {
            if (!empty($values)) $values .= ', ';
            $values .= $this->quoteSpecialName($key) . ' = ' . $this->escapeItem($value);
        }

        $sql .= $values . ' WHERE ' . $where;

        if (!empty($limit)) {
            $sql .= ' LIMIT ' . $limit;
        }

        $sql .= ';';

        return $sql;
    }
1369472
public function updateByField($fieldName, $fieldValue, array $data)
    {
        $this->manager->postPendingQuery(
            new PendingQuery(
                $this->entity,
                PendingQuery::TYPE_UPDATE,
                $this->getUpdateQuery($data)
                     ->where(
                         $this->equalsExpression($fieldName, $fieldValue)
                     ),
                $this->parameters
            )
        );
    }
470746
public function getValuesChangeset($forceRecompute = false)
    {
        if (null === $this->valuesChangeset || $forceRecompute) {
            $this->computeValuesChangeset();
        }

        return $this->valuesChangeset;
    }
1146968
public function verifyData($data, $excluded_fields=null, $strict_mode=false)
    {
        $model = static::getQueryModel();
        
        if (!isset($model['fields']) || !isset($model['primary_key'])) {
            return ErrorInfo::error('table has not any fields.');
        }
        
        $errinfo = [];
        if ($data) {
            if (isset($data[0]) && is_array($data[0])) {
                foreach ($data as $k => $v) {
                    $res = static::verifyData($v);
                    if ($res['errcode']) {
                        return $res;
                    }
                }
            } else {
                foreach ($data as $k => $v) {
                    if (isset($model['fields'][$k])) {
                        $field = $model['fields'][$k];
                        
                        $v = FieldInputHandler::formatValue($model['fields'][$k], $v);    // don't modify $data
                        
                        $field_title = isset($model['fields'][$k]['field_title']) ? $model['fields'][$k]['field_title'] : $model['fields'][$k]['field_name'];
                        
                        if (empty($excluded_fields) || !in_array($k, $excluded_fields)) {
                            
                            // check is_nullable and min_length
                            $is_nullable = isset($model['fields'][$k]['is_nullable']) && $model['fields'][$k]['is_nullable'] == 0 ? false : true;
                            $min_length = isset($model['fields'][$k]['min_length']) ? intval($model['fields'][$k]['min_length']) : 0;
                            $min_length = (!$is_nullable) ? $min_length : 0;
                            $is_primary = isset($field['is_primary']) && $field['is_primary'] ? : 0;
                            if (!$is_primary && $min_length && strlen($v) < $min_length) {
                                $errinfo['errcode'] = -201;
                                $errinfo['errmsg'] = $field_title . '不允许为空';    //'至少' . $min_length . '位';
                                break;
                            }
                            
                            // check code type
                            if (isset($model['fields'][$k]['base_type'])) {
                                $base_type = $model['fields'][$k]['base_type'];
                                if (in_array($base_type, ['name', 'code']) && strlen($v) > 0 && !DataHelper::verify_code($v)) {
                                    $errinfo['errcode']  = -202;
                                    $errinfo['errmsg']   = $field_title . '只能取数字字母下划线';
                                    break;
                                }
                            }
                        }
                        
                        // check data_length
                        if (!empty($v) && !empty($model['fields'][$k]['data_length']) && (strlen($v) > $model['fields'][$k]['data_length']) ) {
                            $errinfo['errcode'] = -221;
                            $errinfo['errmsg'] = $field_title . '最大长度为: ' . $model['fields'][$k]['data_length'];
                            break;
                        }
                    } elseif ($strict_mode) {
                        $errinfo['errcode'] = -1;
                        $errinfo['errmsg'] = '数据不正确，不存在字段' . $k;
                        break;
                    }
                }
            }
        }
        
        return ErrorInfo::instance($errinfo);
    }
80414
protected function getForm(FieldTypeInterface $field, $force = false)
    {
        $datasource = $field->getDataSource();

        if ($datasource === null) {
            return null;
        }

        if (!$field->getOption('form_filter')) {
            return null;
        }

        $field_oid = spl_object_hash($field);

        if (isset($this->forms[$field_oid]) && !$force) {
            return $this->forms[$field_oid];
        }

        $options = $field->getOption('form_options');
        $options = array_merge($options, ['required' => false, 'auto_initialize' => false]);

        $form = $this->formFactory->createNamed(
            $datasource->getName(),
            $this->isFqcnFormTypePossible()
                ? 'Symfony\Component\Form\Extension\Core\Type\CollectionType'
                : 'collection',
            null,
            ['csrf_protection' => false]
        );
        $fieldsForm = $this->formFactory->createNamed(
            DataSourceInterface::PARAMETER_FIELDS,
            $this->isFqcnFormTypePossible()
                ? 'Symfony\Component\Form\Extension\Core\Type\FormType'
                : 'form',
            null,
            ['auto_initialize' => false]
        );

        switch ($field->getComparison()) {
            case 'between':
                $this->buildBetweenComparisonForm($fieldsForm, $field, $options);
                break;

            case 'isNull':
                $this->buildIsNullComparisonForm($fieldsForm, $field, $options);
                break;

            default:

                switch ($field->getType()) {
                    case 'boolean':
                        $this->buildBooleanForm($fieldsForm, $field, $options);
                        break;

                    default:
                        $fieldsForm->add($field->getName(), $this->getFieldFormType($field), $options);
                }
        }

        $form->add($fieldsForm);
        $this->forms[$field_oid] = $form;

        return $this->forms[$field_oid];
    }
465117
public static function encode($data, $forceObject = false)
	{
		return @json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | ($forceObject ? JSON_FORCE_OBJECT : 0));
	}
1013223
protected function updateListElementBody($listElement, $data)
    {
        $listElement = $listElement;

        if (is_string($listElement)) {
            return $data;
        }

        if (is_array($listElement)) {
            return array_merge((array) $listElement, (array) $data);
        }

        return (object) array_merge((array) $listElement, (array) $data);
    }
1212593
public function bulk_insert( $table, $fields, $data_list ) {
		if ( ! isset( $this->table_defines[ $table ] ) || empty( $fields ) || empty( $data_list ) ) {
			return false;
		}
		$columns     = $this->table_defines[ $table ]['columns'];
		$table       = $this->get_table( $table );
		$sql         = "INSERT INTO {$table} ";
		$names       = [];
		$placeholder = [];
		$time        = $this->set_update_params( [], true, true, false );
		foreach ( $fields as $field ) {
			if ( ! isset( $columns[ $field ] ) ) {
				return false;
			}
			$names[]       = $columns[ $field ]['name'];
			$placeholder[] = $columns[ $field ]['format'];
		}
		foreach ( $time as $k => $v ) {
			$names[]       = $columns[ $k ]['name'];
			$placeholder[] = $columns[ $k ]['format'];
		}
		$placeholder = '(' . implode( ', ', $placeholder ) . ')';
		$sql         .= '(' . implode( ', ', $names ) . ') VALUES ';

		$values = [];
		foreach ( $data_list as $data ) {
			$data += $time;
			if ( count( $names ) != count( $data ) ) {
				return false;
			}

			$values[] = $this->prepare( $placeholder, $data );
		}
		$sql .= implode( ', ', $values );

		return $this->query( $sql );
	}
385868
public function writeAMFData($data,$forcetype=null) {

           if (is_null($forcetype)) {
               // Autodetecting data type
               $type=false;
               if (!$type && is_null($data))    $type = SabreAMF_AMF3_Const::DT_NULL;
               if (!$type && is_bool($data))    {
                    $type = $data?SabreAMF_AMF3_Const::DT_BOOL_TRUE:SabreAMF_AMF3_Const::DT_BOOL_FALSE;
                }
                if (!$type && is_int($data)) {
                    // We essentially only got 29 bits for integers
                    if ($data > 0xFFFFFFF || $data < -268435456) {
                        $type = SabreAMF_AMF3_Const::DT_NUMBER;
                    } else {
                        $type = SabreAMF_AMF3_Const::DT_INTEGER;
                    }
                }
                if (!$type && is_float($data))   $type = SabreAMF_AMF3_Const::DT_NUMBER;
                if (!$type && is_int($data))     $type = SabreAMF_AMF3_Const::DT_INTEGER;
                if (!$type && is_string($data))  $type = SabreAMF_AMF3_Const::DT_STRING;
                if (!$type && is_array($data))   $type = SabreAMF_AMF3_Const::DT_ARRAY; 
                if (!$type && is_object($data)) {

                    if ($data instanceof SabreAMF_ByteArray) 
                        $type = SabreAMF_AMF3_Const::DT_BYTEARRAY;
                    elseif ($data instanceof DateTime) 
                        $type = SabreAMF_AMF3_Const::DT_DATE;
                    else 
                        $type = SabreAMF_AMF3_Const::DT_OBJECT;
                    

                }
                if ($type===false) {
                    throw new Exception('Unhandled data-type: ' . gettype($data));
                    return null;
                }
                if ($type == SabreAMF_AMF3_Const::DT_INTEGER && ($data > 268435455 || $data < -268435456)) {
                    $type = SabreAMF_AMF3_Const::DT_NUMBER;
                }
           } else $type = $forcetype;

           $this->stream->writeByte($type);

           switch ($type) {

                case SabreAMF_AMF3_Const::DT_NULL        : break;
                case SabreAMF_AMF3_Const::DT_BOOL_FALSE  : break;
                case SabreAMF_AMF3_Const::DT_BOOL_TRUE   : break;
                case SabreAMF_AMF3_Const::DT_INTEGER     : $this->writeInt($data); break;
                case SabreAMF_AMF3_Const::DT_NUMBER      : $this->stream->writeDouble($data); break;
                case SabreAMF_AMF3_Const::DT_STRING      : $this->writeString($data); break;
                case SabreAMF_AMF3_Const::DT_DATE        : $this->writeDate($data); break;
                case SabreAMF_AMF3_Const::DT_ARRAY       : $this->writeArray($data); break;
                case SabreAMF_AMF3_Const::DT_OBJECT      : $this->writeObject($data); break; 
                case SabreAMF_AMF3_Const::DT_BYTEARRAY   : $this->writeByteArray($data); break;
                default                   :  throw new Exception('Unsupported type: ' . gettype($data)); return null; 
 
           }

        }
491903
protected function _dataPreparation($key, $data, array $rulesList)
    {
        foreach ($rulesList as $ruleKey => $function) {

            switch (true) {
                case is_null($key):
                    $data = $this->_prepareWholeData($ruleKey, $data, $function);
                    break;

                case preg_match($ruleKey, $key) && !is_null($key):
                    $data = $this->_callUserFunction($function, $key, $data, null);
                    break;

                default:
                    break;
            }
        }

        return $data;
    }
1091080
public function update( $data = array(), $stripTags = TRUE ){
		if( !( is_array( $data ) && $data ) )
			throw new \InvalidArgumentException( 'Data for update must be an array and have atleast 1 pair' );
		$this->validateFocus();
		$has	= $this->get( FALSE );
		if( !$has )
			throw new \InvalidArgumentException( 'No data sets focused for update' );
		$updates	= array();
		foreach( $this->columns as $column ){
			if( !array_key_exists($column, $data) )
				continue;
			$value	= $data[$column];
			if( $stripTags && $value !== NULL )
				$value	= strip_tags( $value );
			$value	= $this->secureValue( $value );
			$updates[] = '`'.$column.'`='.$value;
		}
		if( sizeof( $updates ) ){
			$updates	= implode( ', ', $updates );
			$query	= 'UPDATE '.$this->getTableName().' SET '.$updates.' WHERE '.$this->getConditionQuery( array() );
			$result	= $this->dbc->exec( $query );
			return $result;
		}
	}
194620
protected function getCache(DataAbstract $data)
    {
        if (!$this->isCacheEnabled) {
            return false;
        }

        return $this->cache->get($data->getCacheKey());
    }