ext/duckdb/prepared_statement.c in duckdb-1.1.1.0 vs ext/duckdb/prepared_statement.c in duckdb-1.1.2.0
- old
+ new
@@ -1,15 +1,17 @@
#include "ruby-duckdb.h"
VALUE cDuckDBPreparedStatement;
+static void destroy_prepared_statement(rubyDuckDBPreparedStatement *p);
static void deallocate(void *ctx);
static VALUE allocate(VALUE klass);
static size_t memsize(const void *p);
static VALUE duckdb_prepared_statement_initialize(VALUE self, VALUE con, VALUE query);
static VALUE duckdb_prepared_statement_nparams(VALUE self);
static VALUE duckdb_prepared_statement_execute(VALUE self);
+static VALUE duckdb_prepared_statement_destroy(VALUE self);
static idx_t check_index(VALUE vidx);
static VALUE duckdb_prepared_statement_bind_parameter_index(VALUE self, VALUE name);
static VALUE duckdb_prepared_statement_parameter_name(VALUE self, VALUE vidx);
static VALUE duckdb_prepared_statement_clear_bindings(VALUE self);
@@ -35,14 +37,21 @@
"DuckDB/PreparedStatement",
{NULL, deallocate, memsize,},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
};
+static void destroy_prepared_statement(rubyDuckDBPreparedStatement *p) {
+ if (p->prepared_statement) {
+ duckdb_destroy_prepare(&(p->prepared_statement));
+ }
+}
+
static void deallocate(void *ctx) {
rubyDuckDBPreparedStatement *p = (rubyDuckDBPreparedStatement *)ctx;
- duckdb_destroy_prepare(&(p->prepared_statement));
+ destroy_prepared_statement(p);
+ // duckdb_destroy_prepare(&(p->prepared_statement));
xfree(p);
}
static VALUE allocate(VALUE klass) {
rubyDuckDBPreparedStatement *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBPreparedStatement));
@@ -89,11 +98,10 @@
rubyDuckDBPreparedStatement *ctx;
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
return ULL2NUM(duckdb_nparams(ctx->prepared_statement));
}
-
static VALUE duckdb_prepared_statement_execute(VALUE self) {
rubyDuckDBPreparedStatement *ctx;
rubyDuckDBResult *ctxr;
VALUE result = rbduckdb_create_result();
@@ -103,10 +111,23 @@
rb_raise(eDuckDBError, "%s", duckdb_result_error(&(ctxr->result)));
}
return result;
}
+/*
+ * :nodoc:
+ */
+static VALUE duckdb_prepared_statement_destroy(VALUE self) {
+ rubyDuckDBPreparedStatement *ctx;
+ TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
+ destroy_prepared_statement(ctx);
+ /*
+ ctx->prepared_statement = NULL;
+ */
+ return Qnil;
+}
+
static idx_t check_index(VALUE vidx) {
idx_t idx = NUM2ULL(vidx);
if (idx <= 0) {
rb_raise(rb_eArgError, "index of parameter must be greater than 0");
}
@@ -389,9 +410,10 @@
rb_define_alloc_func(cDuckDBPreparedStatement, allocate);
rb_define_method(cDuckDBPreparedStatement, "initialize", duckdb_prepared_statement_initialize, 2);
rb_define_method(cDuckDBPreparedStatement, "execute", duckdb_prepared_statement_execute, 0);
+ rb_define_method(cDuckDBPreparedStatement, "destroy", duckdb_prepared_statement_destroy, 0);
rb_define_method(cDuckDBPreparedStatement, "nparams", duckdb_prepared_statement_nparams, 0);
rb_define_method(cDuckDBPreparedStatement, "bind_parameter_index", duckdb_prepared_statement_bind_parameter_index, 1);
rb_define_method(cDuckDBPreparedStatement, "parameter_name", duckdb_prepared_statement_parameter_name, 1);
rb_define_method(cDuckDBPreparedStatement, "clear_bindings", duckdb_prepared_statement_clear_bindings, 0);
rb_define_method(cDuckDBPreparedStatement, "bind_bool", duckdb_prepared_statement_bind_bool, 2);