@param array $fields

@return bool

@throws DBALException
@throws Exception
433374
protected function insertInternal(array $fields = [])
    {
        $dirty = $this->getDirtyAttributes();

        $values = $this->getChangedAttributes($fields);
        if (empty($values)) {
            return true;
        }

        $connection = static::getConnection();
        $qb = $this->getQueryBuilder();

        $tableName = $qb->getQuotedName(TableNameResolver::getTableName($this->tableName()));
        $sql = $qb
            ->insert()
            ->table($tableName)
            ->values($values)
            ->toSQL();
        $inserted = $connection->executeUpdate($sql);
        if (false === $inserted) {
            return false;
        }

        foreach (self::getMeta()->getPrimaryKeyName(true) as $primaryKeyName) {
            if (
                empty($this->getAttribute($this->getSequenceName())) ||
                false === in_array($primaryKeyName, $dirty)
            ) {
                $values[$primaryKeyName] = $connection->lastInsertId($this->getSequenceName());
            }
        }

        $this->setAttributes($values);

        return true;
    }
440456
protected function setFields($fields)
    {
        if(is_array($fields)) {
            foreach ( $fields as $field ) {
                if ( !in_array($field, $this->fieldsWhitelist) ) {
                    throw new \InvalidArgumentException(sprintf('The field `%s` was not recognized.', $field));
                }
            }
        } elseif($fields === true) {
            $fields = $this->fieldsWhitelist;
        } else {
            throw new \InvalidArgumentException("The argument passed to setFields was invalid");
        }

        $this->setQueryParam('fields', $fields);
    }
1210470
public function selectExcept($fields)
    {
        $fields = array_diff($this->getFields(), is_array($fields) ? $fields : [$fields]);

        return $this->select($fields);
    }
534421
public function insert(array $fields = [])
    {
        $connection = $this->getConnection();

        $this->beforeInsertInternal();

        $connection->beginTransaction();
        try {
            if (($inserted = $this->insertInternal($fields))) {
                $connection->commit();
            } else {
                $connection->rollBack();
            }
        } catch (\Exception $e) {
            $connection->rollBack();
            throw $e;
        }

        $this->afterInsertInternal();

        if ($inserted) {
            $this->setIsNewRecord(false);
            $this->updateRelated();
            $this->attributes->resetOldAttributes();
        }

        return $inserted;
    }
113602
public function fields($fields) {
        if (!is_array($fields)) {
            $fields = func_get_args();
        }

        $this->_fields = $fields;

        return $this;
    }
627968
protected function sqlupdate(array $fields, array $nums = null, array $bools = null) {
		$db = $this->db;

		$idfield = $this->idfield();

		$nums != null or $nums = [];
		$bools != null or $bools = [];

		$keys = array_diff(array_keys($fields), [ $idfield ]);
		$strs = array_diff(array_keys($fields), $bools, $nums);

		$setters = \hlin\Arr::join(",\n\t\t\t\t\t       ", $keys, function ($_, $val) {
			return "`$val` = :$val";
		});

		$db->prepare
			(
				"	UPDATE `[table]`
					   SET $setters
					 WHERE `$idfield` = :$idfield
				",
				[ 'table' => $this->constants()['table'] ]
			)
			->strs($fields, $strs)
			->bools($fields, $bools)
			->nums($fields, $nums)
			->execute();

		return $fields[$idfield];
	}
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;
    }
555014
public function login(array $pFields)
	{
		$this->logout();

		$conditions = new Conditions();
		foreach ($pFields as $field => $value) {
			$conditions->add($field, Conditions::EQ, $value);
		}

		$this->_user->load(array(
			DbInterface::FILTER_CONDITIONS => $conditions
		));
		if ($this->_user->getId()) {
			$this->_session->userId = $this->_user->getId();
			return true;
		}

		return false;
    }
1328816
public function setFields(array $fields)
    {
        foreach ($fields as $name => $value) {
            $this->setField($name, $value);
        }

        $this->prepareQuery();

        return $this;
    }
748998
public function setFields(array $fields)
    {
        $this->fields = $fields;
        $this->queryBuilder->select(implode(', ', $fields));
        return $this;
    }
5564
public function hasFields(array $fields)
    {
        try {
            $this->model_class::checkUnknownColumn($fields);
        } catch (UnknownColumnException $e) {
            return "Resource '$this->name' "
                . explode(' ', $e->getMessage(), 2)[1];
        }
        return true;
    }
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]);
            }
         }
      }
   }
954177
public function select($fields = [])
    {
        if (is_array($fields)) {
            foreach ($fields as $field) {
                $this->addSelect($field);
            }
        } elseif (is_string($fields)) {
            $this->addSelect($fields);
        }

        return $this;
    }
174803
public function setFields(array $fields)
    {
        $this->fields = [];

        foreach ($fields as $type => $field) {
            //Remove empty and repeated fields
            $this->fields[$type] = array_unique(array_filter(explode(',', $field)));
        }

        return $this;
    }
422914
public function addFields(array $fields)
    {
        foreach ($fields as $field)
        {
            $name = $field->getName();
            $addFields[$name] = $field; # we key by name to prevent duplicates!
        }
        
        $keysString = "";
        $fieldStrings = array();
        
        foreach ($addFields as $fieldName => $field)
        {
            $fieldStrings[] = $field->getFieldString();
                
            /* @var $field DatabaseField */
            if ($field->isPrimaryKey())
            {
                $errMsg = 'Do not set field to be primary key when adding fields. ' .
                          'Instead, use the changePrimaryKey method';
                throw new \Exception($errMsg);
            }
            elseif ($field->isKey())
            {
                if ($keysString !== "")
                {
                    $keysString .= ", ";
                }
                
                if ($field->isUnique())
                {
                    $keysString .= "UNIQUE ";
                }
                
                $keysString .= "KEY (`" . $fieldName . "`) ";
            }
        }
        
        $fieldsString = implode(", ", $fieldStrings);
        
        $fieldsString .= $keysString;
        
        $query = 
            "ALTER TABLE " . 
            "`" . $this->m_name . "` " . 
            "ADD " .
            "(" . $fieldsString . ") ";
        
        $result = $this->m_mysqliConn->query($query);
        
        if ($result !== TRUE)
        {
            throw new \Exception('Error creating table with query: ' . $query);
        }
    }
208063
private function isValidFields(array $fields): void
    {
        $allowedFields = $this->getAllowedFields();
        foreach ($fields as $field) {
            if (!\in_array($field, $allowedFields, true)) {
                throw new InvalidKeyException(sprintf(
                    '%s is not a valid value. fields must only contain "%s".',
                    $field,
                    implode(', ', $allowedFields)
                ));
            }
        }
    }
12726
private function assertValidFields($fields)
    {
        if(!isset($fields)) {
            throw new InvalidArgumentException("Fields are empty");
        }

        foreach($fields as $field) {
            if(count(explode('.', $field['key'])) != 2) {
                throw new InvalidArgumentException('Key has wrong format');
            }
        }
    }