@param array  $row
@param string $idField

@return mixed

@throws ReaderException
335072
protected function getRowId(array $row, $idField)
    {
        if (!array_key_exists($idField, $row)) {
            throw new ReaderException(
                sprintf(
                    'Row: "%s" has no field named "%s"',
                    $this->key(),
                    $idField
                )
            );
        }

        return $row[$idField];
    }
439956
public function extractFieldFromRow(array $row, array $multilingualData = [])
    {
        $storageFieldDef = $this->extractStorageFieldFromRow($row, $multilingualData);

        $field = new FieldDefinition();

        $field->id = (int)$row['ezcontentclass_attribute_id'];
        $field->name = $this->unserialize($row['ezcontentclass_attribute_serialized_name_list']);
        $field->description = $this->unserialize($row['ezcontentclass_attribute_serialized_description_list']);
        // Unset redundant data
        unset(
            $field->name['always-available'],
            $field->name[0],
            $field->description['always-available'],
            $field->description[0]
        );
        $field->identifier = $row['ezcontentclass_attribute_identifier'];
        $field->fieldGroup = $row['ezcontentclass_attribute_category'];
        $field->fieldType = $row['ezcontentclass_attribute_data_type_string'];
        $field->isTranslatable = ($row['ezcontentclass_attribute_can_translate'] == 1);
        $field->isRequired = $row['ezcontentclass_attribute_is_required'] == 1;
        $field->isInfoCollector = $row['ezcontentclass_attribute_is_information_collector'] == 1;

        $field->isSearchable = (bool)$row['ezcontentclass_attribute_is_searchable'];
        $field->position = (int)$row['ezcontentclass_attribute_placement'];

        $mainLanguageCode = $this->maskGenerator->extractLanguageCodesFromMask((int)$row['ezcontentclass_initial_language_id']);
        $field->mainLanguageCode = array_shift($mainLanguageCode);

        $this->toFieldDefinition($storageFieldDef, $field);

        return $field;
    }
512808
private function updateBoundColumns(array $row)
    {
        foreach ($this->columnBinding as $column => &$metadata) {
            $index = $this->collection->getColumnIndex($column);
            if ($index === null) {
                // todo: I would like to throw an exception and tell someone they screwed up
                // but i think that would violate the PDO api
                continue;
            }

            // Update by reference
            $value           = $this->typedValue($row[$index], $metadata['type']);
            $metadata['ref'] = $value;
        }
    }
1012500
protected function convertRowCharset(array $row, $inputCharset, $fileCharset)
    {
        foreach ($row as $k => $v) {
            $row[$k] = $this->getConverter()->convert($v, $inputCharset, $fileCharset);
        }

        return $row;
    }
1178824
protected function populateFromRow(Row $row = null, $classname = null, $id_column = null, $row_id = null, $from_resultset = false)
        {
            $item = null;
            if ($row instanceof Row) {
                if (!$from_resultset && Core::isDebugMode()) {
                    $previous_time = Core::getDebugTime();
                }
                if ($classname === null) {
                    $classnames = Core::getCachedTableEntityClasses('\\'.get_class($this));
                    if ($classnames) {
                        $classname = $this->getSubclassNameFromRow($row, $classnames);
                    } else {
                        $classname = Core::getCachedTableEntityClass('\\'.get_class($this));
                    }
                    if (!$classname) {
                        throw new Exception("Classname '{$classname}' or subclasses for table '{$this->getB2DBName()}' is not valid");
                    }
                }

                $id_column = ($id_column) ?? $row->getQuery()->getTable()->getIdColumn();
                $row_id = ($row_id !== null) ? $row_id : $row->get($id_column);
                $is_cached = $classname::getB2DBTable()->hasCachedB2DBObject($row_id);
                $item = $classname::getB2DBCachedObjectIfAvailable($row_id, $classname, $row);
                if (!$from_resultset && !$is_cached && Core::isDebugMode()) {
                    Core::objectPopulationHit(1, array($classname), $previous_time);
                }
            }
            return $item;
        }
933848
public function addRow($row)
    {
        if ($row instanceof TableSeparator) {
            $this->rowsCopy[] = $row;

            return parent::addRow($row);
        }

        if (!is_array($row)) {
            throw new \InvalidArgumentException('A row must be an array or a TableSeparator instance.');
        }

        $this->rowsCopy[] = array_values($row);

        return parent::addRow($row);
    }
445553
public function parse($value, $row)
    {
        if ($this->parser != null) {
            return call_user_func($this->parser, $value, $row);
        }
        return $value;
    }
1269951
protected function serializeFields(array $row)
    {
        $data    = array();
        $columns = $this->getColumns();

        $builder = $this->newQueryBuilder($this->getName());
        $parts   = $builder->getQueryPart('from');
        $part    = reset($parts);
        $alias   = $part['alias'];

        foreach ($columns as $name => $type) {
            if (!empty($alias)) {
                $pos = strpos($name, $alias . '.');
                if ($pos !== false) {
                    $name = substr($name, strlen($alias) + 1);
                }
            }

            if (isset($row[$name])) {
                $data[$name] = $this->serializeType($row[$name], $type);
            }
        }

        return $data;
    }
255230
protected function loadObjects(array $row)
    {

        $objectsInfo = [];
        foreach ($row as $alias => $value) {
            $pos = strrpos($alias, ISelector::ALIAS_SEPARATOR);
            if (!$pos) {
                throw new LoadEntityException($this->translate(
                    'Cannot load objects from data row. Field alias "{alias}" is not correct.',
                    ['alias' => $alias]
                ));
            }
            $collectionPath = substr($alias, 0, $pos);
            $fieldName = substr($alias, $pos + 1);

            if (!isset($objectsInfo[$collectionPath])) {
                $objectsInfo[$collectionPath] = [];
            }
            $objectsInfo[$collectionPath][$fieldName] = $value;
        }

        $mainObject = null;
        foreach ($objectsInfo as $collectionPath => $objectInfo) {

            if (!array_key_exists(IObject::FIELD_TYPE, $objectInfo)) {
                throw new LoadEntityException($this->translate(
                    'Cannot load object from data row. Information about object type is not found.'
                ));
            }

            if (!is_null($objectInfo[IObject::FIELD_TYPE])) {
                $object = $this->loadObject($objectInfo[IObject::FIELD_TYPE], $objectInfo);
                if (!$mainObject && !substr_count($collectionPath, ISelector::FIELD_SEPARATOR)) {
                    $mainObject = $object;
                }
            }

        }
        if (!$mainObject) {
            throw new LoadEntityException($this->translate(
                'Cannot detect main object from data row.'
            ));
        }

        return $mainObject;
    }
348822
public function insertBatch(array $items, string $idField = 'id')
    {
        $collectionData = $this->storage->load(true);
        if (!isset($collectionData['items'])) {
            $collectionData['items'] = [];
        }
        if (!isset($collectionData['inc'])) {
            $collectionData['inc'] = 1;
        }
        foreach ($items as &$item) {
            $item[$idField] = $collectionData['inc']++;
        }
        unset($item);
        $collectionData['items'] = \array_merge($collectionData['items'], $items);
        $this->storage->save($collectionData);
    }
126557
public function setHeaderRow(array $row)
    {
        if (null === $this->nbColumns) {
            $this->nbColumns = count($row);
        } elseif (count($row) !== $this->nbColumns) {
            throw new LogicException(sprintf(
                'Expected the header row to contain %s cells, but got %s.',
                $this->nbColumns,
                count($row)
            ));
        }

        $this->headerRow = array_values($row);

        return $this;
    }
1047818
public static function prepareQuery(array &$options=array(), &$instance=null, $IDField=null) {
		self::prepareInstance($instance);
		self::$instances[$instance]->setIDField($IDField);
		if( !empty($options) && !empty($options['output']) && $options['output'] == SQLAdapter::ARR_FIRST ) {
			$options['number'] = 1;
		}
	}
743633
public function createDataObject($row)
    {
        // remove any composed fields
        $add = [];

        if ($this->_compositeExtraFields) {
            foreach ($this->_compositeExtraFields as $fieldName => $composed) {
                // convert joined extra fields into their composite field types.
                $value = [];

                foreach ($composed as $subField) {
                    if (isset($row[$fieldName . $subField])) {
                        $value[$subField] = $row[$fieldName . $subField];

                        // don't duplicate data in the record
                        unset($row[$fieldName . $subField]);
                    }
                }

                $obj = Injector::inst()->create($this->extraFields[$fieldName], $fieldName);
                $obj->setValue($value, null, false);
                $add[$fieldName] = $obj;
            }
        }

        $dataObject = parent::createDataObject($row);

        foreach ($add as $fieldName => $obj) {
            $dataObject->$fieldName = $obj;
        }

        return $dataObject;
    }
921340
function Load(&$row)
    {

        $fms = $this->_phreezer->GetFieldMaps(get_class($this));
		$this->_phreezer->Observe("Loading " . get_class($this),OBSERVE_DEBUG);

        $this->IsLoaded(true); // assume true until fail occurs
		$this->IsPartiallyLoaded(false); // at least we tried

		// in order to prevent collisions on fields, QueryBuilder appends __tablename__rand to the
		// sql statement.  We need to strip that out so we can match it up to the property names
		$rowlocal = array();
		foreach ($row as $key => $val)
		{
			$info = explode("___",$key);

			// we prefer to use tablename.colname if we have it, but if not
			// just use the colname
			$newkey = isset($info[1]) ? ($info[1] . "." . $info[0]) : $info[0];
			if (isset($rowlocal[$newkey]))
			{
				throw new Exception("The column `$newkey` was selected twice in the same query, causing a data collision");
			}
			$rowlocal[$newkey] = $val;

		}

        foreach ($fms as $fm)
        {
            if ( array_key_exists($fm->TableName . "." . $fm->ColumnName, $rowlocal) )
            {
				// first try to locate the field by tablename.colname
				$prop = $fm->PropertyName;
				$this->$prop = $rowlocal[$fm->TableName . "." . $fm->ColumnName];
            }
			elseif ( array_key_exists($fm->ColumnName, $rowlocal) )
			{
				// if we can't locate the field by tablename.colname, then just look for colname
				$prop = $fm->PropertyName;
				$this->$prop = $rowlocal[$fm->ColumnName];
			}
			else
            {
                // there is a required column missing from this $row array - mark as partially loaded
                $this->_phreezer->Observe("Missing column '".$fm->ColumnName."' while loading " . get_class($this), OBSERVE_WARN);
                $this->IsLoaded(false);
				$this->IsPartiallyLoaded(true);
            }
        }

		// now look for any eagerly loaded children - their fields should be available in this query
		$kms = $this->_phreezer->GetKeyMaps(get_class($this));

		foreach ($kms as $km)
		{
			if ($km->LoadType == KM_LOAD_EAGER || $km->LoadType == KM_LOAD_INNER)
			{
				// load the child object that was obtained eagerly and cache so we
				// won't ever grab the same object twice in one page load
				$this->_phreezer->IncludeModel($km->ForeignObject);
				$foclass = $km->ForeignObject;
				$fo = new $foclass($this->_phreezer,$row);

				$this->_phreezer->SetCache(
					$foclass,
					$fo->GetPrimaryKeyValue(),
					$fo,
					$this->_phreezer->CacheQueryObjectLevel2
				);
			}
		}
		$this->_phreezer->Observe("Firing " . get_class($this) . "->OnLoad()",OBSERVE_DEBUG);
		$this->OnLoad();
    }
422832
protected function loadRow(array $row) {
        $settings = \json_decode($row['settings'], true);
        if($settings === null) {
            $this->client->emit('warn', 'MySQLProvider couldn\'t parse the settings stored for guild "'.$row['guild'].'". Error: '.\json_last_error_msg());
            return;
        }
        
        $settings = new \ArrayObject($settings, \ArrayObject::ARRAY_AS_PROPS);
        $this->settings->set($row['guild'], $settings);
        
        try {
            $this->setupGuild($row['guild']);
        } catch (\InvalidArgumentException $e) {
            $this->settings->delete($row['guild']);
            $this->runQuery('DELETE FROM `settings` WHERE `guild` = ?', array($row['guild']))->done(null, array($this->client, 'handlePromiseRejection'));
        }
    }
124228
public function get(string $path, array $row): ?string
    {
        if (null === $content = $this->decode($row)) {
            return null;
        }

        $pathChunks = explode('.', $path);
        if (0 !== strpos($pathChunks[0], 'row')) {
            throw new \InvalidArgumentException('Path ' . $path . ' first part must be row, found: ' . $pathChunks[0]);
        }
        if (0 !== strpos($pathChunks[1], 'col')) {
            throw new \InvalidArgumentException('Path ' . $path . ' second part must be col, found: ' . $pathChunks[1]);
        }

        if ($value = ($content[(int) substr($pathChunks[0], 3)][(int) substr($pathChunks[1], 3)] ?? null)) {
            return $value;
        }

        return null;
    }
479479
public function process(array $row)
    {
        foreach ($row as &$item) {
            if (is_object($item)) {
                if (method_exists($item, '__toString')) {
                    $item = $item->__toString();
                } else {
                    throw new InvalidArgumentException("Supplied object does not implement __toString");
                }
            }
        }

        return $row;
    }