@param PDOStatement $result
@param string|callable  $entity

@return DatabaseResult|int
192868
protected function createResult (PDOStatement $result, $entity = null)
		{
			if ($result->columnCount()) {
				return new DatabaseResult($result, $this->transformEntity($entity));
			} else {
				return true;
			}
		}
6107
public function affectingStatement($query, $bindings = [])
    {
        return $this->run($query, $bindings, function ($query, $bindings) {
            if ($this->pretending()) {
                return 0;
            }

            // For update or delete statements, we want to get the number of rows affected
            // by the statement and return that back to the developer. We'll first need
            // to execute the statement and then we'll use PDO to fetch the affected.
            $statement = $this->getPdo()->prepare($query);

            $this->bindValues($statement, $this->prepareBindings($bindings));

            $statement->execute();

            return $statement->rowCount();
        });
    }
835681
public function addResult($child, $result) {
        if (!$result instanceof Result\ResultInterface) {
            throw new RuntimeException('Result type must be implements ResultInterface');
        }
        $this->results[$child - 1] = $result;
    }
376935
public static function save($entity): ResultInterface
    {
        $className = \get_class($entity);
        list($table, , , $fields) = self::getFields($entity, 1);
        $instance = self::getInstance($className);

        $fields = $fields ?? [];
        $query  = Query::table($table)->selectInstance($instance);
        // Set Primary Id to Entity
        $query->addDecorator(function ($primaryId) use ($entity, $className) {
            list(, , $idColumn) = self::getTable($className);
            // When Primary Id is auto increment
            $getter = 'get' . StringHelper::camel($idColumn, false);
            $setter = 'set' . StringHelper::camel($idColumn, false);
            if (method_exists($entity, $getter) && method_exists($entity, $setter)) {
                if ($entity->$getter() === null) {
                    $entity->$setter($primaryId);
                } else {
                    $primaryId = $entity->$getter();
                }
            }
            return $primaryId;
        });
        return $query->insert($fields);
    }
747051
private function transformResult($result)
    {
        if ($this->actualDriver() === self::DRIVER_PREDIS && $result instanceof Status) {
            $result = $result->getPayload() === 'OK';
        }
        return $result;
    }
1083439
public function delete(&$result)
    {
        $entity = $this->accessor->getPropertyValue($result, $this->definition->container());
        if (empty($entity)) {
            return $result;
        }

        $mediator = [];

        foreach ($this->definition->localKeys() as $entityField => $mediatorField) {
            $mediator[$mediatorField] = $this->accessor->getPropertyValue($result, $entityField);
        }

        foreach ($this->definition->foreignKeys() as $mediatorField => $entityField) {
            $mediator[$mediatorField] = $this->accessor->getPropertyValue($entity, $entityField);
        }

        $this->storage->delete($mediator, $this->definition->mediator())->execute();
        $this->accessor->setPropertyValue($result, $this->definition->container(), $entity);

        return $result;
    }
645337
private function createGetIteratorCallable(stdClass $result, Server $server)
    {
        // Inline results can be wrapped with an ArrayIterator
        if (isset($result->results) && is_array($result->results)) {
            $results = $result->results;

            return function() use ($results) {
                if (isset($this->options['typeMap'])) {
                    return new TypeMapArrayIterator($results, $this->options['typeMap']);
                }

                return new ArrayIterator($results);
            };
        }

        if (isset($result->result) && (is_string($result->result) || is_object($result->result))) {
            $options = isset($this->options['typeMap']) ? ['typeMap' => $this->options['typeMap']] : [];

            $find = is_string($result->result)
                ? new Find($this->databaseName, $result->result, [], $options)
                : new Find($result->result->db, $result->result->collection, [], $options);

            return function() use ($find, $server) {
                return $find->execute($server);
            };
        }

        throw new UnexpectedValueException('mapReduce command did not return inline results or an output collection');
    }
331768
public function executeQuery($model, \PDOStatement $stmt)
    {
        $objectStorage = new EntityObjectStorage();
        if ($stmt->execute()) {
            if ($stmt->rowCount() > 1) {
                return $this->getList($model, $stmt);
            }
            $objectStorage->attach($this->hydrate($model, $stmt->fetchObject()));

        } else {
            $this->log(ILog::T_ERROR, implode(',', $stmt->errorInfo()));
        }

        return $objectStorage;
    }
174042
protected function _fetchField($result, $key = 0)
    {
        $return = null;
        if ($row = $result->fetch_row()) {
            $return = $row[(int)$key];
        }

        $result->free();

        return $return;
    }
48421
public static function delete($entity): ResultInterface
    {
        $className = \get_class($entity);
        list($table, , , $fields) = self::getFields($entity, 3);
        $instance = self::getInstance($className);

        $query = Query::table($table)->selectInstance($instance);
        foreach ($fields ?? [] as $column => $value) {
            $query->where($column, $value);
        }

        return $query->delete();
    }
567530
protected function createModelFromDatabaseResult(array $result)
    {
        $model = $this->getEmptyModel();

        foreach ($result as $key => $value) {
            if ($key === $this->idProperty) {
                $model->setIdRaw($value);
            }

            $model->setPropertyRaw($key, StringUtil::deserialize($value));
        }

        return $model;
    }
1025879
protected function makeObject(IResult $result) {

        // TODO: Prefer to return existing instance from IdentityMap

        $row = $result->fetchRow(ARRAY_ASSOC);
        if ($row === null)
            return null;
        return PersistableObject::populateNew($this->entityClass, $row);
    }
398490
private function setTotalCount(ResultSet $result): void
    {
        $this->totalCount = $result->getTotalCount() - $this->startingOffset;
        $this->totalCount = $this->totalCount > 0 ? $this->totalCount : 0;

        if ($this->maxTotalCount !== null && $this->totalCount >= $this->maxTotalCount) {
            $this->totalCount = $this->maxTotalCount;
        }
    }
932120
public function findByResult(Result $result)
    {
        $dql = '
            SELECT
                u.id,
                CONCAT(u.firstName, \' \', u.lastName) AS name,
                m.value AS mark,
                m.id AS markId
            FROM Claroline\ResultBundle\Entity\Mark m
            JOIN m.user u
            WHERE m.result = :result
            ORDER BY u.lastName ASC
        ';

        $query = $this->_em->createQuery($dql);
        $query->setParameter('result', $result);

        return $query->getArrayResult();
    }
1082652
private function binding(\PDOStatement $sql, array $bindings = []): \PDOStatement
    {
        foreach ($bindings as $binding=>$value) {
            if (!is_array($value)) {
                $sql->bindValue($binding, $value);
            } else {
                switch(strtolower($value[1])) {
                    case 'date':
                        $sql->bindValue($binding, $this->time($value[0], 'Y-m-d'), \PDO::PARAM_STR);
                        break;
                    case 'time':
                        $sql->bindValue($binding, $this->time($value[0], 'Y-m-d H:i:s.u'), \PDO::PARAM_STR);
                        break;
                    case 'bool':
                    case 'boolean':
                        $sql->bindValue($binding, boolval($value[0]), \PDO::PARAM_BOOL);
                        break;
                    case 'null':
                        $sql->bindValue($binding, NULL, \PDO::PARAM_NULL);
                        break;
                    case 'int':
                    case 'integer':
                    case 'number':
                    case 'limit':
                    case 'offset':
                        $sql->bindValue($binding, intval($value[0]), \PDO::PARAM_INT);
                        break;
                    case 'str':
                    case 'string':
                    case 'text':
                    case 'float':
                    case 'varchar':
                    case 'varchar2':
                        $sql->bindValue($binding, strval($value[0]), \PDO::PARAM_STR);
                        break;
                    case 'lob':
                    case 'large':
                    case 'object':
                    case 'blob':
                        $sql->bindParam($binding, $value[0], \PDO::PARAM_LOB, strlen($value[0]));
                        break;
                    case 'like':
                        $sql->bindValue($binding, '%'.$value[0].'%', \PDO::PARAM_STR);
                        break;
                    default:
                        if (is_int($value[1])) {
                            $sql->bindValue($binding, $value[0], $value[1]);
                        } else {
                            $sql->bindValue($binding, strval($value[0]), \PDO::PARAM_STR);
                        }
                }
            }
        }
        return $sql;
    }
1199238
public static function count($where = null): int
    {
        $select = static::select();

        if ($where !== null) {
            if ($where instanceof Where) {
                $select->field('COUNT(*)', 'total');
                $select->where(clone $where);

            } else if (is_array($where)) {
                $select->field('COUNT(*)', 'total');
                foreach ($where as $field => $value) {
                    $select->where($field, $value);
                }

            } else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
                $select->field('COUNT(' . static::$primaryKey . ')', 'total');
                $select->where(static::$primaryKey, $where);

            }
        } else {
            $pk = is_string(static::$primaryKey) ? static::$primaryKey : '*';
            $select->field('COUNT(' . $pk . ')', 'total');
        }

        $results = $select->fetchAll();

        if (isset($results[0])) {
            $r = $results[0];
            if (array_key_exists('total', $r)) {
                return (int)$r['total'];
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }
949913
protected function handleResult(ContextInterface $context, $result)
    {
        $validated = $this->validateResult($result);
        if (is_null($validated)) {
            $validated = $result;
        }

        if ($validated instanceof ContextInterface) {
            $context = $validated;
        } elseif (!is_null($validated)) {
            $context->setResult($validated);
        }

        return $context;
    }