Execute an sql query
175612
public function query($query, array $params = null)
    {
        # If the next query should be cached then run the cache function instead
        if ($this->cacheNext) {
            $this->cacheNext = false;
            return $this->cache($query, $params);
        }

        # Ensure we have a connection to run this query on
        $this->connect();

        $this->query = $query;
        $this->params = null;
        $this->preparedQuery = false;

        if (is_array($params)) {
            $this->params = $params;
        }

        $this->quoteChars($query);
        $this->functions($query);
        $this->limit($query);
        $this->tableNames($query);
        $this->namedParams($query, $params);
        $this->paramArrays($query, $params);
        $this->convertNulls($params);

        $preparedQuery = $this->prepareQuery($query, $params);
        $this->preparedQuery = $preparedQuery;

        if ($this->output) {
            if ($this->htmlMode) {
                echo "<pre>";
            }

            echo $preparedQuery;

            if ($this->htmlMode) {
                echo "<hr>";
            } else {
                echo "\n";
            }
        }

        switch ($this->mode) {

            case "mysql":
                if (!$result = $this->server->query($preparedQuery)) {
                    $this->error();
                }
                break;

            case "postgres":
            case "redshift":
                $tmpQuery = $query;
                $query = "";

                $noParams = false;
                if ($this->mode == "redshift" && count($params) > 32767) {
                    $noParams = true;
                }

                $i = 1;
                reset($params);
                while ($pos = strpos($tmpQuery, "?")) {
                    if ($noParams) {
                        $query .= substr($tmpQuery, 0, $pos) . "'" . pg_escape_string(current($params)) . "'";
                        next($params);
                    } else {
                        $query .= substr($tmpQuery, 0, $pos) . "\$" . $i++;
                    }
                    $tmpQuery = substr($tmpQuery, $pos + 1);
                }
                $query .= $tmpQuery;

                $params = Helper::toArray($params);
                if (!$result = pg_query_params($this->server, $query, $params)) {
                    $this->error();
                }
                break;

            case "odbc":
                if (!$result = odbc_prepare($this->server, $query)) {
                    $this->error();
                }
                $params = Helper::toArray($params);
                if (!odbc_execute($result, $params)) {
                    $this->error();
                }
                break;

            case "sqlite":

                if (!is_array($params)) {
                    if (!$result = $this->server->query($preparedQuery)) {
                        $this->error();
                    }

                # If we have some parameters then we must convert them to the sqlite format
                } else {
                    $newQuery = "";
                    foreach ($params as $key => $val) {
                        $pos = strpos($query, "?");
                        $newQuery .= substr($query, 0, $pos);
                        $query = substr($query, $pos + 1);

                        $newQuery .= ":var" . $key;
                    }
                    $newQuery .= $query;

                    if (!$result = $this->server->prepare($newQuery)) {
                        $this->error();
                    }

                    foreach ($params as $key => $val) {
                        switch (gettype($val)) {

                            case "boolean":
                            case "integer":
                                $type = SQLITE3_INTEGER;
                                break;

                            case "double":
                                $type = SQLITE3_FLOAT;
                                break;

                            case "NULL":
                                if ($this->allowNulls) {
                                    $type = SQLITE3_NULL;
                                } else {
                                    $type = SQLITE3_TEXT;
                                    $val = "";
                                }
                                break;

                            default:
                                $type = SQLITE3_TEXT;
                        }

                        $result->bindValue(":var" . $key, $val, $type);
                    }

                    if (!$result = $result->execute()) {
                        $this->error();
                    }
                }
                break;

            case "mssql":
                if (!$result = mssql_query($preparedQuery, $this->server)) {
                    $this->error();
                }
                break;

            case "mssqlsrv":
                if (!$result = sqlsrv_query($this->server, $preparedQuery)) {
                    $this->error();
                }
        }

        if (!$result) {
            $this->error();
        }

        return new Result($result, $this->mode);
    }
918639
protected function executeQuery() {

		$this->lastQuerySql = $this->sql;
		return $this->dbConnection->doPreparedQuery($this->sql, $this->valuesToBind);

	}
90320
def _execute_sql(sql, is_batch, args)
    result = []
    if sql
      #puts "RhomDbAdapter: Executing query - #{sql}; #{args}"
      begin
        result = @database.execute( sql, is_batch, args )
        #puts "result : #{result}"
      rescue Exception => e
        puts "exception when running query: #{e}"
        puts "query: #{sql}"
        raise
      end
    end
    result
  end
85985
function query() {
        if(empty($this->sql)) {
            $this->_constructSql();
        }
        list($sql, $param) = $this->_constructSql();
        $this->_reset();
        return $this->execute($sql, $param);
    }
945130
function exeucte($sql = '')
    {
        if ($sql == '')
        {
            $this->getsql(false);
        }
        else
        {
            $this->sql = $sql;
        }
        $this->result = $this->db->query($this->sql);
        $this->is_execute++;
    }
39325
public void execute(String query, Object... params) throws SQLException {
        createPreparedStatement(query, 0, params).execute();
    }
1076229
def exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil)
      exec_query(sql, name, binds)
    end
972407
def execute_sql(self, *args, **kwargs):
        
        assert self._allow_sync, (
            "Error, sync query is not allowed! Call the `.set_allow_sync()` "
            "or use the `.allow_sync()` context manager.")
        if self._allow_sync in (logging.ERROR, logging.WARNING):
            logging.log(self._allow_sync,
                        "Error, sync query is not allowed: %s %s" %
                        (str(args), str(kwargs)))
        return super().execute_sql(*args, **kwargs)
671890
public static int execute(Connection conn, String sql, Object... params) throws SQLException {
		PreparedStatement ps = null;
		try {
			ps = StatementUtil.prepareStatement(conn, sql, params);
			return ps.executeUpdate();
		} finally {
			DbUtil.close(ps);
		}
	}
1047928
public int execute(String sql, Object... params) {
        Connection conn = getConn();
        try {
            return conn.createQuery(sql)
                    .withParams(params)
                    .executeUpdate()
                    .getResult();
        } finally {
            this.closeConn(conn);
            this.clean(conn);
        }
    }
797674
def ExecuteQuery(self, query, args=None):
    """"""

    def Action(connection):
      connection.cursor.execute(query, args)
      rowcount = connection.cursor.rowcount
      results = connection.cursor.fetchall()
      return results, rowcount

    return self._RetryWrapper(Action)
883338
@Override
    public boolean execute(String sql, String[] columnNames) throws SQLException
    {
        checkClosed();
        throw SQLError.noSupport();
    }
338267
async def execute(
        self,
        db_name,
        sql,
        params=None,
        truncate=False,
        custom_time_limit=None,
        page_size=None,
    ):
        """"""
        page_size = page_size or self.page_size

        def sql_operation_in_thread(conn):
            time_limit_ms = self.sql_time_limit_ms
            if custom_time_limit and custom_time_limit < time_limit_ms:
                time_limit_ms = custom_time_limit

            with sqlite_timelimit(conn, time_limit_ms):
                try:
                    cursor = conn.cursor()
                    cursor.execute(sql, params or {})
                    max_returned_rows = self.max_returned_rows
                    if max_returned_rows == page_size:
                        max_returned_rows += 1
                    if max_returned_rows and truncate:
                        rows = cursor.fetchmany(max_returned_rows + 1)
                        truncated = len(rows) > max_returned_rows
                        rows = rows[:max_returned_rows]
                    else:
                        rows = cursor.fetchall()
                        truncated = False
                except sqlite3.OperationalError as e:
                    if e.args == ('interrupted',):
                        raise InterruptedError(e)
                    print(
                        "ERROR: conn={}, sql = {}, params = {}: {}".format(
                            conn, repr(sql), params, e
                        )
                    )
                    raise

            if truncate:
                return Results(rows, truncated, cursor.description)

            else:
                return Results(rows, False, cursor.description)

        with trace("sql", (db_name, sql.strip(), params)):
            results = await self.execute_against_connection_in_thread(
                db_name, sql_operation_in_thread
            )
        return results
488235
private void executeSql(final Connection connection, final String sql, final boolean isCommit) throws SQLException
   {
      if (sql != null) {
         try (Statement statement = connection.createStatement()) {
            // connection was created a few milliseconds before, so set query timeout is omitted (we assume it will succeed)
            statement.execute(sql);
         }

         if (isIsolateInternalQueries && !isAutoCommit) {
            if (isCommit) {
               connection.commit();
            }
            else {
               connection.rollback();
            }
         }
      }
   }
870682
def query(self, query, *parameters, **kwargs):
        """"""
        cursor = self._cursor()
        try:
            self._execute(cursor, query, parameters or None, kwargs)
            if cursor.description:
                column_names = [column.name for column in cursor.description]
                res = [Row(zip(column_names, row)) for row in cursor.fetchall()]
                cursor.close()
                return res
        except:
            cursor.close()
            raise
537515
function execQueryString($sql, $params = null)
    {
        if (!is_array($params) && !is_null($params)) {
            $params = array($params);
        }

        $stmt = $this->prepare($sql);
        $stmt->execute($params);
        return $stmt;
    }
1289495
def db_query(self, query, args=None):
        
        if args is None:
            self.cursor.execute(query)
        else:
            self.cursor.execute(query, args)