ext/duckdb/prepared_statement.c in duckdb-0.9.0.1 vs ext/duckdb/prepared_statement.c in duckdb-0.9.1

- old
+ new

@@ -10,11 +10,14 @@ static VALUE duckdb_prepared_statement_execute(VALUE self); static idx_t check_index(VALUE vidx); #ifdef HAVE_DUCKDB_H_GE_V090 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 +#endif 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); @@ -108,12 +111,31 @@ if (duckdb_bind_parameter_index(ctx->prepared_statement, &idx, StringValuePtr(name)) == DuckDBError) {; rb_raise(rb_eArgError, "parameter '%s' not found", StringValuePtr(name)); } return ULL2NUM(idx); } -#endif +#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); + + TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx); + + name = duckdb_parameter_name(ctx->prepared_statement, idx); + if (name == NULL) { + rb_raise(eDuckDBError, "fail to get name of %llu parameter", (unsigned long long)idx); + } + vname = rb_str_new2(name); + duckdb_free((void *)name); + return vname; +} +#endif /* HAVE_DUCKDB_PARAMETER_NAME */ +#endif /* HAVE_DUCKDB_H_GE_V090 */ + 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); @@ -328,9 +350,12 @@ rb_define_method(cDuckDBPreparedStatement, "execute", duckdb_prepared_statement_execute, 0); rb_define_method(cDuckDBPreparedStatement, "nparams", duckdb_prepared_statement_nparams, 0); #ifdef HAVE_DUCKDB_H_GE_V090 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 #endif 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);