Class: DuckDB::PendingResult
- Inherits:
-
Object
- Object
- DuckDB::PendingResult
- Defined in:
- lib/duckdb/pending_result.rb,
ext/duckdb/pending_result.c
Overview
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
Constant Summary collapse
- STATES =
:nodoc:
%i[ready not_ready error no_tasks].freeze
Instance Method Summary collapse
-
#execute_check_state ⇒ symbol
returns the state of the pending result.
-
#execute_pending ⇒ DuckDB::Result
Get DuckDB::Result object after query execution finished.
-
#execute_task ⇒ nil
Executes the task in the pending result.
- #execution_finished? ⇒ Boolean
- #initialize(*args) ⇒ Object constructor
-
#state ⇒ symbol
returns the state of the pending result.
Constructor Details
#initialize(*args) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'ext/duckdb/pending_result.c', line 38
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;
}
|
Instance Method Details
#execute_check_state ⇒ symbol
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`.
48 49 50 |
# File 'lib/duckdb/pending_result.rb', line 48 def execute_check_state STATES[_execute_check_state] end |
#execute_pending ⇒ DuckDB::Result
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'ext/duckdb/pending_result.c', line 97
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;
}
|
#execute_task ⇒ nil
74 75 76 77 78 |
# File 'ext/duckdb/pending_result.c', line 74
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;
}
|
#execution_finished? ⇒ Boolean
80 81 82 83 |
# File 'ext/duckdb/pending_result.c', line 80
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;
}
|
#state ⇒ symbol
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`.
34 35 36 |
# File 'lib/duckdb/pending_result.rb', line 34 def state STATES[_state] end |