Invoked before any query is executed

@param string $sql
548490
protected function beforeQuery($sql)
    {
        // Reset state
        $this->rowCount = 0;
        $this->lastStatementError = null;

        // Flush if necessary
        if ($this->isQueryDDL($sql)) {
            $this->flushStatements();
        }
    }
1250373
protected function query ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		if (!($res = mysqli_query( $this->conn, $sql)))
		{
			$this->sql_errcheck($sql);
		}
		if (!is_bool($res))
		{
			((mysqli_free_result($res) || (is_object($res) && (get_class($res) == "mysqli_result"))) ? true : false);
		}
	}
345927
public function prepare($sql)
    {
        $this->_connect();
        if ($this->_stmt) {
            $this->_stmt->close();
        }
        $stmtClass = $this->_defaultStmtClass;
        if (!class_exists($stmtClass)) {
            // require_once 'Zend/Loader.php';
            Zend_Loader::loadClass($stmtClass);
        }
        $stmt = new $stmtClass($this, $sql);
        if ($stmt === false) {
            return false;
        }
        $stmt->setFetchMode($this->_fetchMode);
        $this->_stmt = $stmt;
        return $stmt;
    }
1181705
public function execute($sql) {
        try {
            $lastExecMode = $this->skipResults;
            $this->skipResults = true;

            $this->executeRaw($sql);
            return $this;
        }
        finally {
            $this->skipResults = $lastExecMode;
        }
    }
664819
protected function execSQL($sql)
    {
        // Check and ignore empty statements
        if (trim($sql) == "") {
            return;
        }

        try {
            $this->totalSql++;

            if (!$this->autocommit) {
                $this->conn->beginTransaction();
            }

            $stmt = $this->conn->prepare($sql);
            $this->log(sprintf('    Executing statement "%s"', $sql), Project::MSG_VERBOSE);
            $stmt->execute();
            $this->log(sprintf('    %d rows affected', $stmt->rowCount()), Project::MSG_VERBOSE);

            if (!$this->autocommit) {
                $this->conn->commit();
            }

            $this->goodSql++;
        } catch (PDOException $e) {
            $this->log("Failed to execute: " . $sql, Project::MSG_ERR);
            if ($this->onError != "continue") {
                throw $e;
            }
            $this->log($e->getMessage(), Project::MSG_ERR);
        }
    }
649516
public static void execute(final Connection connection, final String sql) throws SQLException {
        try (PreparedStatement preparedStatement = connection.prepareStatement(sql)){
            preparedStatement.execute();
        }
    }
1016007
protected function _beforeQuerySelect()
    {
        if ($this->scope) {
            $this->scopes = $this->getService('com://site/components.domain.entityset.scope');
            if ($this->current_scope = $this->scopes->find($this->scope)) {
                $this->where('node.type', 'LIKE', '%'.$this->current_scope->identifier);
            }
        }
    }
698912
public function writeSQL($sql)
    {
        $this->sql = $sql;
        $this->PDO = $this->PDO->prepare($this->sql);
    }
465725
private function before(callable $before): void
    {
        if ($before instanceof Closure) {
            $this->options["before"] = $before->bindTo($this);
        } else {
            $this->options["before"] = $before;
        }
    }
306697
private void doInterceptBeforeQuery(Class<?> clazz, StringBuilder sql, List<Object> args) {
        for (DBHelperInterceptor interceptor : interceptors) {
            boolean isContinue = interceptor.beforeSelect(clazz, sql.toString(), args);
            if (!isContinue) {
                throw new NotAllowQueryException("interceptor class:" + interceptor.getClass());
            }
        }
    }
987691
protected function _execute( $sql, $name = 'db' )
	{
		$this->_getConnection( $name )->create( $sql )->execute()->finish();
	}
477467
public function log(string $sql, array $parameters = []): void
    {
        $message = sprintf('[SQL]: %s', $this->removeWhitespace($sql));
        $this->logger->log($this->logLevel, $message, $parameters);
    }
847246
public function execute()
    {
        if (!$this->sessionSet && $this->platform instanceof MySqlPlatform) {
            $this->connection->exec("SET @@SESSION.sql_mode = '';");
            $this->sessionSet = true;
        }

        // Take a local copy so that we don't modify the original query and cause issues later
        $query = $this->replacePrefix((string) $this->sql);

        if (!($this->sql instanceof \JDatabaseQuery) && ($this->limit > 0 || $this->offset > 0)) {
            // @TODO
            if ($this->offset > 0) {
                $query .= ' LIMIT ' . $this->offset . ', ' . $this->limit;
            } else {
                $query .= ' LIMIT ' . $this->limit;
            }
        }

        $this->prepared = $this->connection->prepare($query);

        // Increment the query counter.
        $this->count++;

        // Reset the error values.
        $this->errorNum = 0;
        $this->errorMsg = '';
        $memoryBefore = null;

        // If debugging is enabled then let's log the query.
        if ($this->debug) {
            // Add the query to the object queue.
            $this->log[] = $query;

            \JLog::add($query, \JLog::DEBUG, 'databasequery');

            $this->timings[] = microtime(true);
        }

        // Execute the query.
        $this->executed = false;
        $previous = null;

        if ($this->prepared instanceof Statement) {
            // Bind the variables:
            if ($this->sql instanceof JDatabaseQueryPreparable) {
                $bounded = $this->sql->getBounded();

                foreach ($bounded as $key => $obj) {
                    $this->prepared->bindParam($key, $obj->value, $obj->dataType, $obj->length, $obj->driverOptions);
                }
            }

            try {
                $this->executed = $this->prepared->execute();
            } catch (\Exception $previous) {
            }
        }

        if ($this->debug) {
            $this->timings[] = microtime(true);

            if (defined('DEBUG_BACKTRACE_IGNORE_ARGS')) {
                $this->callStacks[] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
            } else {
                $this->callStacks[] = debug_backtrace();
            }
        }

        // If an error occurred handle it.
        if (!$this->executed) {
            // Get the error number and message before we execute any more queries.
            $errorNum = (int) $this->connection->errorCode();
            $errorMsg = (string) 'SQL: ' . implode(", ", $this->connection->errorInfo());

            // Get the error number and message from before we tried to reconnect.
            $this->errorNum = $errorNum;
            $this->errorMsg = $errorMsg;

            // Throw the normal query exception.
            \JLog::add(
                \JText::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg),
                \JLog::ERROR,
                'databasequery'
            );
            throw new RuntimeException($this->errorMsg, $this->errorNum, $previous);
        }

        return $this->prepared;
    }
246634
public void preExecute() throws SQLException {
    lastQueryNanos = System.nanoTime();
    //if connection is closed or failed on slave
    if (this.currentProtocol != null && this.currentProtocol.isClosed()) {
      preAutoReconnect();
    }
  }
567356
public static function execute($conn, $sql) {
    $conn = is_array($conn) ? self::connect($conn) : $conn;
    $result = $conn->query($sql);
    if (!$result) {
      throw new SqlException("Cannot execute $sql: " . $conn->error);
    }

    if ($result && $result !== TRUE) {
      $result->free_result();
    }

  }
514268
protected function checkTableStatus(string $table, string $sql) : void
    {
        $sql = preg_replace("@^\s+@ms", '', $sql);
        $requestedColumns = [];
        foreach (preg_split("@,\n@m", $sql) as $reqCol) {
            if (preg_match("@^PRIMARY KEY\s*\((.*?)\)@", $reqCol, $pk)) {
                continue;
            }
            preg_match("@^[^\s]+@", $reqCol, $name);
            $name = $name[0];
            $requestedColumns[$name] = [
                'column_name' => $name,
                'column_default' => null,
                'is_nullable' => true,
                'column_type' => '',
                '_definition' => trim($reqCol),
            ];
            $reqCol = str_replace('PRIMARY KEY', '', $reqCol);
            $reqCol = preg_replace("@^$name\s+@", '', $reqCol);
            if (strpos($reqCol, 'NOT NULL')) {
                $requestedColumns[$name]['is_nullable'] = false;
                $reqCol = str_replace('NOT NULL', '', $reqCol);
            }
            if (preg_match("@DEFAULT\s+(.*?)$@", $reqCol, $default)) {
                $parsed = preg_replace("@(^'|'$)@", '', $default[1]);
                $requestedColumns[$name]['column_default'] = $parsed;
                $requestedColumns[$name]['_default'] = $default[1];
                $reqCol = str_replace($default[0], '', $reqCol);
            }
            $requestedColumns[$name]['column_type'] = trim($reqCol);
        }
        $this->columns->execute([$this->loader->getDatabase(), $table]);
        $currentColumns = [];
        foreach ($this->columns->fetchAll(PDO::FETCH_ASSOC) as $column) {
            if (!isset($requestedColumns[$column['column_name']])) {
                $this->addOperation("ALTER TABLE $table DROP COLUMN {$column['column_name']};");
            } else {
                $column['is_nullable'] = $column['is_nullable'] == 'YES';
                $column['column_type'] = strtoupper($column['column_type']);
                $currentColumns[$column['column_name']] = $column;
            }
        }
        foreach ($requestedColumns as $name => $col) {
            if (!isset($currentColumns[$name])) {
                $this->addOperation("ALTER TABLE $table ADD COLUMN {$col['_definition']};");
            } else {
                foreach ($this->modifyColumn($table, $name, $col, $currentColumns[$name]) as $sql) {
                    $this->addOperation($sql);
                }
            }
        }
    }
220107
public function execute($sql)
    {
        if ($this->hasProfiler()) {
            if ($profile = $this->getProfiler()->start()) {
                $profile->setName($sql);
                $profile->setAdapter($this);
            }
        }

        $result = $this->query($sql);

        if ($this->hasProfiler() && $profile !== null) {
            $this->getProfiler()->end($profile);
        }

        if ($result !== false) {
            return $result;
        } else {
            trigger_error($this->error() . " [$sql]", E_USER_WARNING);
        }

        return false;
    }