ext/duckdb/prepared_statement.c in duckdb-1.0.0.2 vs ext/duckdb/prepared_statement.c in duckdb-1.1.0.0
- old
+ new
@@ -9,24 +9,24 @@
static VALUE duckdb_prepared_statement_nparams(VALUE self);
static VALUE duckdb_prepared_statement_execute(VALUE self);
static idx_t check_index(VALUE vidx);
static VALUE duckdb_prepared_statement_bind_parameter_index(VALUE self, VALUE name);
-#ifdef HAVE_DUCKDB_PARAMETER_NAME
static VALUE duckdb_prepared_statement_parameter_name(VALUE self, VALUE vidx);
-#endif
-
+static VALUE duckdb_prepared_statement_clear_bindings(VALUE self);
static VALUE duckdb_prepared_statement_bind_bool(VALUE self, VALUE vidx, VALUE val);
static VALUE duckdb_prepared_statement_bind_int8(VALUE self, VALUE vidx, VALUE val);
static VALUE duckdb_prepared_statement_bind_int16(VALUE self, VALUE vidx, VALUE val);
static VALUE duckdb_prepared_statement_bind_int32(VALUE self, VALUE vidx, VALUE val);
static VALUE duckdb_prepared_statement_bind_int64(VALUE self, VALUE vidx, VALUE val);
static VALUE duckdb_prepared_statement_bind_float(VALUE self, VALUE vidx, VALUE val);
static VALUE duckdb_prepared_statement_bind_double(VALUE self, VALUE vidx, VALUE val);
static VALUE duckdb_prepared_statement_bind_varchar(VALUE self, VALUE vidx, VALUE str);
static VALUE duckdb_prepared_statement_bind_blob(VALUE self, VALUE vidx, VALUE blob);
static VALUE duckdb_prepared_statement_bind_null(VALUE self, VALUE vidx);
+static VALUE duckdb_prepared_statement__statement_type(VALUE self);
+static VALUE duckdb_prepared_statement__param_type(VALUE self, VALUE vidx);
static VALUE duckdb_prepared_statement__bind_date(VALUE self, VALUE vidx, VALUE year, VALUE month, VALUE day);
static VALUE duckdb_prepared_statement__bind_time(VALUE self, VALUE vidx, VALUE hour, VALUE min, VALUE sec, VALUE micros);
static VALUE duckdb_prepared_statement__bind_timestamp(VALUE self, VALUE vidx, VALUE year, VALUE month, VALUE day, VALUE hour, VALUE min, VALUE sec, VALUE micros);
static VALUE duckdb_prepared_statement__bind_interval(VALUE self, VALUE vidx, VALUE months, VALUE days, VALUE micros);
static VALUE duckdb_prepared_statement__bind_hugeint(VALUE self, VALUE vidx, VALUE lower, VALUE upper);
@@ -123,11 +123,10 @@
rb_raise(rb_eArgError, "parameter '%s' not found", StringValuePtr(name));
}
return ULL2NUM(idx);
}
-#ifdef HAVE_DUCKDB_PARAMETER_NAME
static VALUE duckdb_prepared_statement_parameter_name(VALUE self, VALUE vidx) {
rubyDuckDBPreparedStatement *ctx;
VALUE vname;
const char *name;
idx_t idx = check_index(vidx);
@@ -140,12 +139,28 @@
}
vname = rb_str_new2(name);
duckdb_free((void *)name);
return vname;
}
-#endif /* HAVE_DUCKDB_PARAMETER_NAME */
+/*
+ * call-seq:
+ * prepared_statement.clear_bindings -> DuckDB::PreparedStatement
+ *
+ * clear all bindings of prepared statement.
+ */
+static VALUE duckdb_prepared_statement_clear_bindings(VALUE self) {
+ rubyDuckDBPreparedStatement *ctx;
+ TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
+
+ if (duckdb_clear_bindings(ctx->prepared_statement) == DuckDBError) {
+ const char *error = duckdb_prepare_error(ctx->prepared_statement);
+ rb_raise(eDuckDBError, "fail to clear bindings. %s", error);
+ }
+ return self;
+}
+
static VALUE duckdb_prepared_statement_bind_bool(VALUE self, VALUE vidx, VALUE val) {
rubyDuckDBPreparedStatement *ctx;
idx_t idx = check_index(vidx);
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
@@ -271,10 +286,22 @@
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
}
return self;
}
+static VALUE duckdb_prepared_statement__statement_type(VALUE self) {
+ rubyDuckDBPreparedStatement *ctx;
+ TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
+ return INT2FIX(duckdb_prepared_statement_type(ctx->prepared_statement));
+}
+
+static VALUE duckdb_prepared_statement__param_type(VALUE self, VALUE vidx) {
+ rubyDuckDBPreparedStatement *ctx;
+ TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
+ return INT2FIX(duckdb_param_type(ctx->prepared_statement, NUM2ULL(vidx)));
+}
+
static VALUE duckdb_prepared_statement__bind_date(VALUE self, VALUE vidx, VALUE year, VALUE month, VALUE day) {
rubyDuckDBPreparedStatement *ctx;
duckdb_date dt;
idx_t idx = check_index(vidx);
@@ -364,24 +391,23 @@
rb_define_method(cDuckDBPreparedStatement, "initialize", duckdb_prepared_statement_initialize, 2);
rb_define_method(cDuckDBPreparedStatement, "execute", duckdb_prepared_statement_execute, 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);
-
-#ifdef HAVE_DUCKDB_PARAMETER_NAME
rb_define_method(cDuckDBPreparedStatement, "parameter_name", duckdb_prepared_statement_parameter_name, 1);
-#endif
-
+ rb_define_method(cDuckDBPreparedStatement, "clear_bindings", duckdb_prepared_statement_clear_bindings, 0);
rb_define_method(cDuckDBPreparedStatement, "bind_bool", duckdb_prepared_statement_bind_bool, 2);
rb_define_method(cDuckDBPreparedStatement, "bind_int8", duckdb_prepared_statement_bind_int8, 2);
rb_define_method(cDuckDBPreparedStatement, "bind_int16", duckdb_prepared_statement_bind_int16, 2);
rb_define_method(cDuckDBPreparedStatement, "bind_int32", duckdb_prepared_statement_bind_int32, 2);
rb_define_method(cDuckDBPreparedStatement, "bind_int64", duckdb_prepared_statement_bind_int64, 2);
rb_define_method(cDuckDBPreparedStatement, "bind_float", duckdb_prepared_statement_bind_float, 2);
rb_define_method(cDuckDBPreparedStatement, "bind_double", duckdb_prepared_statement_bind_double, 2);
rb_define_method(cDuckDBPreparedStatement, "bind_varchar", duckdb_prepared_statement_bind_varchar, 2);
rb_define_method(cDuckDBPreparedStatement, "bind_blob", duckdb_prepared_statement_bind_blob, 2);
rb_define_method(cDuckDBPreparedStatement, "bind_null", duckdb_prepared_statement_bind_null, 1);
+ rb_define_private_method(cDuckDBPreparedStatement, "_statement_type", duckdb_prepared_statement__statement_type, 0);
+ rb_define_private_method(cDuckDBPreparedStatement, "_param_type", duckdb_prepared_statement__param_type, 1);
rb_define_private_method(cDuckDBPreparedStatement, "_bind_date", duckdb_prepared_statement__bind_date, 4);
rb_define_private_method(cDuckDBPreparedStatement, "_bind_time", duckdb_prepared_statement__bind_time, 5);
rb_define_private_method(cDuckDBPreparedStatement, "_bind_timestamp", duckdb_prepared_statement__bind_timestamp, 8);
rb_define_private_method(cDuckDBPreparedStatement, "_bind_interval", duckdb_prepared_statement__bind_interval, 4);
rb_define_private_method(cDuckDBPreparedStatement, "_bind_hugeint", duckdb_prepared_statement__bind_hugeint, 3);