@inheritdoc

@throws DBALException
776462
public function indexIdentities(): array
    {
        $pkName  = $this->getModelSchemas()->getPrimaryKey($this->getModelClass());
        $builder = $this->createIndexModelBuilder([$pkName]);
        /** @var Generator $data */
        $data   = $this->fetchColumn($builder, $builder->getModelClass(), $pkName);
        $result = iterator_to_array($data);

        return $result;
    }
1121821
public static function dbQuery($sql) {
        
        try {
            return self::query($sql);   
        } catch (PDOException $e) {
            die(self::dbError($sql));
        }
    }
166907
public function setDatabase($dbname)
    {
        $this->config->setDatabase($dbname);
        if ($this->connection) {
            try {
                $this->query('USE ' . $this->quote()->identifier($dbname));
            } catch (RuntimeException $exception) {
                /** @var \PDOException $prevException */
                $prevException = $exception->getPrevious();
                if (UnknownDatabaseException::isUnknownDatabase($prevException)) {
                    throw UnknownDatabaseException::createFromUnknownDatabase($dbname, $prevException);
                }

                throw $exception;
            }
        }

        return $this;
    }
1313350
function registerDatabaseType($typeIdentifier, \Plasma\Types\TypeExtensionInterface $type): void {
        if(isset($this->dbTypes[$typeIdentifier])) {
            throw new \Plasma\Exception('Database Type identifier is already in use');
        }
        
        $this->dbTypes[$typeIdentifier] = $type;
    }
463612
public function columns(array $fields) : self
    {
        foreach ($fields as $k => $v) {
            if (strpos($v, '*') !== false) {
                $temp = explode('.', $v);
                if (count($temp) === 1) {
                    $table = $this->definition->getName();
                    $cols = $this->definition->getColumns();
                } else if (count($temp) === 2) {
                    $table = $temp[0];
                    if ($this->definition->hasRelation($table)) {
                        $cols = $this->definition->getRelation($table)->table->getColumns();
                    } else if (isset($this->joins[$table])) {
                        $cols = $this->joins[$table]->table->getColumns();
                    } else {
                        throw new DBException('Invalid foreign table name');
                    }
                } else {
                    array_pop($temp);
                    $this->with(implode('.', $temp));
                    $table = array_reduce(
                        $temp,
                        function ($carry, $item) use (&$table) {
                            return $table->getRelation($item)->table;
                        }
                    );
                    $cols = $table->getColumns();
                    $table = implode(static::SEP, $temp);
                }
                unset($fields[$k]);
                foreach ($cols as $col) {
                    $fields[] = $table . '.' . $col;
                }
            }
        }
        $primary = $this->definition->getPrimaryKey();
        foreach ($fields as $k => $v) {
            try {
                $fields[$k] = $this->getColumn($v)['name'];
            } catch (DBException $e) {
                $fields[$k] = $v;
            }
        }
        foreach ($primary as $field) {
            $field = $this->getColumn($field)['name'];
            if (!in_array($field, $fields)) {
                $fields[] = $field;
            }
        }
        $this->fields = $fields;
        return $this;
    }
1319550
public function exec($statement)
    {
        $connection = $this->getWrappedConnection();

        $logger = $this->_config->getSQLLogger();
        if ($logger) {
            $logger->startQuery($statement);
        }

        try {
            $result = $connection->exec($statement);
        } catch (Throwable $ex) {
            throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement);
        }

        if ($logger) {
            $logger->stopQuery();
        }

        return $result;
    }
1374992
public function resolve($databaseResult)
    {
        $className = $this->className;

        try {
            $object = new $className();

            $this->loader
                ->mapObjectWithOptions($object, $databaseResult);

            $databaseResult->{$this->fieldName} = $object;
        } catch (\Exception $e) {
            //This is fine, just an empty join
            echo $e->getMessage();
        }
    }
23594
public function execute()
	{
		if( count( $this->_binds ) !== count( $this->_parts ) - 1 ) {
			throw new MW_DB_Exception( sprintf( 'Number of binds (%1$d) doesn\'t match the number of markers in "%2$s"', count( $this->_binds ), $this->_sql ) );
		}

		$sql = $this->_buildSQL();

		try {
			return new MW_DB_Result_PDO( $this->_conn->query( $sql ) );
		} catch ( PDOException $pe ) {
			throw new MW_DB_Exception( sprintf( 'Executing statement "%1$s" failed: ', $sql ) . $pe->getMessage(), $pe->getCode(), $pe->errorInfo );
		}
	}
498860
public static function query($sql) {
        self::init();
        try {
            $db = self::connect();
            if(is_array($db)) {
                throw new DbException('Connection error');
            }
            if(!$query = $db->query($sql)) {
                throw new DbException('Failed to execute query!');
            }
        } catch(mysqli_sql_exception $e) {
            self::$_ops->formatError([], $e->getMessage(), $sql);

        } catch(DbException $e) {
            self::$_ops->formatError([], $e->getMessage(), $sql);
        }
        if(isset($query) && isset($db)) {
            return ['result' => $query, 'link' => $db];
        }
    }
168267
protected function prepareDatabaseException(\PDOException $pdoException, string $query, array $criteria = []): DatabaseException {
		$databaseException = new DatabaseException(
			$pdoException->getMessage(),
			(int)$pdoException->getCode(),
			$pdoException
		);
		
		$query = $this->getStatement($query, $criteria);
		$databaseException->setQuery($query);
		return $databaseException;
	}
1319326
public function get(string $name) : Type
    {
        if (! isset($this->instances[$name])) {
            throw DBALException::unknownColumnType($name);
        }

        return $this->instances[$name];
    }
521412
public static function update(array $data, array $where): int
    {
        $self = static::getInstance();

        $data = static::filterColumns($data);

        if (!\count($data)) {
            throw new DbException(
                "Invalid field names of table `{$self->name}`. Please check use of `update()` method"
            );
        }

        $where = static::filterColumns($where);

        if (!\count($where)) {
            throw new DbException(
                "Method `Table::update()` can't update all records in the table `{$self->name}`,\n" .
                "please use `Db::query()` instead (of cause if you know what are you doing)"
            );
        }

        $table = DbProxy::quoteIdentifier($self->name);

        $sql = "UPDATE $table SET " . implode(',', self::prepareStatement($data))
            . " WHERE " . implode(' AND ', self::prepareStatement($where));

        return DbProxy::query($sql, array_merge(array_values($data), array_values($where)));
    }
1341211
public function query()
    {
        $connection = $this->getWrappedConnection();

        $args = func_get_args();

        $logger = $this->_config->getSQLLogger();
        if ($logger) {
            $logger->startQuery($args[0]);
        }

        try {
            $statement = $connection->query(...$args);
        } catch (Throwable $ex) {
            throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $args[0]);
        }

        $statement->setFetchMode($this->defaultFetchMode);

        if ($logger) {
            $logger->stopQuery();
        }

        return $statement;
    }
1347873
public static function selectOne($sqlstatement, array $data = [])
    {
        static::verifyConnection();

        if (!preg_match("/^select\s.+?\sfrom\s.+;?$/i", $sqlstatement)) {
            throw new DatabaseException(
                'Syntax Error on the Request',
                E_USER_ERROR
            );
        }

        // Prepare query
        $pdostatement = static::$adapter
            ->getConnection()
            ->prepare($sqlstatement);

        // Bind data
        static::$adapter->bind($pdostatement, $data);

        // Execute query
        $pdostatement->execute();

        return Sanitize::make($pdostatement->fetch());
    }
902071
public function execute( $query, array $data = [ ] )
    {
        $result = NULL;

        $statement = $this->database->prepare( $query );

        if ( FALSE === $statement )
        {
            $this->close();

            throw new DatabaseException( 'Failed to create prepared statement.' );
        }

        $result = $statement->execute( $data );

        $this->query = $statement->queryString;

        if ( FALSE !== $result )
        {
            $result = ( int ) $statement->rowCount();
        }

        return $result;
    }
869991
public function prepare($statement)
    {
        try {
            $stmt = new Statement($statement, $this);
        } catch (Throwable $ex) {
            throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement);
        }

        $stmt->setFetchMode($this->defaultFetchMode);

        return $stmt;
    }
420019
public function next(): bool
    {
        try {
            return $this->pdoStatement->nextRowset();
        } catch (PDOException $pdoe) {
            throw new DatabaseException($pdoe->getMessage(), $pdoe);
        }
    }