ext/duckdb/result.c in duckdb-0.9.2.3 vs ext/duckdb/result.c in duckdb-0.10.0.0
- old
+ new
@@ -1,8 +1,15 @@
#include "ruby-duckdb.h"
static VALUE cDuckDBResult;
+static ID id__to_date;
+static ID id__to_time;
+static ID id__to_time_from_duckdb_time;
+static ID id__to_interval_from_vector;
+static ID id__to_hugeint_from_vector;
+static ID id__to_decimal_from_hugeint;
+static ID id__to_uuid_from_vector;
static void deallocate(void *ctx);
static VALUE allocate(VALUE klass);
static size_t memsize(const void *p);
static VALUE to_ruby_obj_boolean(duckdb_result *result, idx_t col_idx, idx_t row_idx);
@@ -480,20 +487,20 @@
}
static VALUE vector_date(void *vector_data, idx_t row_idx) {
duckdb_date_struct date = duckdb_from_date(((duckdb_date *) vector_data)[row_idx]);
- return rb_funcall(mDuckDBConverter, rb_intern("_to_date"), 3,
+ return rb_funcall(mDuckDBConverter, id__to_date, 3,
INT2FIX(date.year),
INT2FIX(date.month),
INT2FIX(date.day)
);
}
static VALUE vector_timestamp(void* vector_data, idx_t row_idx) {
duckdb_timestamp_struct data = duckdb_from_timestamp(((duckdb_timestamp *)vector_data)[row_idx]);
- return rb_funcall(mDuckDBConverter, rb_intern("_to_time"), 7,
+ return rb_funcall(mDuckDBConverter, id__to_time, 7,
INT2FIX(data.date.year),
INT2FIX(data.date.month),
INT2FIX(data.date.day),
INT2FIX(data.time.hour),
INT2FIX(data.time.min),
@@ -502,22 +509,22 @@
);
}
static VALUE vector_time(void* vector_data, idx_t row_idx) {
duckdb_time_struct data = duckdb_from_time(((duckdb_time *)vector_data)[row_idx]);
- return rb_funcall(mDuckDBConverter, rb_intern("_to_time_from_duckdb_time"), 4,
+ return rb_funcall(mDuckDBConverter, id__to_time_from_duckdb_time, 4,
INT2FIX(data.hour),
INT2FIX(data.min),
INT2FIX(data.sec),
INT2NUM(data.micros)
);
}
static VALUE vector_interval(void* vector_data, idx_t row_idx) {
duckdb_interval data = ((duckdb_interval *)vector_data)[row_idx];
- return rb_funcall(mDuckDBConverter, rb_intern("_to_interval_from_vector"), 3,
+ return rb_funcall(mDuckDBConverter, id__to_interval_from_vector, 3,
INT2NUM(data.months),
INT2NUM(data.days),
LL2NUM(data.micros)
);
}
@@ -540,38 +547,51 @@
}
}
static VALUE vector_hugeint(void* vector_data, idx_t row_idx) {
duckdb_hugeint hugeint = ((duckdb_hugeint *)vector_data)[row_idx];
- return rb_funcall(mDuckDBConverter, rb_intern("_to_hugeint_from_vector"), 2,
+ return rb_funcall(mDuckDBConverter, id__to_hugeint_from_vector, 2,
ULL2NUM(hugeint.lower),
LL2NUM(hugeint.upper)
);
}
static VALUE vector_decimal(duckdb_logical_type ty, void* vector_data, idx_t row_idx) {
- uint8_t width = duckdb_decimal_width(ty);
- uint8_t scale = duckdb_decimal_scale(ty);
+ VALUE width = INT2FIX(duckdb_decimal_width(ty));
+ VALUE scale = INT2FIX(duckdb_decimal_scale(ty));
duckdb_type type = duckdb_decimal_internal_type(ty);
duckdb_hugeint value;
+ VALUE upper = Qnil;
+ VALUE lower = Qnil;
value.upper = 0;
value.lower = 0;
- switch(duckdb_decimal_internal_type(ty)) {
+ switch(type) {
case DUCKDB_TYPE_HUGEINT:
value = ((duckdb_hugeint *) vector_data)[row_idx];
+ upper = LL2NUM(value.upper);
+ lower = ULL2NUM(value.lower);
break;
+ case DUCKDB_TYPE_SMALLINT:
+ upper = INT2FIX(((int16_t *) vector_data)[row_idx]);
+ break;
+ case DUCKDB_TYPE_INTEGER:
+ upper = INT2NUM(((int32_t *) vector_data)[row_idx]);
+ break;
+ case DUCKDB_TYPE_BIGINT:
+ upper = LL2NUM(((int64_t *) vector_data)[row_idx]);
+ break;
default:
rb_warn("Unknown decimal internal type %d", type);
}
- return rb_funcall(mDuckDBConverter, rb_intern("_to_decimal_from_vector"), 4,
- INT2FIX(width),
- INT2FIX(scale),
- ULL2NUM(value.lower),
- LL2NUM(value.upper)
+ return rb_funcall(mDuckDBConverter, id__to_decimal_from_hugeint, 4,
+ width,
+ scale,
+ upper,
+ lower
);
}
static VALUE vector_enum(duckdb_logical_type ty, void* vector_data, idx_t row_idx) {
duckdb_type type = duckdb_enum_internal_type(ty);
@@ -663,11 +683,11 @@
return hash;
}
static VALUE vector_uuid(void* vector_data, idx_t row_idx) {
duckdb_hugeint hugeint = ((duckdb_hugeint *)vector_data)[row_idx];
- return rb_funcall(mDuckDBConverter, rb_intern("_to_uuid_from_vector"), 2,
+ return rb_funcall(mDuckDBConverter, id__to_uuid_from_vector, 2,
ULL2NUM(hugeint.lower),
LL2NUM(hugeint.upper)
);
}
@@ -772,9 +792,17 @@
return obj;
}
void rbduckdb_init_duckdb_result(void) {
cDuckDBResult = rb_define_class_under(mDuckDB, "Result", rb_cObject);
+ id__to_date = rb_intern("_to_date");
+ id__to_time = rb_intern("_to_time");
+ id__to_time_from_duckdb_time = rb_intern("_to_time_from_duckdb_time");
+ id__to_interval_from_vector = rb_intern("_to_interval_from_vector");
+ id__to_hugeint_from_vector = rb_intern("_to_hugeint_from_vector");
+ id__to_decimal_from_hugeint = rb_intern("_to_decimal_from_hugeint");
+ id__to_uuid_from_vector = rb_intern("_to_uuid_from_vector");
+
rb_define_alloc_func(cDuckDBResult, allocate);
rb_define_method(cDuckDBResult, "column_count", duckdb_result_column_count, 0);
rb_define_method(cDuckDBResult, "row_count", duckdb_result_row_count, 0);
rb_define_method(cDuckDBResult, "rows_changed", duckdb_result_rows_changed, 0);