duckdb 1.0.0.2 → 1.1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/duckdb/result.c CHANGED
@@ -18,20 +18,11 @@ static ID id__to_time_from_duckdb_timestamp_ms;
18
18
  static ID id__to_time_from_duckdb_timestamp_ns;
19
19
  static ID id__to_time_from_duckdb_time_tz;
20
20
  static ID id__to_time_from_duckdb_timestamp_tz;
21
+ static ID id__to_infinity;
21
22
 
22
23
  static void deallocate(void *ctx);
23
24
  static VALUE allocate(VALUE klass);
24
25
  static size_t memsize(const void *p);
25
- static VALUE to_ruby_obj_boolean(duckdb_result *result, idx_t col_idx, idx_t row_idx);
26
- static VALUE to_ruby_obj_smallint(duckdb_result *result, idx_t col_idx, idx_t row_idx);
27
- static VALUE to_ruby_obj_utinyint(duckdb_result *result, idx_t col_idx, idx_t row_idx);
28
- static VALUE to_ruby_obj_integer(duckdb_result *result, idx_t col_idx, idx_t row_idx);
29
- static VALUE to_ruby_obj_bigint(duckdb_result *result, idx_t col_idx, idx_t row_idx);
30
- static VALUE to_ruby_obj_hugeint(duckdb_result *result, idx_t col_idx, idx_t row_idx);
31
- static VALUE to_ruby_obj_decimal(duckdb_result *result, idx_t col_idx, idx_t row_idx);
32
- static VALUE to_ruby_obj_float(duckdb_result *result, idx_t col_idx, idx_t row_idx);
33
- static VALUE to_ruby_obj_double(duckdb_result *result, idx_t col_idx, idx_t row_idx);
34
- static VALUE to_ruby_obj_blob(duckdb_result *result, idx_t col_idx, idx_t row_idx);
35
26
  static VALUE duckdb_result_column_count(VALUE oDuckDBResult);
36
27
  static VALUE duckdb_result_row_count(VALUE oDuckDBResult);
37
28
  static VALUE duckdb_result_rows_changed(VALUE oDuckDBResult);
@@ -43,23 +34,13 @@ static VALUE duckdb_result_chunk_each(VALUE oDuckDBResult);
43
34
  static VALUE duckdb_result__chunk_stream(VALUE oDuckDBResult);
44
35
  static VALUE yield_rows(VALUE arg);
45
36
  static VALUE duckdb_result__column_type(VALUE oDuckDBResult, VALUE col_idx);
46
- static VALUE duckdb_result__is_null(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
47
- static VALUE duckdb_result__to_boolean(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
48
- static VALUE duckdb_result__to_smallint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
49
- static VALUE duckdb_result__to_utinyint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
50
- static VALUE duckdb_result__to_integer(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
51
- static VALUE duckdb_result__to_bigint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
52
- static VALUE duckdb_result___to_hugeint_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
53
- static VALUE duckdb_result___to_decimal_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
54
- static VALUE duckdb_result__to_float(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
55
- static VALUE duckdb_result__to_double(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
56
- static VALUE duckdb_result__to_string(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
57
- static VALUE duckdb_result__to_string_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
58
- static VALUE duckdb_result__to_blob(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
37
+ static VALUE duckdb_result__return_type(VALUE oDuckDBResult);
38
+ static VALUE duckdb_result__statement_type(VALUE oDuckDBResult);
59
39
  static VALUE duckdb_result__enum_internal_type(VALUE oDuckDBResult, VALUE col_idx);
60
40
  static VALUE duckdb_result__enum_dictionary_size(VALUE oDuckDBResult, VALUE col_idx);
61
41
  static VALUE duckdb_result__enum_dictionary_value(VALUE oDuckDBResult, VALUE col_idx, VALUE idx);
62
42
 
43
+ static VALUE infinite_date_value(duckdb_date date);
63
44
  static VALUE vector_date(void *vector_data, idx_t row_idx);
64
45
  static VALUE vector_timestamp(void* vector_data, idx_t row_idx);
65
46
  static VALUE vector_time(void* vector_data, idx_t row_idx);
@@ -69,6 +50,7 @@ static VALUE vector_varchar(void* vector_data, idx_t row_idx);
69
50
  static VALUE vector_hugeint(void* vector_data, idx_t row_idx);
70
51
  static VALUE vector_uhugeint(void* vector_data, idx_t row_idx);
71
52
  static VALUE vector_decimal(duckdb_logical_type ty, void* vector_data, idx_t row_idx);
53
+ static VALUE infinite_timestamp_value(duckdb_timestamp timestamp);
72
54
  static VALUE vector_timestamp_s(void* vector_data, idx_t row_idx);
73
55
  static VALUE vector_timestamp_ms(void* vector_data, idx_t row_idx);
74
56
  static VALUE vector_timestamp_ns(void* vector_data, idx_t row_idx);
@@ -113,114 +95,6 @@ rubyDuckDBResult *get_struct_result(VALUE obj) {
113
95
  return ctx;
114
96
  }
115
97
 
116
- static VALUE to_ruby_obj_boolean(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
117
- #ifdef DUCKDB_API_NO_DEPRECATED
118
- return Qnil;
119
- #else
120
- rb_warn("private method `_to_boolean` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
121
- bool bval = duckdb_value_boolean(result, col_idx, row_idx);
122
- return bval ? Qtrue : Qfalse;
123
- #endif
124
- }
125
-
126
- static VALUE to_ruby_obj_smallint(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
127
- #ifdef DUCKDB_API_NO_DEPRECATED
128
- return Qnil;
129
- #else
130
- rb_warn("private method `_to_smallint` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
131
- int16_t i16val = duckdb_value_int16(result, col_idx, row_idx);
132
- return INT2FIX(i16val);
133
- #endif
134
- }
135
-
136
- static VALUE to_ruby_obj_utinyint(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
137
- #ifdef DUCKDB_API_NO_DEPRECATED
138
- return Qnil;
139
- #else
140
- rb_warn("private method `_to_utinyint` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
141
- uint8_t ui8val = duckdb_value_uint8(result, col_idx, row_idx);
142
- return UINT2NUM(ui8val);
143
- #endif
144
- }
145
-
146
- static VALUE to_ruby_obj_integer(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
147
- #ifdef DUCKDB_API_NO_DEPRECATED
148
- return Qnil;
149
- #else
150
- rb_warn("private method `_to_integer` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
151
- int32_t i32val = duckdb_value_int32(result, col_idx, row_idx);
152
- return INT2NUM(i32val);
153
- #endif
154
- }
155
-
156
- static VALUE to_ruby_obj_bigint(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
157
- #ifdef DUCKDB_API_NO_DEPRECATED
158
- return Qnil;
159
- #else
160
- rb_warn("private method `_to_bigint` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
161
- int64_t i64val = duckdb_value_int64(result, col_idx, row_idx);
162
- return LL2NUM(i64val);
163
- #endif
164
- }
165
-
166
- static VALUE to_ruby_obj_hugeint(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
167
- #ifdef DUCKDB_API_NO_DEPRECATED
168
- return Qnil;
169
- #else
170
- rb_warn("private method `__to_hugeint_internal` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
171
- duckdb_hugeint hugeint = duckdb_value_hugeint(result, col_idx, row_idx);
172
- return rb_ary_new3(2, ULL2NUM(hugeint.lower), LL2NUM(hugeint.upper));
173
- #endif
174
- }
175
-
176
- static VALUE to_ruby_obj_decimal(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
177
- #ifdef DUCKDB_API_NO_DEPRECATED
178
- return Qnil;
179
- #else
180
- rb_warn("private method `__to_decimal_internal` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
181
- duckdb_decimal decimal = duckdb_value_decimal(result, col_idx, row_idx);
182
- return rb_ary_new3(4, ULL2NUM(decimal.value.lower), LL2NUM(decimal.value.upper), UINT2NUM(decimal.width), UINT2NUM(decimal.scale));
183
- #endif
184
- }
185
-
186
- static VALUE to_ruby_obj_float(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
187
- #ifdef DUCKDB_API_NO_DEPRECATED
188
- return Qnil;
189
- #else
190
- rb_warn("private method `_to_float` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
191
- float fval = duckdb_value_float(result, col_idx, row_idx);
192
- return DBL2NUM(fval);
193
- #endif
194
- }
195
-
196
- static VALUE to_ruby_obj_double(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
197
- #ifdef DUCKDB_API_NO_DEPRECATED
198
- return Qnil;
199
- #else
200
- rb_warn("private method `_to_double` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
201
- double dval = duckdb_value_double(result, col_idx, row_idx);
202
- return DBL2NUM(dval);
203
- #endif
204
- }
205
-
206
- static VALUE to_ruby_obj_blob(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
207
-
208
- #ifdef DUCKDB_API_NO_DEPRECATED
209
- return Qnil;
210
- #else
211
- VALUE str;
212
- rb_warn("private method `_to_blob` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
213
- duckdb_blob bval = duckdb_value_blob(result, col_idx, row_idx);
214
- str = rb_str_new(bval.data, bval.size);
215
-
216
- if (bval.data) {
217
- duckdb_free(bval.data);
218
- }
219
-
220
- return str;
221
- #endif
222
- }
223
-
224
98
  /*
225
99
  * call-seq:
226
100
  * result.rows_changed -> integer
@@ -433,128 +307,16 @@ static VALUE duckdb_result__column_type(VALUE oDuckDBResult, VALUE col_idx) {
433
307
  return LL2NUM(duckdb_column_type(&(ctx->result), NUM2LL(col_idx)));
434
308
  }
435
309
 
436
- static VALUE duckdb_result__is_null(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
310
+ static VALUE duckdb_result__return_type(VALUE oDuckDBResult) {
437
311
  rubyDuckDBResult *ctx;
438
- bool is_null;
439
- #ifdef DUCKDB_API_NO_DEPRECATED
440
- return Qfalse;
441
- #else
442
- rb_warn("private method `_null?` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
443
312
  TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
444
-
445
- is_null = duckdb_value_is_null(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
446
- return is_null ? Qtrue : Qfalse;
447
- #endif
313
+ return INT2FIX(duckdb_result_return_type(ctx->result));
448
314
  }
449
315
 
450
- static VALUE duckdb_result__to_boolean(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
316
+ static VALUE duckdb_result__statement_type(VALUE oDuckDBResult) {
451
317
  rubyDuckDBResult *ctx;
452
318
  TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
453
-
454
- return to_ruby_obj_boolean(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx)) ? Qtrue : Qfalse;
455
- }
456
-
457
- static VALUE duckdb_result__to_smallint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
458
- rubyDuckDBResult *ctx;
459
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
460
-
461
- return to_ruby_obj_smallint(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
462
- }
463
-
464
- static VALUE duckdb_result__to_utinyint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
465
- rubyDuckDBResult *ctx;
466
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
467
-
468
- return to_ruby_obj_utinyint(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
469
- }
470
-
471
- static VALUE duckdb_result__to_integer(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
472
- rubyDuckDBResult *ctx;
473
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
474
-
475
- return to_ruby_obj_integer(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
476
- }
477
-
478
- static VALUE duckdb_result__to_bigint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
479
- rubyDuckDBResult *ctx;
480
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
481
-
482
- return to_ruby_obj_bigint(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
483
- }
484
-
485
- static VALUE duckdb_result___to_hugeint_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
486
- rubyDuckDBResult *ctx;
487
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
488
-
489
- return to_ruby_obj_hugeint(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
490
- }
491
-
492
- static VALUE duckdb_result___to_decimal_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
493
- rubyDuckDBResult *ctx;
494
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
495
-
496
- return to_ruby_obj_decimal(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
497
- }
498
-
499
- static VALUE duckdb_result__to_float(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
500
- rubyDuckDBResult *ctx;
501
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
502
-
503
- return to_ruby_obj_float(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
504
- }
505
-
506
- static VALUE duckdb_result__to_double(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
507
- rubyDuckDBResult *ctx;
508
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
509
-
510
- return to_ruby_obj_double(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
511
- }
512
-
513
- static VALUE duckdb_result__to_string(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
514
- rubyDuckDBResult *ctx;
515
- duckdb_string p;
516
- VALUE obj;
517
-
518
- #ifdef DUCKDB_API_NO_DEPRECATED
519
- return Qnil;
520
- #else
521
- rb_warn("private method `_to_string` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
522
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
523
-
524
- p = duckdb_value_string(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
525
- if (p.data) {
526
- obj = rb_utf8_str_new(p.data, p.size);
527
- duckdb_free(p.data);
528
- return obj;
529
- }
530
- #endif
531
- return Qnil;
532
- }
533
-
534
- static VALUE duckdb_result__to_string_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
535
- rubyDuckDBResult *ctx;
536
- duckdb_string p;
537
- VALUE obj;
538
- #ifdef DUCKDB_API_NO_DEPRECATED
539
- // duckdb_value_string_internal will be deprecated in the future.
540
- #else
541
- rb_warn("private method `_to_string_internal` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
542
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
543
-
544
- p = duckdb_value_string_internal(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
545
- if (p.data) {
546
- obj = rb_utf8_str_new(p.data, p.size);
547
- return obj;
548
- }
549
- #endif
550
- return Qnil;
551
- }
552
-
553
- static VALUE duckdb_result__to_blob(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
554
- rubyDuckDBResult *ctx;
555
- TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
556
-
557
- return to_ruby_obj_blob(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
319
+ return INT2FIX(duckdb_result_statement_type(ctx->result));
558
320
  }
559
321
 
560
322
  static VALUE duckdb_result__enum_internal_type(VALUE oDuckDBResult, VALUE col_idx) {
@@ -608,27 +370,47 @@ VALUE rbduckdb_create_result(void) {
608
370
  return allocate(cDuckDBResult);
609
371
  }
610
372
 
611
- static VALUE vector_date(void *vector_data, idx_t row_idx) {
612
- duckdb_date_struct date = duckdb_from_date(((duckdb_date *) vector_data)[row_idx]);
373
+ static VALUE infinite_date_value(duckdb_date date) {
374
+ if (duckdb_is_finite_date(date) == false) {
375
+ return rb_funcall(mDuckDBConverter, id__to_infinity, 1,
376
+ INT2NUM(date.days)
377
+ );
378
+ }
379
+ return Qnil;
380
+ }
613
381
 
614
- return rb_funcall(mDuckDBConverter, id__to_date, 3,
615
- INT2FIX(date.year),
616
- INT2FIX(date.month),
617
- INT2FIX(date.day)
618
- );
382
+ static VALUE vector_date(void *vector_data, idx_t row_idx) {
383
+ duckdb_date date = ((duckdb_date *) vector_data)[row_idx];
384
+ VALUE obj = infinite_date_value(date);
385
+
386
+ if (obj == Qnil) {
387
+ duckdb_date_struct date_st = duckdb_from_date(date);
388
+ obj = rb_funcall(mDuckDBConverter, id__to_date, 3,
389
+ INT2FIX(date_st.year),
390
+ INT2FIX(date_st.month),
391
+ INT2FIX(date_st.day)
392
+ );
393
+ }
394
+ return obj;
619
395
  }
620
396
 
621
397
  static VALUE vector_timestamp(void* vector_data, idx_t row_idx) {
622
- duckdb_timestamp_struct data = duckdb_from_timestamp(((duckdb_timestamp *)vector_data)[row_idx]);
623
- return rb_funcall(mDuckDBConverter, id__to_time, 7,
624
- INT2FIX(data.date.year),
625
- INT2FIX(data.date.month),
626
- INT2FIX(data.date.day),
627
- INT2FIX(data.time.hour),
628
- INT2FIX(data.time.min),
629
- INT2FIX(data.time.sec),
630
- INT2NUM(data.time.micros)
631
- );
398
+ duckdb_timestamp data = ((duckdb_timestamp *)vector_data)[row_idx];
399
+ VALUE obj = infinite_timestamp_value(data);
400
+
401
+ if (obj == Qnil) {
402
+ duckdb_timestamp_struct data_st = duckdb_from_timestamp(data);
403
+ return rb_funcall(mDuckDBConverter, id__to_time, 7,
404
+ INT2FIX(data_st.date.year),
405
+ INT2FIX(data_st.date.month),
406
+ INT2FIX(data_st.date.day),
407
+ INT2FIX(data_st.time.hour),
408
+ INT2FIX(data_st.time.min),
409
+ INT2FIX(data_st.time.sec),
410
+ INT2NUM(data_st.time.micros)
411
+ );
412
+ }
413
+ return obj;
632
414
  }
633
415
 
634
416
  static VALUE vector_time(void* vector_data, idx_t row_idx) {
@@ -723,11 +505,20 @@ static VALUE vector_decimal(duckdb_logical_type ty, void* vector_data, idx_t row
723
505
  );
724
506
  }
725
507
 
508
+ static VALUE infinite_timestamp_value(duckdb_timestamp timestamp) {
509
+ if (duckdb_is_finite_timestamp(timestamp) == false) {
510
+ return rb_funcall(mDuckDBConverter, id__to_infinity, 1,
511
+ LL2NUM(timestamp.micros)
512
+ );
513
+ }
514
+ return Qnil;
515
+ }
516
+
726
517
  static VALUE vector_timestamp_s(void* vector_data, idx_t row_idx) {
727
518
  duckdb_timestamp data = ((duckdb_timestamp *)vector_data)[row_idx];
728
519
  return rb_funcall(mDuckDBConverter, id__to_time_from_duckdb_timestamp_s, 1,
729
520
  LL2NUM(data.micros)
730
- );
521
+ );
731
522
  }
732
523
 
733
524
  static VALUE vector_timestamp_ms(void* vector_data, idx_t row_idx) {
@@ -1099,6 +890,7 @@ void rbduckdb_init_duckdb_result(void) {
1099
890
  id__to_time_from_duckdb_timestamp_ns = rb_intern("_to_time_from_duckdb_timestamp_ns");
1100
891
  id__to_time_from_duckdb_time_tz = rb_intern("_to_time_from_duckdb_time_tz");
1101
892
  id__to_time_from_duckdb_timestamp_tz = rb_intern("_to_time_from_duckdb_timestamp_tz");
893
+ id__to_infinity = rb_intern("_to_infinity");
1102
894
 
1103
895
  rb_define_alloc_func(cDuckDBResult, allocate);
1104
896
 
@@ -1110,20 +902,9 @@ void rbduckdb_init_duckdb_result(void) {
1110
902
  rb_define_method(cDuckDBResult, "chunk_each", duckdb_result_chunk_each, 0);
1111
903
  rb_define_private_method(cDuckDBResult, "_chunk_stream", duckdb_result__chunk_stream, 0);
1112
904
  rb_define_private_method(cDuckDBResult, "_column_type", duckdb_result__column_type, 1);
905
+ rb_define_private_method(cDuckDBResult, "_return_type", duckdb_result__return_type, 0);
906
+ rb_define_private_method(cDuckDBResult, "_statement_type", duckdb_result__statement_type, 0);
1113
907
 
1114
- rb_define_private_method(cDuckDBResult, "_null?", duckdb_result__is_null, 2); /* deprecated */
1115
- rb_define_private_method(cDuckDBResult, "_to_boolean", duckdb_result__to_boolean, 2); /* deprecated */
1116
- rb_define_private_method(cDuckDBResult, "_to_smallint", duckdb_result__to_smallint, 2); /* deprecated */
1117
- rb_define_private_method(cDuckDBResult, "_to_utinyint", duckdb_result__to_utinyint, 2); /* deprecated */
1118
- rb_define_private_method(cDuckDBResult, "_to_integer", duckdb_result__to_integer, 2); /* deprecated */
1119
- rb_define_private_method(cDuckDBResult, "_to_bigint", duckdb_result__to_bigint, 2); /* deprecated */
1120
- rb_define_private_method(cDuckDBResult, "__to_hugeint_internal", duckdb_result___to_hugeint_internal, 2); /* deprecated */
1121
- rb_define_private_method(cDuckDBResult, "__to_decimal_internal", duckdb_result___to_decimal_internal, 2); /* deprecated */
1122
- rb_define_private_method(cDuckDBResult, "_to_float", duckdb_result__to_float, 2); /* deprecated */
1123
- rb_define_private_method(cDuckDBResult, "_to_double", duckdb_result__to_double, 2); /* deprecated */
1124
- rb_define_private_method(cDuckDBResult, "_to_string", duckdb_result__to_string, 2); /* deprecated */
1125
- rb_define_private_method(cDuckDBResult, "_to_string_internal", duckdb_result__to_string_internal, 2); /* deprecated */
1126
- rb_define_private_method(cDuckDBResult, "_to_blob", duckdb_result__to_blob, 2); /* deprecated */
1127
908
  rb_define_private_method(cDuckDBResult, "_enum_internal_type", duckdb_result__enum_internal_type, 1);
1128
909
  rb_define_private_method(cDuckDBResult, "_enum_dictionary_size", duckdb_result__enum_dictionary_size, 1);
1129
910
  rb_define_private_method(cDuckDBResult, "_enum_dictionary_value", duckdb_result__enum_dictionary_value, 2);
@@ -15,6 +15,10 @@
15
15
  #define HAVE_DUCKDB_H_GE_V1_0_0 1
16
16
  #endif
17
17
 
18
+ #ifdef HAVE_DUCKDB_RESULT_ERROR_TYPE
19
+ #define HAVE_DUCKDB_H_GE_V1_1_0 1
20
+ #endif
21
+
18
22
  #include "./error.h"
19
23
  #include "./database.h"
20
24
  #include "./connection.h"
@@ -38,5 +42,7 @@ extern VALUE cDuckDBConfig;
38
42
  extern VALUE eDuckDBError;
39
43
  extern VALUE mDuckDBConverter;
40
44
  extern VALUE cDuckDBPreparedStatement;
45
+ extern VALUE PositiveInfinity;
46
+ extern VALUE NegativeInfinity;
41
47
 
42
48
  #endif
data/lib/duckdb/column.rb CHANGED
@@ -17,44 +17,8 @@ module DuckDB
17
17
  # columns.first.type #=> :integer
18
18
  #
19
19
  def type
20
- types = %i[
21
- invalid
22
- boolean
23
- tinyint
24
- smallint
25
- integer
26
- bigint
27
- utinyint
28
- usmallint
29
- uinteger
30
- ubigint
31
- float
32
- double
33
- timestamp
34
- date
35
- time
36
- interval
37
- hugeint
38
- varchar
39
- blob
40
- decimal
41
- timestamp_s
42
- timestamp_ms
43
- timestamp_ns
44
- enum
45
- list
46
- struct
47
- map
48
- uuid
49
- json
50
- ]
51
- if Gem::Version.new(DuckDB::LIBRARY_VERSION) == Gem::Version.new('0.10.0')
52
- types[17, 0] = :uhugeint
53
- end
54
- index = _type
55
- return :unknown if index >= types.size
56
-
57
- types[index]
20
+ type_id = _type
21
+ DuckDB::Converter::IntToSym.type_to_sym(type_id)
58
22
  end
59
23
  end
60
24
  end
data/lib/duckdb/config.rb CHANGED
@@ -1,64 +1,62 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DuckDB
4
- if defined?(DuckDB::Config)
5
- # The DuckDB::Config encapsulates DuckDB Configuration.
4
+ # The DuckDB::Config encapsulates DuckDB Configuration.
5
+ #
6
+ # require 'duckdb'
7
+ # config = DuckDB::Config.new
8
+ # config['default_order'] = 'DESC'
9
+ # db = DuckDB::Database.open(nil, config)
10
+ # con = db.connect
11
+ # con.query('CREATE TABLE numbers (number INTEGER)')
12
+ # con.query('INSERT INTO numbers VALUES (2), (1), (4), (3)')
13
+ #
14
+ # # number is ordered by descending.
15
+ # r = con.query('SELECT number FROM numbers ORDER BY number)
16
+ # r.first.first # => 4
17
+ class Config
18
+ class << self
19
+ #
20
+ # returns available configuration name and the description.
21
+ # The return value is array object. The first element is the configuration
22
+ # name. The second is the description.
23
+ #
24
+ # key, desc = DuckDB::Config.key_description(0)
25
+ # key # => "access_mode"
26
+ # desc # => "Access mode of the database ([AUTOMATIC], READ_ONLY or READ_WRITE)"
27
+ #
28
+ alias key_description get_config_flag
29
+
30
+ #
31
+ # returns the Hash object of all available configuration names and
32
+ # the descriptions.
33
+ #
34
+ # configs = DuckDB::Config.key_descriptions
35
+ # configs['default_order'] # => "The order type used when none is specified ([ASC] or DESC)"
36
+ #
37
+ def key_descriptions
38
+ @key_descriptions ||= (0...size).each_with_object({}) do |i, hash|
39
+ key, description = key_description(i)
40
+ hash[key] = description
41
+ end
42
+ end
43
+ end
44
+
45
+ #
46
+ # set configuration value
6
47
  #
7
- # require 'duckdb'
8
48
  # config = DuckDB::Config.new
49
+ # # config.set_config('default_order', 'DESC')
9
50
  # config['default_order'] = 'DESC'
51
+ #
10
52
  # db = DuckDB::Database.open(nil, config)
11
53
  # con = db.connect
12
54
  # con.query('CREATE TABLE numbers (number INTEGER)')
13
55
  # con.query('INSERT INTO numbers VALUES (2), (1), (4), (3)')
14
56
  #
15
- # # number is ordered by descending.
57
+ # # numbers are ordered by descending.
16
58
  # r = con.query('SELECT number FROM numbers ORDER BY number)
17
59
  # r.first.first # => 4
18
- class Config
19
- class << self
20
- #
21
- # returns available configuration name and the description.
22
- # The return value is array object. The first element is the configuration
23
- # name. The second is the description.
24
- #
25
- # key, desc = DuckDB::Config.key_description(0)
26
- # key # => "access_mode"
27
- # desc # => "Access mode of the database ([AUTOMATIC], READ_ONLY or READ_WRITE)"
28
- #
29
- alias key_description get_config_flag
30
-
31
- #
32
- # returns the Hash object of all available configuration names and
33
- # the descriptions.
34
- #
35
- # configs = DuckDB::Config.key_descriptions
36
- # configs['default_order'] # => "The order type used when none is specified ([ASC] or DESC)"
37
- #
38
- def key_descriptions
39
- @key_descriptions ||= (0...size).each_with_object({}) do |i, hash|
40
- key, description = key_description(i)
41
- hash[key] = description
42
- end
43
- end
44
- end
45
-
46
- #
47
- # set configuration value
48
- #
49
- # config = DuckDB::Config.new
50
- # # config.set_config('default_order', 'DESC')
51
- # config['default_order'] = 'DESC'
52
- #
53
- # db = DuckDB::Database.open(nil, config)
54
- # con = db.connect
55
- # con.query('CREATE TABLE numbers (number INTEGER)')
56
- # con.query('INSERT INTO numbers VALUES (2), (1), (4), (3)')
57
- #
58
- # # numbers are ordered by descending.
59
- # r = con.query('SELECT number FROM numbers ORDER BY number)
60
- # r.first.first # => 4
61
- alias []= set_config
62
- end
60
+ alias []= set_config
63
61
  end
64
62
  end
@@ -62,7 +62,6 @@ module DuckDB
62
62
  # This method returns DuckDB::PendingResult object.
63
63
  #
64
64
  # require 'duckdb'
65
- # DuckDB::Result.use_chunk_each = true # must be true
66
65
  # db = DuckDB::Database.open('duckdb_file')
67
66
  # con = db.connect
68
67
  #
@@ -98,6 +97,14 @@ module DuckDB
98
97
  # returns PreparedStatement object.
99
98
  # The first argument is SQL string.
100
99
  #
100
+ # require 'duckdb'
101
+ # db = DuckDB::Database.open('duckdb_file')
102
+ # con = db.connect
103
+ #
104
+ # sql = 'SELECT * FROM users WHERE name = $name AND email = $email'
105
+ # stmt = con.prepared_statement(sql)
106
+ # stmt.bind_args(name: 'Dave', email: 'dave@example.com')
107
+ # result = stmt.execute
101
108
  def prepared_statement(str)
102
109
  PreparedStatement.new(self, str)
103
110
  end
@@ -127,5 +134,6 @@ module DuckDB
127
134
  alias async_execute async_query
128
135
  alias open connect
129
136
  alias close disconnect
137
+ alias prepare prepared_statement
130
138
  end
131
139
  end