class DuckDB::PendingResult
The DuckDB::PendingResult encapsulates connection with DuckDB pending result. PendingResult provides methods to execute SQL asynchronousely and check if the result is ready and to get the result.
require 'duckdb' db = DuckDB::Database.open con = db.connect stmt = con.prepared_statement(VERY_SLOW_QUERY) pending_result = stmt.pending_prepared while pending_result.state == :not_ready print '.' sleep(0.01) pending_result.execute_task end result = pending_result.execute_pending
Public Class Methods
Source
static VALUE duckdb_pending_result_initialize(int argc, VALUE *argv, VALUE self) {
VALUE oDuckDBPreparedStatement;
VALUE streaming_p = Qfalse;
duckdb_state state;
if (argc == 2) {
rb_warn("The second argument of `DuckDB::PendingResult#new` is now meaningless. The result is the same when it is set to true.");
}
rb_scan_args(argc, argv, "11", &oDuckDBPreparedStatement, &streaming_p);
if (rb_obj_is_kind_of(oDuckDBPreparedStatement, cDuckDBPreparedStatement) != Qtrue) {
rb_raise(rb_eTypeError, "1st argument must be DuckDB::PreparedStatement");
}
rubyDuckDBPendingResult *ctx = get_struct_pending_result(self);
rubyDuckDBPreparedStatement *stmt = get_struct_prepared_statement(oDuckDBPreparedStatement);
state = duckdb_pending_prepared(stmt->prepared_statement, &(ctx->pending_result));
if (state == DuckDBError) {
rb_raise(eDuckDBError, "%s", duckdb_pending_error(ctx->pending_result));
}
return self;
}
Public Instance Methods
Source
# File lib/duckdb/pending_result.rb, line 48 def execute_check_state STATES[_execute_check_state] end
returns the state of the pending result. the result can be :ready, :not_ready, :error, :no_tasks.
:ready means the result is ready to be fetched, and you can call ‘execute_pending` to get the result.
:not_ready or :no_tasks might mean the pending result is not executed yet, so you need to call ‘execute_task`.
@return [symbol] :ready, :not_ready, :error, :no_tasks
Source
static VALUE duckdb_pending_result_execute_pending(VALUE self) {
rubyDuckDBPendingResult *ctx;
rubyDuckDBResult *ctxr;
VALUE result = rbduckdb_create_result();
TypedData_Get_Struct(self, rubyDuckDBPendingResult, &pending_result_data_type, ctx);
ctxr = get_struct_result(result);
if (duckdb_execute_pending(ctx->pending_result, &(ctxr->result)) == DuckDBError) {
rb_raise(eDuckDBError, "%s", duckdb_pending_error(ctx->pending_result));
}
return result;
}
Get DuckDB::Result object after query execution finished.
db = DuckDB::Database.open conn = db.connect pending_result = conn.async_query("slow query") pending_result.execute_task while pending_result.state != :ready result = pending_result.execute_pending # => DuckDB::Result
Source
static VALUE duckdb_pending_result_execute_task(VALUE self) {
rubyDuckDBPendingResult *ctx = get_struct_pending_result(self);
ctx->state = duckdb_pending_execute_task(ctx->pending_result);
return Qnil;
}
Executes the task in the pending result.
db = DuckDB::Database.open conn = db.connect pending_result = conn.async_query("slow query") pending_result.execute_task
Source
static VALUE duckdb_pending_result_execution_finished_p(VALUE self) {
rubyDuckDBPendingResult *ctx = get_struct_pending_result(self);
return duckdb_pending_execution_is_finished(ctx->state) ? Qtrue : Qfalse;
}
Source
# File lib/duckdb/pending_result.rb, line 34 def state STATES[_state] end
returns the state of the pending result. the result can be :ready, :not_ready, :error, :no_tasks.
:ready means the result is ready to be fetched, and you can call ‘execute_pending` to get the result.
:not_ready means the result is not ready yet, so you need to call ‘execute_task`.
@return [symbol] :ready, :not_ready, :error, :no_tasks