保存指定的属性（字段）值
@param string $fields 字段名列表，多个字段以逗号隔开
@return boolean
@throws \wf\model\Exception
498523
public function saveFields($fields)
    {
        $this->mustBeDataModel();

        $fieldArr = explode(',', str_replace(' ', '', $fields));
        $update = [];

        foreach ($fieldArr as $field) {
            $update[$field] = $this->$field;
        }

        $arg = [
            $this->table,
            $this->fieldSet($update),
            \wf\db\QueryBuilder::whereArr($this->pkvAsWhere())
        ];
        $exe = $this->getDb()->exec("UPDATE %t SET %x WHERE %x", $arg);

        if (false === $exe) {
            throw new \wf\model\Exception($this->getDb()->getLastErr());
        }

        return $exe;
    }
318016
protected function checkFields($fields='') {
        if(empty($fields) || '*'==$fields ) {
            // 获取全部聚合字段
            $fields =   $this->fields;
        }
        if(!is_array($fields))
            $fields =   explode(',',$fields);

        // 解析成聚合字段
        $array =  array();
        foreach ($fields as $field){
            if(array_key_exists($field,$this->mapFields)){
                // 需要处理映射字段
                $array[]  =   $this->mapFields[$field].' AS '.$field;
            }else{
                $array[]  =     $field;
            }
        }
        $fields = implode(',',$array);
        return $fields;
    }
171976
public function count($field = '*') {
        $this->statementContext->setFields("COUNT({$field}) AS __COUNT__");
        $row = $this->findOne();

        //SQL执行发生错误
        if ($row === false) {
            return false;
        }

        return $row['__COUNT__'];
    }
428052
public function fields($fields)
    {
        if (!is_array($fields)) {
            $fields = func_get_args();
        }

        $this->fields = array_merge($this->fields, $fields);

        return $this;
    }
1310411
protected function assignFields($fields)
    {
        foreach ($fields as $field) {
            if (!$field instanceof FieldInterface) {
                throw new ModelException(sprintf('Field must be an instance of FieldInterface, got "%s"', $this->getType($field)));
            }

            $field->table($this->table);
            $this->fields[$field->name()] = $field;
        }
    }
1313927
public function write(array $fields): int
    {
        $options = $this->getCsvControl();
        $delimiter = $options[0];
        $enclosure = $options[1];
        if (!empty($enclosure)) {
            return $this->fputcsv($fields, $delimiter, $enclosure);
        }

        $fields = array_map(function ($field) use ($delimiter) {
            return str_replace([$delimiter, PHP_EOL], ['', ''], $field);
        }, $fields);

        return $this->fwrite(implode($delimiter, $fields) . PHP_EOL);
    }
1345187
protected function _resolveFields($fields)
    {
        if (is_string($fields)) {
            $fields = [$fields];
        }

        if (!is_array($fields)) {
            throw new Exception('Invalid "fields" configuration.');
        }

        $types = array_keys(Type::map());

        foreach ($fields as $field => $type) {
            if (is_numeric($field) && is_string($type)) {
                unset($fields[$field]);
                $field = $type;
                $type = self::DEFAULT_TYPE;
                $fields[$field] = $type;
            }

            if (!in_array($type, $types)) {
                throw new Exception(sprintf('The field "%s" mapped type "%s" was not found.', $field, $type));
            }
        }

        return $fields;
    }
828993
public function update($fields) {
        if (is_array($fields)) {
            foreach ($fields as $key => $value) {
                if (is_string($value)) {
                    array_push($this->_updates, $key . ' = \'' . addslashes($value) . '\'');
                } else {
                    array_push($this->_updates, $key . ' = ' . $value);
                }
            }
        } else {
            return false;
        }
        
        $sql_query = 'UPDATE ' . $this->_table . 
                     ' SET ' . implode($this->_updates, ', ');
        
        // Where statements
        if (count($this->_where)) {
            $sql_query .= ' WHERE ';
            $sql_query .= implode($this->_where, ' AND ');
            
            // or statements
            if (count($this->_or)) {
                $sql_query .= ' OR ';
                $sql_query .= implode($this->_or, ' AND ');
            }
        }
        
        // Set the query
        $this->_sql_query = $sql_query;
        
        return $this;
    }
790900
public function valid($fields = array())
    {
        if (empty($fields)) {
            $fields = array_diff($this->getFields(), array($this->getIndex()));
        }
        foreach ($fields as $field) {
            $value = $this->getFieldValue($field);
            if (!empty($value)) {
                return true;
            }
        }
        return false;
    }
868574
public function Unserialize($Fields = array('Attributes', 'Data')) {
      $Result =& $this->Result();
      $First = TRUE;
      
      foreach ($Result as $Row) {
         if ($First) {
            // Check which fields are in the dataset.
            foreach ($Fields as $Index => $Field) {
               if (GetValue($Field, $Row, FALSE) === FALSE) {
                  unset($Fields[$Index]);
               }
            }
            $First = FALSE;
         }
         
         foreach ($Fields as $Field) {
            if (is_object($Row)) {
               if (is_string($Row->$Field))
                  $Row->$Field = @unserialize($Row->$Field);
            } else {
               if (is_string($Row[$Field]))
                  $Row[$Field] = @unserialize($Row[$Field]);
            }
         }
      }
   }
1063344
protected function parseField($fields, $options = [])
    {
        $fieldsStr = '';
        if ('*' == $fields || empty($fields)) {
            $fieldsStr = '*';
        } elseif (is_array($fields)) {
            // 支持 'field1'=>'field2' 这样的字段别名定义
            $array = [];
            foreach ($fields as $key => $field) {
                if (!is_numeric($key)) {
                    $array[] = $this->parseKey($key, $options) . ' AS ' . $this->parseKey($field, $options);
                } else {
                    $array[] = $this->parseKey($field, $options);
                }
            }
            $fieldsStr = implode(',', $array);
        }
        return $fieldsStr;
    }
1130000
public final function verifyOnly($fields){

        foreach($fields as $k){
            $this->verifyData($k);
        }//foreach

        if(count($this->errors)){
            return false;
        }//if

        return true;

    }
1338608
public function addField(Field ...$fields)
    {
        collect($fields)->map(function ($field) {
            $this->group['fields']->put($field->key(), $field->get());
        });

        return $this;
    }
664036
public function saveAgent($fields = array()) {
        $this->checkRequiredKeys(__METHOD__, $fields, array('MODULE_ID', 'NAME'));

        $exists = $this->getAgent(array(
            'MODULE_ID' => $fields['MODULE_ID'],
            'NAME' => $fields['NAME']
        ));

        $exportExists = $this->prepareExportAgent($exists);
        $fields = $this->prepareExportAgent($fields);

        if (empty($exists)) {
            $ok = $this->getMode('test') ? true : $this->addAgent($fields);
            $this->outNoticeIf($ok, 'Агент %s: добавлен', $fields['NAME']);
            return $ok;
        }

        if (strtotime($fields['NEXT_EXEC']) <= strtotime($exportExists['NEXT_EXEC'])) {
            unset($fields['NEXT_EXEC']);
            unset($exportExists['NEXT_EXEC']);
        }

        if ($this->hasDiff($exportExists, $fields)) {
            $ok = $this->getMode('test') ? true : $this->updateAgent($fields);
            $this->outNoticeIf($ok, 'Агент %s: обновлен', $fields['NAME']);
            $this->outDiffIf($ok, $exportExists, $fields);
            return $ok;
        }


        $ok = $this->getMode('test') ? true : $exists['ID'];
        if ($this->getMode('out_equal')) {
            $this->outIf($ok, 'Агент %s: совпадает', $fields['NAME']);
        }
        return $ok;
    }
240556
public function save( $fields = null ) 
	{
		$settings = static::_model();

		// check if we should save just some fields
		if ( is_null( $fields ) ) 
		{
			$fields = array_keys( $settings['defaults'] );
		}
		elseif ( !is_array( $fields ) ) 
		{
			$fields = array( $fields );
		}

		$pkey = $this->_data_store[$settings['primary_key']];
		$data = array();

		// Now we have to filter the data to the save g
		foreach( $fields as $field )
		{
			$data[$field] = $this->_data_store[$field];
		}

		// We have to remove the primary key from our data
		if ( array_key_exists( $settings['primary_key'], $data ) )
		{
			unset( $data[$settings['primary_key']] );
		}

		// We pass the data trough the before save callback.
		// This is a local callback for performence reasons.
		$data = $this->_before_save( $data );

		// after the before save event,
		// do we have to to something with the data type?
		foreach( $data as $key => $value )
		{
			if ( array_key_exists( $key, $settings['types'] ) )
			{
				$data[$key] = $this->_type_assignment_set( $settings['types'][$key], $value );
			}
		}

		// check if we have to set the timestamps automatically
		if ( $settings['timestamps'] === true )
		{
			if ( array_key_exists( 'created_at', $data ) )
			{
				// check if created_at should be set
				if ( $data['created_at'] < 1 )
				{
					$this->_data_store['created_at'] = $data['created_at'] = time();
				}
			}

			if ( array_key_exists( 'modified_at', $data ) )
			{
				$this->_data_store['modified_at'] =$data['modified_at'] = time();
			}
		}

		// When we already have a primary key we are going to 
		// update our record instead of inserting a new one.
		if ( !is_null( $pkey ) && $pkey > 0 ) 
		{
			$query = DB::update( $settings['table'], $data )
				->where( $settings['primary_key'], $pkey );
		}
		// No primary key? Smells like an insert query. 
		else 
		{
			$query = DB::insert( $settings['table'], $data );
		}

		// We check the query type to handle the response right
		if ( $query instanceof Query_Insert ) 
		{
			$this->_data_store[$settings['primary_key']] = $query->run();
		}
		else 
		{
			$query->run();
		}

		// after save hookt
		$this->_after_save();

		// return self
		return $this;
	}
1241368
public function fields($fields)
    {
        if (!is_string($fields)) {
            throw new FatalException('Only strings are allowed in COUNT query');
        }

        $this->fields = sprintf(
            'COUNT(%s)',
            DatabaseConnectionFactory::get()->quoteIdentifier($fields)
        );

        return $this;
    }
299333
public function values($fields = [])
    {
        $this->values = [];

        if (empty($fields)) {
            foreach ($this->model->fields() as $field) {
                $this->assignValue($field);
            }

            return $this;
        }

        foreach ($fields as $field) {
            $this->assignValue($this->model->field($field));
        }

        return $this;
    }