Prepares a statement for execution and returns a statement object

@param  string ...$args
@return \PDOStatement
@throws Issues\QueryError
182350
public function prepare(...$args): \PDOStatement
    {
        $trimmed = trim($args[0]);
        if (empty($trimmed)) {
            throw new Issues\QueryError(
                "Empty query passed to prepare()"
            );
        }
        return $this->pdo->prepare(...$args);
    }
222201
public function query($sql)
    {
        $this->numExecutes++;
        $this->numStatements++;
        
        $pdos = $this->_pdo->query($sql);
        
        return new PDOStatement($this, $pdos);
    }
1108498
public function setArguments(array $args): PostTypeInterface
    {
        $this->args = array_merge($this->args, $args);

        return $this;
    }
191231
private function _parseArgs(array $args)
	{
		$arg = '';
		if(count($args) > 0)
		{
			foreach($args as $number => $argument)
			{
				if($number === 0)
				{
					$arg .= $argument;
				}
				else
				{
					$arg .= ', ' . $argument;
				}
			}
		}

		return $arg;
	}
595507
private function _exec($sql, $arguments = array())
    {
        $sql = $this->replaceArgs($sql, $arguments);

        // executes the statement
        $result = $this->_conn->query($sql);
        if ($this->_conn->errno > 0) {
            throw new DbException(
                "Failed to execute the statement: " .
                "({$this->_conn->errno}) {$this->_conn->error}"
            );
        }

        return $result;
    }
172714
public function select($query, $args = array(), $returnArray = true)
    {
        if($this->pdo) {

            if (!defined('GL_INSTALL') || !GL_INSTALL) {
                $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
            } else {
                $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
            }
            $stmt = $this->pdo->prepare($query);
            $result = $stmt->execute($args);
            //$list = array();
            if ($result) {
                if ($returnArray) {
                    return $stmt->fetchAll(\PDO::FETCH_ASSOC);
                }
                return true;
            } else {
                //            if($this->getLastError())
                throw new \Exception($query . "\n" . $this->getLastError());
            }
        } else {
            throw new \Exception("Error executing query: $query\nIt seems that the connection was not opened!");

        }
    }
102098
public function prepare(string $statement) : PreparedStatementInterface
    {
        $preparedStatement = @$this->getConnection()->prepare($statement);

        if ($preparedStatement === false) {
            throw new ParserRuntimeException('Statement could not be prepared.', 0);
        }

        return new Sqlite3PreparedStatement($preparedStatement);
    }
200975
private function prepare_statement($stmt, $args=[]) {
		if (!$this->connection) {
			self::$logger->error(sprintf(
				"SQL: connection failed: '%s'.",
				json_encode($this->verified_params)));
			throw new SQLError(SQLError::CONNECTION_ERROR,
				$this->dbtype . " connection error.");
		}

		$conn = $this->connection;
		try {
			$pstmt = $conn->prepare($stmt);
		} catch (\PDOException $e) {
			self::$logger->error(sprintf(
				"SQL: execution failed: %s <- '%s': %s.",
				$stmt, json_encode($args),
				$e->getMessage()));
			throw new SQLError(
				SQLError::EXECUTION_ERROR,
				sprintf("Execution error: %s.", $e->getMessage()),
				$stmt, $args
			);
		}

		try {
			$pstmt->execute(array_values($args));
		} catch (\PDOException $e) {
			self::$logger->error(sprintf(
				"SQL: execution failed: %s <- '%s': %s.",
				$stmt, json_encode($args),
				$e->getMessage()));
			throw new SQLError(
				SQLError::EXECUTION_ERROR,
				sprintf("Execution error: %s.", $e->getMessage()),
				$stmt, $args
			);
		}

		return $pstmt;
	}
1095227
private function cmdReset($args)
    {
        $cmd = new ResetCommand($this->cwd);

        return $cmd->run(array_slice($args, 1));
    }
758537
public function prepare($statement) {
        $this->connect();

        $this->statement = new Statement($statement, $this->getParams(), $this->routings);
        $this->statement->setFetchMode($this->defaultFetchMode);

        return $this->statement;
    }
1248338
public function query($statement, ...$fetch): PDOStatement
    {
        $this->connect();

        $statement = DBHelper::replaceTablePrefix($statement, $this->tablePrefix, $this->prefixPlaceholder);

        // trigger before event
        $this->fire(self::BEFORE_EXECUTE, [$statement]);

        $sth = $this->pdo->query($statement, ...$fetch);

        // trigger after event
        $this->fire(self::AFTER_EXECUTE, [$statement]);

        return $sth;
    }
1182727
public function pdoPrepare($statement, $options = [])
    {
        $this->STH = $this->prepare($statement, $options);

        return $this;
    }
306811
protected function _prepareLogMessage(array $args)
    {
        $pattern = $args[0];
        $substitutes = array_slice($args, 1);

        if ( ! $this->_validatePattern($pattern, $substitutes)) {
            return $pattern;
        }

        return vsprintf($pattern, $substitutes);
    }
897886
private function prepareType($arg){
        if(($arg===null || $arg=='null') && $arg !== 0){
            return 'NULL';
        }//if
        if(!is_numeric($arg)){
            return $this->quote($arg);
        }//if
        return $arg;
    }
134366
public function setSQL($sql, array $args=[]) {
		$this->sql = $sql;
		$this->args = $args;

		$this->message = $this->getMessage();

		if(strlen($sql) > 2048)
			return $this;
		$msg = '<br/>'."\n".'SQL: '.$sql;
		if(count($args) > 0) {
			$msg .= ' ('.implode(', ', $args).')';
			if(strlen($msg) > 2048)
				return $this;
		}
		$this->message .= $msg;

		return $this;
	}
790295
public function prepareCommand($args)
    {
        $command = $this->getCommand();
        if (is_string($args)) {
            return $command . ' ' . trim($args);
        }

        foreach ($args as $arg) {
            if ($arg instanceof ModifierInterface) {
                $command = $arg->modify($command);
            } else {
                $command .= ' ' . escapeshellarg($arg);
            }
        }

        return $command;
    }
268961
protected function createPdoStatement($query, $pdo = null)
    {
        if (is_null($pdo)) {
            $pdo = $this->getPdo();
        }

        $grammar = $this->getQueryGrammar();

        $query = preg_replace_callback('#\{(.*?)\}#', function ($matches) use ($grammar)
        {
            $value = $matches[1];

            return $grammar->wrap($value);

        }, $query);

        return $pdo->prepare($query);
    }