ext/duckdb/result.c in duckdb-0.6.1 vs ext/duckdb/result.c in duckdb-0.7.0

- old
+ new

@@ -8,10 +8,12 @@ static VALUE to_ruby_obj_boolean(duckdb_result *result, idx_t col_idx, idx_t row_idx); static VALUE to_ruby_obj_smallint(duckdb_result *result, idx_t col_idx, idx_t row_idx); static VALUE to_ruby_obj_utinyint(duckdb_result *result, idx_t col_idx, idx_t row_idx); static VALUE to_ruby_obj_integer(duckdb_result *result, idx_t col_idx, idx_t row_idx); static VALUE to_ruby_obj_bigint(duckdb_result *result, idx_t col_idx, idx_t row_idx); +static VALUE to_ruby_obj_hugeint(duckdb_result *result, idx_t col_idx, idx_t row_idx); +static VALUE to_ruby_obj_decimal(duckdb_result *result, idx_t col_idx, idx_t row_idx); static VALUE to_ruby_obj_float(duckdb_result *result, idx_t col_idx, idx_t row_idx); static VALUE to_ruby_obj_double(duckdb_result *result, idx_t col_idx, idx_t row_idx); static VALUE to_ruby_obj_blob(duckdb_result *result, idx_t col_idx, idx_t row_idx); static VALUE duckdb_result_column_count(VALUE oDuckDBResult); static VALUE duckdb_result_row_count(VALUE oDuckDBResult); @@ -22,13 +24,16 @@ static VALUE duckdb_result__to_boolean(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); static VALUE duckdb_result__to_smallint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); static VALUE duckdb_result__to_utinyint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); static VALUE duckdb_result__to_integer(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); static VALUE duckdb_result__to_bigint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); +static VALUE duckdb_result___to_hugeint_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); +static VALUE duckdb_result___to_decimal_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); static VALUE duckdb_result__to_float(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); static VALUE duckdb_result__to_double(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); static VALUE duckdb_result__to_string(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); +static VALUE duckdb_result__to_string_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); static VALUE duckdb_result__to_blob(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx); static VALUE duckdb_result__enum_internal_type(VALUE oDuckDBResult, VALUE col_idx); static VALUE duckdb_result__enum_dictionary_size(VALUE oDuckDBResult, VALUE col_idx); static VALUE duckdb_result__enum_dictionary_value(VALUE oDuckDBResult, VALUE col_idx, VALUE idx); @@ -83,10 +88,20 @@ static VALUE to_ruby_obj_bigint(duckdb_result *result, idx_t col_idx, idx_t row_idx) { int64_t i64val = duckdb_value_int64(result, col_idx, row_idx); return rb_int2big(i64val); } +static VALUE to_ruby_obj_hugeint(duckdb_result *result, idx_t col_idx, idx_t row_idx) { + duckdb_hugeint hugeint = duckdb_value_hugeint(result, col_idx, row_idx); + return rb_ary_new3(2, ULL2NUM(hugeint.lower), LL2NUM(hugeint.upper)); +} + +static VALUE to_ruby_obj_decimal(duckdb_result *result, idx_t col_idx, idx_t row_idx) { + duckdb_decimal decimal = duckdb_value_decimal(result, col_idx, row_idx); + return rb_ary_new3(4, ULL2NUM(decimal.value.lower), LL2NUM(decimal.value.upper), UINT2NUM(decimal.width), UINT2NUM(decimal.scale)); +} + static VALUE to_ruby_obj_float(duckdb_result *result, idx_t col_idx, idx_t row_idx) { float fval = duckdb_value_float(result, col_idx, row_idx); return DBL2NUM(fval); } @@ -253,10 +268,24 @@ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx); return to_ruby_obj_bigint(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx)); } +static VALUE duckdb_result___to_hugeint_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) { + rubyDuckDBResult *ctx; + TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx); + + return to_ruby_obj_hugeint(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx)); +} + +static VALUE duckdb_result___to_decimal_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) { + rubyDuckDBResult *ctx; + TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx); + + return to_ruby_obj_decimal(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx)); +} + static VALUE duckdb_result__to_float(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) { rubyDuckDBResult *ctx; TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx); return to_ruby_obj_float(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx)); @@ -293,10 +322,34 @@ return obj; } return Qnil; } +static VALUE duckdb_result__to_string_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) { + rubyDuckDBResult *ctx; +#ifdef HAVE_DUCKDB_H_GE_V060 + duckdb_string p; +#else + char *p; +#endif + VALUE obj; + TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx); + +#ifdef HAVE_DUCKDB_H_GE_V060 + p = duckdb_value_string_internal(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx)); + if (p.data) { + obj = rb_utf8_str_new(p.data, p.size); +#else + p = duckdb_value_varchar_internal(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx)); + if (p) { + obj = rb_utf8_str_new_cstr(p); +#endif + return obj; + } + return Qnil; +} + static VALUE duckdb_result__to_blob(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) { rubyDuckDBResult *ctx; TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx); return to_ruby_obj_blob(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx)); @@ -363,12 +416,15 @@ rb_define_private_method(cDuckDBResult, "_to_boolean", duckdb_result__to_boolean, 2); rb_define_private_method(cDuckDBResult, "_to_smallint", duckdb_result__to_smallint, 2); rb_define_private_method(cDuckDBResult, "_to_utinyint", duckdb_result__to_utinyint, 2); rb_define_private_method(cDuckDBResult, "_to_integer", duckdb_result__to_integer, 2); rb_define_private_method(cDuckDBResult, "_to_bigint", duckdb_result__to_bigint, 2); + rb_define_private_method(cDuckDBResult, "__to_hugeint_internal", duckdb_result___to_hugeint_internal, 2); + rb_define_private_method(cDuckDBResult, "__to_decimal_internal", duckdb_result___to_decimal_internal, 2); rb_define_private_method(cDuckDBResult, "_to_float", duckdb_result__to_float, 2); rb_define_private_method(cDuckDBResult, "_to_double", duckdb_result__to_double, 2); rb_define_private_method(cDuckDBResult, "_to_string", duckdb_result__to_string, 2); + rb_define_private_method(cDuckDBResult, "_to_string_internal", duckdb_result__to_string_internal, 2); rb_define_private_method(cDuckDBResult, "_to_blob", duckdb_result__to_blob, 2); rb_define_private_method(cDuckDBResult, "_enum_internal_type", duckdb_result__enum_internal_type, 1); rb_define_private_method(cDuckDBResult, "_enum_dictionary_size", duckdb_result__enum_dictionary_size, 1); rb_define_private_method(cDuckDBResult, "_enum_dictionary_value", duckdb_result__enum_dictionary_value, 2); }