duckdb 0.3.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/ext/duckdb/result.c CHANGED
@@ -4,19 +4,39 @@ static VALUE cDuckDBResult;
4
4
 
5
5
  static void deallocate(void *ctx);
6
6
  static VALUE allocate(VALUE klass);
7
+ static size_t memsize(const void *p);
7
8
  static VALUE to_ruby_obj_boolean(duckdb_result *result, idx_t col_idx, idx_t row_idx);
8
9
  static VALUE to_ruby_obj_smallint(duckdb_result *result, idx_t col_idx, idx_t row_idx);
10
+ static VALUE to_ruby_obj_utinyint(duckdb_result *result, idx_t col_idx, idx_t row_idx);
9
11
  static VALUE to_ruby_obj_integer(duckdb_result *result, idx_t col_idx, idx_t row_idx);
10
12
  static VALUE to_ruby_obj_bigint(duckdb_result *result, idx_t col_idx, idx_t row_idx);
11
13
  static VALUE to_ruby_obj_float(duckdb_result *result, idx_t col_idx, idx_t row_idx);
12
14
  static VALUE to_ruby_obj_double(duckdb_result *result, idx_t col_idx, idx_t row_idx);
13
- static VALUE to_ruby_obj_string_from_blob(duckdb_result *result, idx_t col_idx, idx_t row_idx);
14
- static VALUE to_ruby_obj(duckdb_result *result, idx_t col_idx, idx_t row_idx);
15
- static VALUE row_array(rubyDuckDBResult *ctx, idx_t row_idx);
16
- static VALUE duckdb_result_row_size(VALUE oDuckDBResult, VALUE args, VALUE obj);
17
- static VALUE duckdb_result_each(VALUE oDuckDBResult);
15
+ static VALUE to_ruby_obj_blob(duckdb_result *result, idx_t col_idx, idx_t row_idx);
16
+ static VALUE duckdb_result_column_count(VALUE oDuckDBResult);
17
+ static VALUE duckdb_result_row_count(VALUE oDuckDBResult);
18
18
  static VALUE duckdb_result_rows_changed(VALUE oDuckDBResult);
19
19
  static VALUE duckdb_result_columns(VALUE oDuckDBResult);
20
+ static VALUE duckdb_result__column_type(VALUE oDuckDBResult, VALUE col_idx);
21
+ static VALUE duckdb_result__is_null(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
22
+ static VALUE duckdb_result__to_boolean(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
23
+ static VALUE duckdb_result__to_smallint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
24
+ static VALUE duckdb_result__to_utinyint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
25
+ static VALUE duckdb_result__to_integer(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
26
+ static VALUE duckdb_result__to_bigint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
27
+ static VALUE duckdb_result__to_float(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
28
+ static VALUE duckdb_result__to_double(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
29
+ static VALUE duckdb_result__to_string(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
30
+ static VALUE duckdb_result__to_blob(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
31
+ static VALUE duckdb_result__enum_internal_type(VALUE oDuckDBResult, VALUE col_idx);
32
+ static VALUE duckdb_result__enum_dictionary_size(VALUE oDuckDBResult, VALUE col_idx);
33
+ static VALUE duckdb_result__enum_dictionary_value(VALUE oDuckDBResult, VALUE col_idx, VALUE idx);
34
+
35
+ static const rb_data_type_t result_data_type = {
36
+ "DuckDB/Result",
37
+ {NULL, deallocate, memsize,},
38
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
39
+ };
20
40
 
21
41
  static void deallocate(void *ctx) {
22
42
  rubyDuckDBResult *p = (rubyDuckDBResult *)ctx;
@@ -27,7 +47,17 @@ static void deallocate(void *ctx) {
27
47
 
28
48
  static VALUE allocate(VALUE klass) {
29
49
  rubyDuckDBResult *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBResult));
30
- return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
50
+ return TypedData_Wrap_Struct(klass, &result_data_type, ctx);
51
+ }
52
+
53
+ static size_t memsize(const void *p) {
54
+ return sizeof(rubyDuckDBResult);
55
+ }
56
+
57
+ rubyDuckDBResult *get_struct_result(VALUE obj) {
58
+ rubyDuckDBResult *ctx;
59
+ TypedData_Get_Struct(obj, rubyDuckDBResult, &result_data_type, ctx);
60
+ return ctx;
31
61
  }
32
62
 
33
63
  static VALUE to_ruby_obj_boolean(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
@@ -40,6 +70,11 @@ static VALUE to_ruby_obj_smallint(duckdb_result *result, idx_t col_idx, idx_t ro
40
70
  return INT2FIX(i16val);
41
71
  }
42
72
 
73
+ static VALUE to_ruby_obj_utinyint(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
74
+ uint8_t ui8val = duckdb_value_uint8(result, col_idx, row_idx);
75
+ return UINT2NUM(ui8val);
76
+ }
77
+
43
78
  static VALUE to_ruby_obj_integer(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
44
79
  int32_t i32val = duckdb_value_int32(result, col_idx, row_idx);
45
80
  return INT2NUM(i32val);
@@ -60,7 +95,7 @@ static VALUE to_ruby_obj_double(duckdb_result *result, idx_t col_idx, idx_t row_
60
95
  return DBL2NUM(dval);
61
96
  }
62
97
 
63
- static VALUE to_ruby_obj_string_from_blob(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
98
+ static VALUE to_ruby_obj_blob(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
64
99
  VALUE str;
65
100
  duckdb_blob bval = duckdb_value_blob(result, col_idx, row_idx);
66
101
  str = rb_str_new(bval.data, bval.size);
@@ -72,73 +107,6 @@ static VALUE to_ruby_obj_string_from_blob(duckdb_result *result, idx_t col_idx,
72
107
  return str;
73
108
  }
74
109
 
75
- static VALUE to_ruby_obj(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
76
- char *p;
77
- VALUE obj = Qnil;
78
- if (duckdb_value_is_null(result, col_idx, row_idx)) {
79
- return obj;
80
- }
81
- switch(duckdb_column_type(result, col_idx)) {
82
- case DUCKDB_TYPE_BOOLEAN:
83
- return to_ruby_obj_boolean(result, col_idx, row_idx);
84
- case DUCKDB_TYPE_SMALLINT:
85
- return to_ruby_obj_smallint(result, col_idx, row_idx);
86
- case DUCKDB_TYPE_INTEGER:
87
- return to_ruby_obj_integer(result, col_idx, row_idx);
88
- case DUCKDB_TYPE_BIGINT:
89
- return to_ruby_obj_bigint(result, col_idx, row_idx);
90
- case DUCKDB_TYPE_FLOAT:
91
- return to_ruby_obj_float(result, col_idx, row_idx);
92
- case DUCKDB_TYPE_DOUBLE:
93
- return to_ruby_obj_double(result, col_idx, row_idx);
94
- case DUCKDB_TYPE_BLOB:
95
- return to_ruby_obj_string_from_blob(result, col_idx, row_idx);
96
- default:
97
- p = duckdb_value_varchar(result, col_idx, row_idx);
98
- if (p) {
99
- obj = rb_str_new2(p);
100
- duckdb_free(p);
101
- if (duckdb_column_type(result, col_idx) == DUCKDB_TYPE_HUGEINT) {
102
- obj = rb_funcall(obj, rb_intern("to_i"), 0);
103
- }
104
- }
105
- }
106
- return obj;
107
- }
108
-
109
- static VALUE row_array(rubyDuckDBResult *ctx, idx_t row_idx) {
110
- idx_t col_idx;
111
- idx_t column_count = duckdb_column_count(&(ctx->result));
112
-
113
- VALUE ary = rb_ary_new2(column_count);
114
- for(col_idx = 0; col_idx < column_count; col_idx++) {
115
- rb_ary_store(ary, col_idx, to_ruby_obj(&(ctx->result), col_idx, row_idx));
116
- }
117
- return ary;
118
- }
119
-
120
- static VALUE duckdb_result_row_size(VALUE oDuckDBResult, VALUE args, VALUE obj) {
121
- rubyDuckDBResult *ctx;
122
- Data_Get_Struct(oDuckDBResult, rubyDuckDBResult, ctx);
123
-
124
- return LONG2FIX(duckdb_row_count(&(ctx->result)));
125
- }
126
-
127
- static VALUE duckdb_result_each(VALUE oDuckDBResult) {
128
- rubyDuckDBResult *ctx;
129
- idx_t row_idx = 0;
130
- idx_t row_count = 0;
131
-
132
- RETURN_SIZED_ENUMERATOR(oDuckDBResult, 0, 0, duckdb_result_row_size);
133
-
134
- Data_Get_Struct(oDuckDBResult, rubyDuckDBResult, ctx);
135
- row_count = duckdb_row_count(&(ctx->result));
136
- for (row_idx = 0; row_idx < row_count; row_idx++) {
137
- rb_yield(row_array(ctx, row_idx));
138
- }
139
- return oDuckDBResult;
140
- }
141
-
142
110
  /*
143
111
  * call-seq:
144
112
  * result.rows_changed -> integer
@@ -163,10 +131,58 @@ static VALUE duckdb_result_each(VALUE oDuckDBResult) {
163
131
  */
164
132
  static VALUE duckdb_result_rows_changed(VALUE oDuckDBResult) {
165
133
  rubyDuckDBResult *ctx;
166
- Data_Get_Struct(oDuckDBResult, rubyDuckDBResult, ctx);
134
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
167
135
  return LL2NUM(duckdb_rows_changed(&(ctx->result)));
168
136
  }
169
137
 
138
+ /*
139
+ * call-seq:
140
+ * result.column_count -> Integer
141
+ *
142
+ * Returns the column size of the result.
143
+ *
144
+ * DuckDB::Database.open do |db|
145
+ * db.connect do |con|
146
+ * r = con.query('CREATE TABLE t2 (id INT, name VARCHAR(128))')
147
+ * r = con.query("INSERT INTO t2 VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Catherine')")
148
+ * r = con.query('SELECT id FROM t2')
149
+ * r.column_count # => 1
150
+ * r = con.query('SELECT id, name FROM t2')
151
+ * r.column_count # => 2
152
+ * end
153
+ * end
154
+ *
155
+ */
156
+ static VALUE duckdb_result_column_count(VALUE oDuckDBResult) {
157
+ rubyDuckDBResult *ctx;
158
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
159
+ return LL2NUM(duckdb_column_count(&(ctx->result)));
160
+ }
161
+
162
+ /*
163
+ * call-seq:
164
+ * result.row_count -> Integer
165
+ *
166
+ * Returns the column size of the result.
167
+ *
168
+ * DuckDB::Database.open do |db|
169
+ * db.connect do |con|
170
+ * r = con.query('CREATE TABLE t2 (id INT, name VARCHAR(128))')
171
+ * r = con.query("INSERT INTO t2 VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Catherine')")
172
+ * r = con.query('SELECT * FROM t2')
173
+ * r.row_count # => 3
174
+ * r = con.query('SELECT * FROM t2 where id = 1')
175
+ * r.row_count # => 1
176
+ * end
177
+ * end
178
+ *
179
+ */
180
+ static VALUE duckdb_result_row_count(VALUE oDuckDBResult) {
181
+ rubyDuckDBResult *ctx;
182
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
183
+ return LL2NUM(duckdb_row_count(&(ctx->result)));
184
+ }
185
+
170
186
  /*
171
187
  * call-seq:
172
188
  * result.columns -> DuckDB::Column[]
@@ -176,7 +192,7 @@ static VALUE duckdb_result_rows_changed(VALUE oDuckDBResult) {
176
192
  */
177
193
  static VALUE duckdb_result_columns(VALUE oDuckDBResult) {
178
194
  rubyDuckDBResult *ctx;
179
- Data_Get_Struct(oDuckDBResult, rubyDuckDBResult, ctx);
195
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
180
196
 
181
197
  idx_t col_idx;
182
198
  idx_t column_count = duckdb_column_count(&(ctx->result));
@@ -189,6 +205,136 @@ static VALUE duckdb_result_columns(VALUE oDuckDBResult) {
189
205
  return ary;
190
206
  }
191
207
 
208
+ static VALUE duckdb_result__column_type(VALUE oDuckDBResult, VALUE col_idx) {
209
+ rubyDuckDBResult *ctx;
210
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
211
+ return LL2NUM(duckdb_column_type(&(ctx->result), NUM2LL(col_idx)));
212
+ }
213
+
214
+ static VALUE duckdb_result__is_null(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
215
+ rubyDuckDBResult *ctx;
216
+ bool is_null;
217
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
218
+
219
+ is_null = duckdb_value_is_null(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
220
+ return is_null ? Qtrue : Qfalse;
221
+ }
222
+
223
+ static VALUE duckdb_result__to_boolean(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
224
+ rubyDuckDBResult *ctx;
225
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
226
+
227
+ return to_ruby_obj_boolean(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx)) ? Qtrue : Qfalse;
228
+ }
229
+
230
+ static VALUE duckdb_result__to_smallint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
231
+ rubyDuckDBResult *ctx;
232
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
233
+
234
+ return to_ruby_obj_smallint(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
235
+ }
236
+
237
+ static VALUE duckdb_result__to_utinyint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
238
+ rubyDuckDBResult *ctx;
239
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
240
+
241
+ return to_ruby_obj_utinyint(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
242
+ }
243
+
244
+ static VALUE duckdb_result__to_integer(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
245
+ rubyDuckDBResult *ctx;
246
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
247
+
248
+ return to_ruby_obj_integer(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
249
+ }
250
+
251
+ static VALUE duckdb_result__to_bigint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
252
+ rubyDuckDBResult *ctx;
253
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
254
+
255
+ return to_ruby_obj_bigint(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
256
+ }
257
+
258
+ static VALUE duckdb_result__to_float(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
259
+ rubyDuckDBResult *ctx;
260
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
261
+
262
+ return to_ruby_obj_float(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
263
+ }
264
+
265
+ static VALUE duckdb_result__to_double(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
266
+ rubyDuckDBResult *ctx;
267
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
268
+
269
+ return to_ruby_obj_double(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
270
+ }
271
+
272
+ static VALUE duckdb_result__to_string(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
273
+ rubyDuckDBResult *ctx;
274
+ char *p;
275
+ VALUE obj;
276
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
277
+
278
+ p = duckdb_value_varchar(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
279
+ if (p) {
280
+ obj = rb_utf8_str_new_cstr(p);
281
+ duckdb_free(p);
282
+ return obj;
283
+ }
284
+ return Qnil;
285
+ }
286
+
287
+ static VALUE duckdb_result__to_blob(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
288
+ rubyDuckDBResult *ctx;
289
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
290
+
291
+ return to_ruby_obj_blob(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
292
+ }
293
+
294
+ static VALUE duckdb_result__enum_internal_type(VALUE oDuckDBResult, VALUE col_idx) {
295
+ rubyDuckDBResult *ctx;
296
+ VALUE type = Qnil;
297
+ duckdb_logical_type logical_type;
298
+
299
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
300
+ logical_type = duckdb_column_logical_type(&(ctx->result), NUM2LL(col_idx));
301
+ if (logical_type) {
302
+ type = LL2NUM(duckdb_enum_internal_type(logical_type));
303
+ }
304
+ return type;
305
+ }
306
+
307
+ static VALUE duckdb_result__enum_dictionary_size(VALUE oDuckDBResult, VALUE col_idx) {
308
+ rubyDuckDBResult *ctx;
309
+ VALUE size = Qnil;
310
+ duckdb_logical_type logical_type;
311
+
312
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
313
+ logical_type = duckdb_column_logical_type(&(ctx->result), NUM2LL(col_idx));
314
+ if (logical_type) {
315
+ size = UINT2NUM(duckdb_enum_dictionary_size(logical_type));
316
+ }
317
+ return size;
318
+ }
319
+
320
+ static VALUE duckdb_result__enum_dictionary_value(VALUE oDuckDBResult, VALUE col_idx, VALUE idx) {
321
+ rubyDuckDBResult *ctx;
322
+ VALUE value = Qnil;
323
+ duckdb_logical_type logical_type;
324
+ char *p;
325
+
326
+ TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
327
+ logical_type = duckdb_column_logical_type(&(ctx->result), NUM2LL(col_idx));
328
+ if (logical_type) {
329
+ p = duckdb_enum_dictionary_value(logical_type, NUM2LL(idx));
330
+ if (p) {
331
+ value = rb_utf8_str_new_cstr(p);
332
+ duckdb_free(p);
333
+ }
334
+ }
335
+ return value;
336
+ }
337
+
192
338
  VALUE create_result(void) {
193
339
  return allocate(cDuckDBResult);
194
340
  }
@@ -197,7 +343,22 @@ void init_duckdb_result(void) {
197
343
  cDuckDBResult = rb_define_class_under(mDuckDB, "Result", rb_cObject);
198
344
  rb_define_alloc_func(cDuckDBResult, allocate);
199
345
 
200
- rb_define_method(cDuckDBResult, "each", duckdb_result_each, 0);
346
+ rb_define_method(cDuckDBResult, "column_count", duckdb_result_column_count, 0);
347
+ rb_define_method(cDuckDBResult, "row_count", duckdb_result_row_count, 0);
201
348
  rb_define_method(cDuckDBResult, "rows_changed", duckdb_result_rows_changed, 0);
202
349
  rb_define_method(cDuckDBResult, "columns", duckdb_result_columns, 0);
350
+ rb_define_private_method(cDuckDBResult, "_column_type", duckdb_result__column_type, 1);
351
+ rb_define_private_method(cDuckDBResult, "_null?", duckdb_result__is_null, 2);
352
+ rb_define_private_method(cDuckDBResult, "_to_boolean", duckdb_result__to_boolean, 2);
353
+ rb_define_private_method(cDuckDBResult, "_to_smallint", duckdb_result__to_smallint, 2);
354
+ rb_define_private_method(cDuckDBResult, "_to_utinyint", duckdb_result__to_utinyint, 2);
355
+ rb_define_private_method(cDuckDBResult, "_to_integer", duckdb_result__to_integer, 2);
356
+ rb_define_private_method(cDuckDBResult, "_to_bigint", duckdb_result__to_bigint, 2);
357
+ rb_define_private_method(cDuckDBResult, "_to_float", duckdb_result__to_float, 2);
358
+ rb_define_private_method(cDuckDBResult, "_to_double", duckdb_result__to_double, 2);
359
+ rb_define_private_method(cDuckDBResult, "_to_string", duckdb_result__to_string, 2);
360
+ rb_define_private_method(cDuckDBResult, "_to_blob", duckdb_result__to_blob, 2);
361
+ rb_define_private_method(cDuckDBResult, "_enum_internal_type", duckdb_result__enum_internal_type, 1);
362
+ rb_define_private_method(cDuckDBResult, "_enum_dictionary_size", duckdb_result__enum_dictionary_size, 1);
363
+ rb_define_private_method(cDuckDBResult, "_enum_dictionary_value", duckdb_result__enum_dictionary_value, 2);
203
364
  }
data/ext/duckdb/result.h CHANGED
@@ -7,6 +7,7 @@ struct _rubyDuckDBResult {
7
7
 
8
8
  typedef struct _rubyDuckDBResult rubyDuckDBResult;
9
9
 
10
+ rubyDuckDBResult *get_struct_result(VALUE obj);
10
11
  void init_duckdb_result(void);
11
12
  VALUE create_result(void);
12
13
 
@@ -18,13 +18,8 @@
18
18
 
19
19
  #include "./blob.h"
20
20
  #include "./appender.h"
21
-
22
- #ifdef HAVE_DUCKDB_CREATE_CONFIG
23
-
24
21
  #include "./config.h"
25
22
 
26
- #endif /* HAVE_DUCKDB_CREATE_CONFIG */
27
-
28
23
  extern VALUE mDuckDB;
29
24
  extern VALUE cDuckDBDatabase;
30
25
  extern VALUE cDuckDBConnection;
data/ext/duckdb/util.c CHANGED
@@ -1,7 +1,5 @@
1
1
  #include "ruby-duckdb.h"
2
2
 
3
- #ifdef HAVE_DUCKDB_APPEND_DATE
4
-
5
3
  duckdb_date to_duckdb_date_from_value(VALUE year, VALUE month, VALUE day) {
6
4
  duckdb_date_struct dt_struct;
7
5
 
@@ -42,4 +40,3 @@ void to_duckdb_interval_from_value(duckdb_interval* interval, VALUE months, VALU
42
40
  interval->days = NUM2INT(days);
43
41
  interval->micros = NUM2LL(micros);
44
42
  }
45
- #endif
data/ext/duckdb/util.h CHANGED
@@ -1,13 +1,9 @@
1
1
  #ifndef RUBY_DUCKDB_UTIL_H
2
2
  #define RUBY_DUCKDB_UTIL_H
3
3
 
4
- #ifdef HAVE_DUCKDB_APPEND_DATE
5
-
6
4
  duckdb_date to_duckdb_date_from_value(VALUE year, VALUE month, VALUE day);
7
5
  duckdb_time to_duckdb_time_from_value(VALUE hour, VALUE min, VALUE sec, VALUE micros);
8
6
  duckdb_timestamp to_duckdb_timestamp_from_value(VALUE year, VALUE month, VALUE day, VALUE hour, VALUE min, VALUE sec, VALUE micros);
9
7
  void to_duckdb_interval_from_value(duckdb_interval* interval, VALUE months, VALUE days, VALUE micros);
10
8
 
11
9
  #endif
12
-
13
- #endif
data/lib/duckdb/result.rb CHANGED
@@ -20,5 +20,55 @@ module DuckDB
20
20
  # end
21
21
  class Result
22
22
  include Enumerable
23
+
24
+ ToRuby = {
25
+ 1 => :_to_boolean,
26
+ 3 => :_to_smallint,
27
+ 4 => :_to_integer,
28
+ 5 => :_to_bigint,
29
+ 10 => :_to_float,
30
+ 11 => :_to_double,
31
+ 16 => :_to_hugeint,
32
+ 18 => :_to_blob,
33
+ }
34
+
35
+ ToRuby.default = :_to_string
36
+
37
+ alias column_size column_count
38
+ alias row_size row_count
39
+
40
+ def each
41
+ return to_enum { row_size } unless block_given?
42
+
43
+ row_count.times do |row_index|
44
+ yield row(row_index)
45
+ end
46
+ end
47
+
48
+ def row(row_index)
49
+ row = []
50
+ column_count.times do |col_index|
51
+ row << (_null?(row_index, col_index) ? nil : to_value(row_index, col_index))
52
+ end
53
+ row
54
+ end
55
+
56
+ def to_value(row_index, col_index)
57
+ send(ToRuby[_column_type(col_index)], row_index, col_index)
58
+ end
59
+
60
+ def enum_dictionary_values(col_index)
61
+ values = []
62
+ _enum_dictionary_size(col_index).times do |i|
63
+ values << _enum_dictionary_value(col_index, i)
64
+ end
65
+ values
66
+ end
67
+
68
+ private
69
+
70
+ def _to_hugeint(row, col)
71
+ _to_string(row, col).to_i
72
+ end
23
73
  end
24
74
  end
@@ -1,5 +1,5 @@
1
1
  module DuckDB
2
2
  # The version string of ruby-duckdb.
3
3
  # Currently, ruby-duckdb is NOT semantic versioning.
4
- VERSION = '0.3.4.0'.freeze
4
+ VERSION = '0.5.1'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duckdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Suketa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-29 00:00:00.000000000 Z
11
+ date: 2022-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: '2.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: '2.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
- rubygems_version: 3.3.10
147
+ rubygems_version: 3.3.22
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: This module is Ruby binding for DuckDB database engine.