duckdb 2.0.0.0 → 2.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/ext/duckdb/aggregate_function.c +40 -78
- data/ext/duckdb/appender.c +39 -126
- data/ext/duckdb/connection.c +17 -54
- data/ext/duckdb/conveter.c +39 -76
- data/ext/duckdb/function_executor.c +214 -248
- data/ext/duckdb/function_executor.h +10 -0
- data/ext/duckdb/function_vector.c +26 -0
- data/ext/duckdb/function_vector.h +18 -0
- data/ext/duckdb/logical_type.c +88 -170
- data/ext/duckdb/prepared_statement.c +37 -138
- data/ext/duckdb/result.c +15 -84
- data/ext/duckdb/scalar_function.c +9 -69
- data/ext/duckdb/table_function.c +33 -82
- data/ext/duckdb/util.c +53 -2
- data/lib/duckdb/interval.rb +2 -28
- data/lib/duckdb/prepared_statement.rb +5 -0
- data/lib/duckdb/scalar_function_set.rb +1 -2
- data/lib/duckdb/version.rb +1 -1
- metadata +1 -1
|
@@ -253,140 +253,102 @@ static VALUE prepared_statement_clear_bindings(VALUE self) {
|
|
|
253
253
|
return self;
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
static
|
|
256
|
+
static duckdb_prepared_statement prepared_statement_of(VALUE self) {
|
|
257
257
|
rubyDuckDBPreparedStatement *ctx;
|
|
258
|
+
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
|
|
259
|
+
return ctx->prepared_statement;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
static void raise_if_bind_failed(duckdb_state state, idx_t idx) {
|
|
263
|
+
if (state == DuckDBError) {
|
|
264
|
+
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
static VALUE prepared_statement_bind_bool(VALUE self, VALUE vidx, VALUE val) {
|
|
258
269
|
idx_t idx = check_index(vidx);
|
|
259
270
|
|
|
260
|
-
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
|
|
261
271
|
if (val != Qtrue && val != Qfalse) {
|
|
262
272
|
rb_raise(rb_eArgError, "binding value must be boolean");
|
|
263
273
|
}
|
|
264
274
|
|
|
265
|
-
|
|
266
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
267
|
-
}
|
|
275
|
+
raise_if_bind_failed(duckdb_bind_boolean(prepared_statement_of(self), idx, (val == Qtrue)), idx);
|
|
268
276
|
return self;
|
|
269
277
|
}
|
|
270
278
|
|
|
271
279
|
static VALUE prepared_statement_bind_int8(VALUE self, VALUE vidx, VALUE val) {
|
|
272
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
273
280
|
idx_t idx = check_index(vidx);
|
|
274
281
|
int8_t i8val = (int8_t)NUM2INT(val);
|
|
275
282
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (duckdb_bind_int8(ctx->prepared_statement, idx, i8val) == DuckDBError) {
|
|
279
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
280
|
-
}
|
|
283
|
+
raise_if_bind_failed(duckdb_bind_int8(prepared_statement_of(self), idx, i8val), idx);
|
|
281
284
|
return self;
|
|
282
285
|
}
|
|
283
286
|
|
|
284
|
-
|
|
285
287
|
static VALUE prepared_statement_bind_int16(VALUE self, VALUE vidx, VALUE val) {
|
|
286
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
287
288
|
idx_t idx = check_index(vidx);
|
|
288
289
|
int16_t i16val = NUM2INT(val);
|
|
289
290
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if (duckdb_bind_int16(ctx->prepared_statement, idx, i16val) == DuckDBError) {
|
|
293
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
294
|
-
}
|
|
291
|
+
raise_if_bind_failed(duckdb_bind_int16(prepared_statement_of(self), idx, i16val), idx);
|
|
295
292
|
return self;
|
|
296
293
|
}
|
|
297
294
|
|
|
298
295
|
static VALUE prepared_statement_bind_int32(VALUE self, VALUE vidx, VALUE val) {
|
|
299
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
300
296
|
idx_t idx = check_index(vidx);
|
|
301
297
|
int32_t i32val = NUM2INT(val);
|
|
302
298
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (duckdb_bind_int32(ctx->prepared_statement, idx, i32val) == DuckDBError) {
|
|
306
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
307
|
-
}
|
|
299
|
+
raise_if_bind_failed(duckdb_bind_int32(prepared_statement_of(self), idx, i32val), idx);
|
|
308
300
|
return self;
|
|
309
301
|
}
|
|
310
302
|
|
|
311
303
|
static VALUE prepared_statement_bind_int64(VALUE self, VALUE vidx, VALUE val) {
|
|
312
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
313
304
|
idx_t idx = check_index(vidx);
|
|
314
305
|
int64_t i64val = NUM2LL(val);
|
|
315
306
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if (duckdb_bind_int64(ctx->prepared_statement, idx, i64val) == DuckDBError) {
|
|
319
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
320
|
-
}
|
|
307
|
+
raise_if_bind_failed(duckdb_bind_int64(prepared_statement_of(self), idx, i64val), idx);
|
|
321
308
|
return self;
|
|
322
309
|
}
|
|
323
310
|
|
|
324
311
|
static VALUE prepared_statement_bind_float(VALUE self, VALUE vidx, VALUE val) {
|
|
325
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
326
312
|
idx_t idx = check_index(vidx);
|
|
327
313
|
double dbl = NUM2DBL(val);
|
|
328
314
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (duckdb_bind_float(ctx->prepared_statement, idx, (float)dbl) == DuckDBError) {
|
|
332
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
333
|
-
}
|
|
315
|
+
raise_if_bind_failed(duckdb_bind_float(prepared_statement_of(self), idx, (float)dbl), idx);
|
|
334
316
|
return self;
|
|
335
317
|
}
|
|
336
318
|
|
|
337
319
|
static VALUE prepared_statement_bind_double(VALUE self, VALUE vidx, VALUE val) {
|
|
338
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
339
320
|
idx_t idx = check_index(vidx);
|
|
340
321
|
double dbl = NUM2DBL(val);
|
|
341
322
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
if (duckdb_bind_double(ctx->prepared_statement, idx, dbl) == DuckDBError) {
|
|
345
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
346
|
-
}
|
|
323
|
+
raise_if_bind_failed(duckdb_bind_double(prepared_statement_of(self), idx, dbl), idx);
|
|
347
324
|
return self;
|
|
348
325
|
}
|
|
349
326
|
|
|
350
327
|
static VALUE prepared_statement_bind_varchar(VALUE self, VALUE vidx, VALUE str) {
|
|
351
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
352
328
|
idx_t idx = check_index(vidx);
|
|
353
329
|
const char *pstr;
|
|
354
330
|
long len;
|
|
355
331
|
|
|
356
|
-
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
|
|
357
|
-
|
|
358
332
|
/* Pass the byte length: duckdb_bind_varchar stops at the first NUL, so an
|
|
359
333
|
* embedded one stored a prefix of the String the caller had validated. */
|
|
360
334
|
pstr = StringValuePtr(str);
|
|
361
335
|
len = RSTRING_LEN(str);
|
|
362
336
|
|
|
363
|
-
|
|
364
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
365
|
-
}
|
|
337
|
+
raise_if_bind_failed(duckdb_bind_varchar_length(prepared_statement_of(self), idx, pstr, (idx_t)len), idx);
|
|
366
338
|
return self;
|
|
367
339
|
}
|
|
368
340
|
|
|
369
341
|
static VALUE prepared_statement_bind_blob(VALUE self, VALUE vidx, VALUE blob) {
|
|
370
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
371
342
|
idx_t idx = check_index(vidx);
|
|
372
343
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
if (duckdb_bind_blob(ctx->prepared_statement, idx, (const void *)StringValuePtr(blob), (idx_t)RSTRING_LEN(blob)) == DuckDBError) {
|
|
376
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
377
|
-
}
|
|
344
|
+
raise_if_bind_failed(duckdb_bind_blob(prepared_statement_of(self), idx, (const void *)StringValuePtr(blob), (idx_t)RSTRING_LEN(blob)), idx);
|
|
378
345
|
return self;
|
|
379
346
|
}
|
|
380
347
|
|
|
381
348
|
static VALUE prepared_statement_bind_null(VALUE self, VALUE vidx) {
|
|
382
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
383
349
|
idx_t idx = check_index(vidx);
|
|
384
350
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
if (duckdb_bind_null(ctx->prepared_statement, idx) == DuckDBError) {
|
|
388
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
389
|
-
}
|
|
351
|
+
raise_if_bind_failed(duckdb_bind_null(prepared_statement_of(self), idx), idx);
|
|
390
352
|
return self;
|
|
391
353
|
}
|
|
392
354
|
|
|
@@ -491,91 +453,61 @@ static VALUE prepared_statement__param_type(VALUE self, VALUE vidx) {
|
|
|
491
453
|
|
|
492
454
|
/* :nodoc: */
|
|
493
455
|
static VALUE prepared_statement__bind_uint8(VALUE self, VALUE vidx, VALUE val) {
|
|
494
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
495
456
|
idx_t idx = check_index(vidx);
|
|
496
457
|
uint8_t ui8val = (uint8_t)NUM2UINT(val);
|
|
497
458
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
if (duckdb_bind_uint8(ctx->prepared_statement, idx, ui8val) == DuckDBError) {
|
|
501
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
502
|
-
}
|
|
459
|
+
raise_if_bind_failed(duckdb_bind_uint8(prepared_statement_of(self), idx, ui8val), idx);
|
|
503
460
|
return self;
|
|
504
461
|
}
|
|
505
462
|
|
|
506
463
|
/* :nodoc: */
|
|
507
464
|
static VALUE prepared_statement__bind_uint16(VALUE self, VALUE vidx, VALUE val) {
|
|
508
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
509
465
|
idx_t idx = check_index(vidx);
|
|
510
466
|
uint16_t ui16val = (uint16_t)NUM2UINT(val);
|
|
511
467
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
if (duckdb_bind_uint16(ctx->prepared_statement, idx, ui16val) == DuckDBError) {
|
|
515
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
516
|
-
}
|
|
468
|
+
raise_if_bind_failed(duckdb_bind_uint16(prepared_statement_of(self), idx, ui16val), idx);
|
|
517
469
|
return self;
|
|
518
470
|
}
|
|
519
471
|
|
|
520
472
|
/* :nodoc: */
|
|
521
473
|
static VALUE prepared_statement__bind_uint32(VALUE self, VALUE vidx, VALUE val) {
|
|
522
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
523
474
|
idx_t idx = check_index(vidx);
|
|
524
475
|
uint32_t ui32val = (uint32_t)NUM2UINT(val);
|
|
525
476
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
if (duckdb_bind_uint32(ctx->prepared_statement, idx, ui32val) == DuckDBError) {
|
|
529
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
530
|
-
}
|
|
477
|
+
raise_if_bind_failed(duckdb_bind_uint32(prepared_statement_of(self), idx, ui32val), idx);
|
|
531
478
|
return self;
|
|
532
479
|
}
|
|
533
480
|
|
|
534
481
|
/* :nodoc: */
|
|
535
482
|
static VALUE prepared_statement__bind_uint64(VALUE self, VALUE vidx, VALUE val) {
|
|
536
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
537
483
|
idx_t idx = check_index(vidx);
|
|
538
484
|
uint64_t ui64val = (uint64_t)NUM2ULL(val);
|
|
539
485
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
if (duckdb_bind_uint64(ctx->prepared_statement, idx, ui64val) == DuckDBError) {
|
|
543
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
544
|
-
}
|
|
486
|
+
raise_if_bind_failed(duckdb_bind_uint64(prepared_statement_of(self), idx, ui64val), idx);
|
|
545
487
|
return self;
|
|
546
488
|
}
|
|
547
489
|
|
|
548
490
|
/* :nodoc: */
|
|
549
491
|
static VALUE prepared_statement__bind_date(VALUE self, VALUE vidx, VALUE year, VALUE month, VALUE day) {
|
|
550
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
551
492
|
duckdb_date dt;
|
|
552
493
|
idx_t idx = check_index(vidx);
|
|
553
494
|
|
|
554
495
|
dt = rbduckdb_to_duckdb_date_from_value(year, month, day);
|
|
555
496
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
if (duckdb_bind_date(ctx->prepared_statement, idx, dt) == DuckDBError) {
|
|
559
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
560
|
-
}
|
|
497
|
+
raise_if_bind_failed(duckdb_bind_date(prepared_statement_of(self), idx, dt), idx);
|
|
561
498
|
|
|
562
499
|
return self;
|
|
563
500
|
}
|
|
564
501
|
|
|
565
502
|
/* :nodoc: */
|
|
566
503
|
static VALUE prepared_statement__bind_time(VALUE self, VALUE vidx, VALUE hour, VALUE min, VALUE sec, VALUE micros){
|
|
567
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
568
504
|
duckdb_time time;
|
|
569
505
|
|
|
570
506
|
idx_t idx = check_index(vidx);
|
|
571
507
|
|
|
572
508
|
time = rbduckdb_to_duckdb_time_from_value(hour, min, sec, micros);
|
|
573
509
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
if (duckdb_bind_time(ctx->prepared_statement, idx, time) == DuckDBError) {
|
|
577
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
578
|
-
}
|
|
510
|
+
raise_if_bind_failed(duckdb_bind_time(prepared_statement_of(self), idx, time), idx);
|
|
579
511
|
|
|
580
512
|
return self;
|
|
581
513
|
}
|
|
@@ -583,62 +515,45 @@ static VALUE prepared_statement__bind_time(VALUE self, VALUE vidx, VALUE hour, V
|
|
|
583
515
|
/* :nodoc: */
|
|
584
516
|
static VALUE prepared_statement__bind_timestamp(VALUE self, VALUE vidx, VALUE year, VALUE month, VALUE day, VALUE hour, VALUE min, VALUE sec, VALUE micros) {
|
|
585
517
|
duckdb_timestamp timestamp;
|
|
586
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
587
518
|
idx_t idx = check_index(vidx);
|
|
588
519
|
|
|
589
520
|
timestamp = rbduckdb_to_duckdb_timestamp_from_value(year, month, day, hour, min, sec, micros);
|
|
590
|
-
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
|
|
591
521
|
|
|
592
|
-
|
|
593
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
594
|
-
}
|
|
522
|
+
raise_if_bind_failed(duckdb_bind_timestamp(prepared_statement_of(self), idx, timestamp), idx);
|
|
595
523
|
return self;
|
|
596
524
|
}
|
|
597
525
|
|
|
598
526
|
/* :nodoc: */
|
|
599
527
|
static VALUE prepared_statement__bind_timestamp_tz(VALUE self, VALUE vidx, VALUE year, VALUE month, VALUE day, VALUE hour, VALUE min, VALUE sec, VALUE micros) {
|
|
600
528
|
duckdb_timestamp timestamp_tz;
|
|
601
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
602
529
|
idx_t idx = check_index(vidx);
|
|
603
530
|
|
|
604
531
|
timestamp_tz = rbduckdb_to_duckdb_timestamp_from_value(year, month, day, hour, min, sec, micros);
|
|
605
|
-
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
|
|
606
532
|
|
|
607
|
-
|
|
608
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
609
|
-
}
|
|
533
|
+
raise_if_bind_failed(duckdb_bind_timestamp_tz(prepared_statement_of(self), idx, timestamp_tz), idx);
|
|
610
534
|
return self;
|
|
611
535
|
}
|
|
612
536
|
|
|
613
537
|
/* :nodoc: */
|
|
614
538
|
static VALUE prepared_statement__bind_interval(VALUE self, VALUE vidx, VALUE months, VALUE days, VALUE micros) {
|
|
615
539
|
duckdb_interval interval;
|
|
616
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
617
540
|
idx_t idx = check_index(vidx);
|
|
618
541
|
|
|
619
|
-
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
|
|
620
|
-
|
|
621
542
|
rbduckdb_to_duckdb_interval_from_value(&interval, months, days, micros);
|
|
622
543
|
|
|
623
|
-
|
|
624
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
625
|
-
}
|
|
544
|
+
raise_if_bind_failed(duckdb_bind_interval(prepared_statement_of(self), idx, interval), idx);
|
|
626
545
|
return self;
|
|
627
546
|
}
|
|
628
547
|
|
|
629
548
|
/* :nodoc: */
|
|
630
549
|
static VALUE prepared_statement__bind_hugeint(VALUE self, VALUE vidx, VALUE lower, VALUE upper) {
|
|
631
550
|
duckdb_hugeint hugeint;
|
|
632
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
633
551
|
idx_t idx = check_index(vidx);
|
|
634
552
|
|
|
635
|
-
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
|
|
636
553
|
hugeint.lower = NUM2ULL(lower);
|
|
637
554
|
hugeint.upper = NUM2LL(upper);
|
|
638
555
|
|
|
639
|
-
|
|
640
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
641
|
-
}
|
|
556
|
+
raise_if_bind_failed(duckdb_bind_hugeint(prepared_statement_of(self), idx, hugeint), idx);
|
|
642
557
|
|
|
643
558
|
return self;
|
|
644
559
|
}
|
|
@@ -646,16 +561,12 @@ static VALUE prepared_statement__bind_hugeint(VALUE self, VALUE vidx, VALUE lowe
|
|
|
646
561
|
/* :nodoc: */
|
|
647
562
|
static VALUE prepared_statement__bind_uhugeint(VALUE self, VALUE vidx, VALUE lower, VALUE upper) {
|
|
648
563
|
duckdb_uhugeint uhugeint;
|
|
649
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
650
564
|
idx_t idx = check_index(vidx);
|
|
651
565
|
|
|
652
|
-
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
|
|
653
566
|
uhugeint.lower = NUM2ULL(lower);
|
|
654
567
|
uhugeint.upper = NUM2ULL(upper);
|
|
655
568
|
|
|
656
|
-
|
|
657
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
658
|
-
}
|
|
569
|
+
raise_if_bind_failed(duckdb_bind_uhugeint(prepared_statement_of(self), idx, uhugeint), idx);
|
|
659
570
|
|
|
660
571
|
return self;
|
|
661
572
|
}
|
|
@@ -664,54 +575,42 @@ static VALUE prepared_statement__bind_uhugeint(VALUE self, VALUE vidx, VALUE low
|
|
|
664
575
|
static VALUE prepared_statement__bind_decimal(VALUE self, VALUE vidx, VALUE lower, VALUE upper, VALUE width, VALUE scale) {
|
|
665
576
|
duckdb_hugeint hugeint;
|
|
666
577
|
duckdb_decimal decimal;
|
|
667
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
668
578
|
idx_t idx = check_index(vidx);
|
|
669
579
|
|
|
670
|
-
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
|
|
671
580
|
hugeint.lower = NUM2ULL(lower);
|
|
672
581
|
hugeint.upper = NUM2LL(upper);
|
|
673
582
|
decimal.value = hugeint;
|
|
674
583
|
decimal.width = (uint8_t)NUM2UINT(width);
|
|
675
584
|
decimal.scale = (uint8_t)NUM2UINT(scale);
|
|
676
585
|
|
|
677
|
-
|
|
678
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
679
|
-
}
|
|
586
|
+
raise_if_bind_failed(duckdb_bind_decimal(prepared_statement_of(self), idx, decimal), idx);
|
|
680
587
|
|
|
681
588
|
return self;
|
|
682
589
|
}
|
|
683
590
|
|
|
684
591
|
/* :nodoc: */
|
|
685
592
|
static VALUE prepared_statement__bind_uuid(VALUE self, VALUE vidx, VALUE val) {
|
|
686
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
687
593
|
duckdb_uhugeint uhugeint;
|
|
688
594
|
duckdb_value uuid_val;
|
|
689
595
|
duckdb_state state;
|
|
690
596
|
idx_t idx = check_index(vidx);
|
|
691
597
|
|
|
692
|
-
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
|
|
693
598
|
rbduckdb_uuid_str_to_uhugeint(val, &uhugeint);
|
|
694
599
|
uuid_val = duckdb_create_uuid(uhugeint);
|
|
695
|
-
state = duckdb_bind_value(
|
|
600
|
+
state = duckdb_bind_value(prepared_statement_of(self), idx, uuid_val);
|
|
696
601
|
duckdb_destroy_value(&uuid_val);
|
|
697
|
-
|
|
698
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
699
|
-
}
|
|
602
|
+
raise_if_bind_failed(state, idx);
|
|
700
603
|
return self;
|
|
701
604
|
}
|
|
702
605
|
|
|
703
606
|
/* :nodoc: */
|
|
704
607
|
static VALUE prepared_statement__bind_value(VALUE self, VALUE vidx, VALUE val) {
|
|
705
|
-
rubyDuckDBPreparedStatement *ctx;
|
|
706
608
|
rubyDuckDBValue *val_ctx;
|
|
707
609
|
idx_t idx = check_index(vidx);
|
|
708
610
|
|
|
709
|
-
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
|
|
710
611
|
val_ctx = rbduckdb_get_struct_value(val);
|
|
711
612
|
|
|
712
|
-
|
|
713
|
-
rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
|
|
714
|
-
}
|
|
613
|
+
raise_if_bind_failed(duckdb_bind_value(prepared_statement_of(self), idx, val_ctx->value), idx);
|
|
715
614
|
return self;
|
|
716
615
|
}
|
|
717
616
|
|
data/ext/duckdb/result.c
CHANGED
|
@@ -47,20 +47,10 @@ static VALUE result__return_type(VALUE oDuckDBResult);
|
|
|
47
47
|
static VALUE result__statement_type(VALUE oDuckDBResult);
|
|
48
48
|
static VALUE result__enum_internal_type(VALUE oDuckDBResult, VALUE col_idx);
|
|
49
49
|
|
|
50
|
-
static VALUE vector_date(void *vector_data, idx_t row_idx);
|
|
51
|
-
static VALUE vector_timestamp(void* vector_data, idx_t row_idx);
|
|
52
|
-
static VALUE vector_time(void* vector_data, idx_t row_idx);
|
|
53
|
-
static VALUE vector_interval(void* vector_data, idx_t row_idx);
|
|
54
50
|
static VALUE vector_blob(void* vector_data, idx_t row_idx);
|
|
55
51
|
static VALUE vector_varchar(void* vector_data, idx_t row_idx);
|
|
56
|
-
static VALUE vector_hugeint(void* vector_data, idx_t row_idx);
|
|
57
|
-
static VALUE vector_uhugeint(void* vector_data, idx_t row_idx);
|
|
58
52
|
static VALUE vector_decimal(duckdb_logical_type ty, void* vector_data, idx_t row_idx);
|
|
59
53
|
|
|
60
|
-
static VALUE vector_timestamp_s(void* vector_data, idx_t row_idx);
|
|
61
|
-
static VALUE vector_timestamp_ms(void* vector_data, idx_t row_idx);
|
|
62
|
-
static VALUE vector_timestamp_ns(void* vector_data, idx_t row_idx);
|
|
63
|
-
static VALUE vector_time_ns(void* vector_data, idx_t row_idx);
|
|
64
54
|
static VALUE vector_enum(duckdb_logical_type ty, void* vector_data, idx_t row_idx);
|
|
65
55
|
static VALUE vector_array(duckdb_logical_type ty, duckdb_vector vector, idx_t row_idx);
|
|
66
56
|
static VALUE vector_list(duckdb_logical_type ty, duckdb_vector vector, void* vector_data, idx_t row_idx);
|
|
@@ -311,46 +301,14 @@ VALUE rbduckdb_create_result(void) {
|
|
|
311
301
|
return allocate(cDuckDBResult);
|
|
312
302
|
}
|
|
313
303
|
|
|
314
|
-
static VALUE vector_date(void *vector_data, idx_t row_idx) {
|
|
315
|
-
return rbduckdb_date_to_ruby(((duckdb_date *)vector_data)[row_idx]);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
static VALUE vector_timestamp(void* vector_data, idx_t row_idx) {
|
|
319
|
-
return rbduckdb_timestamp_to_ruby(((duckdb_timestamp *)vector_data)[row_idx]);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
static VALUE vector_time(void* vector_data, idx_t row_idx) {
|
|
323
|
-
return rbduckdb_time_to_ruby(((duckdb_time *)vector_data)[row_idx]);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
static VALUE vector_interval(void* vector_data, idx_t row_idx) {
|
|
327
|
-
return rbduckdb_interval_to_ruby(((duckdb_interval *)vector_data)[row_idx]);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
304
|
static VALUE vector_blob(void* vector_data, idx_t row_idx) {
|
|
331
305
|
duckdb_string_t s = (((duckdb_string_t *)vector_data)[row_idx]);
|
|
332
|
-
|
|
333
|
-
return rb_str_new(s.value.inlined.inlined, s.value.inlined.length);
|
|
334
|
-
} else {
|
|
335
|
-
return rb_str_new(s.value.pointer.ptr, s.value.pointer.length);
|
|
336
|
-
}
|
|
306
|
+
return rb_str_new(duckdb_string_t_data(&s), duckdb_string_t_length(s));
|
|
337
307
|
}
|
|
338
308
|
|
|
339
309
|
static VALUE vector_varchar(void* vector_data, idx_t row_idx) {
|
|
340
310
|
duckdb_string_t s = (((duckdb_string_t *)vector_data)[row_idx]);
|
|
341
|
-
|
|
342
|
-
return rb_utf8_str_new(s.value.inlined.inlined, s.value.inlined.length);
|
|
343
|
-
} else {
|
|
344
|
-
return rb_utf8_str_new(s.value.pointer.ptr, s.value.pointer.length);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
static VALUE vector_hugeint(void* vector_data, idx_t row_idx) {
|
|
349
|
-
return rbduckdb_hugeint_to_ruby(((duckdb_hugeint *)vector_data)[row_idx]);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
static VALUE vector_uhugeint(void* vector_data, idx_t row_idx) {
|
|
353
|
-
return rbduckdb_uhugeint_to_ruby(((duckdb_uhugeint *)vector_data)[row_idx]);
|
|
311
|
+
return rb_utf8_str_new(duckdb_string_t_data(&s), duckdb_string_t_length(s));
|
|
354
312
|
}
|
|
355
313
|
|
|
356
314
|
static VALUE vector_decimal(duckdb_logical_type ty, void* vector_data, idx_t row_idx) {
|
|
@@ -391,26 +349,6 @@ static VALUE vector_decimal(duckdb_logical_type ty, void* vector_data, idx_t row
|
|
|
391
349
|
);
|
|
392
350
|
}
|
|
393
351
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
static VALUE vector_timestamp_s(void* vector_data, idx_t row_idx) {
|
|
397
|
-
return rbduckdb_timestamp_s_to_ruby(((duckdb_timestamp_s *)vector_data)[row_idx]);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
static VALUE vector_timestamp_ms(void* vector_data, idx_t row_idx) {
|
|
402
|
-
return rbduckdb_timestamp_ms_to_ruby(((duckdb_timestamp_ms *)vector_data)[row_idx]);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
static VALUE vector_timestamp_ns(void* vector_data, idx_t row_idx) {
|
|
407
|
-
return rbduckdb_timestamp_ns_to_ruby(((duckdb_timestamp_ns *)vector_data)[row_idx]);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
static VALUE vector_time_ns(void* vector_data, idx_t row_idx) {
|
|
411
|
-
return rbduckdb_time_ns_to_ruby(((duckdb_time_ns *)vector_data)[row_idx]);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
352
|
static VALUE vector_enum(duckdb_logical_type ty, void* vector_data, idx_t row_idx) {
|
|
415
353
|
duckdb_type type = duckdb_enum_internal_type(ty);
|
|
416
354
|
uint8_t index;
|
|
@@ -492,22 +430,22 @@ VALUE rbduckdb_vector_value_at(duckdb_vector vector, duckdb_logical_type element
|
|
|
492
430
|
obj = DBL2NUM((((double *) vector_data)[index]));
|
|
493
431
|
break;
|
|
494
432
|
case DUCKDB_TYPE_TIMESTAMP:
|
|
495
|
-
obj =
|
|
433
|
+
obj = rbduckdb_timestamp_to_ruby(((duckdb_timestamp *)vector_data)[index]);
|
|
496
434
|
break;
|
|
497
435
|
case DUCKDB_TYPE_DATE:
|
|
498
|
-
obj =
|
|
436
|
+
obj = rbduckdb_date_to_ruby(((duckdb_date *)vector_data)[index]);
|
|
499
437
|
break;
|
|
500
438
|
case DUCKDB_TYPE_TIME:
|
|
501
|
-
obj =
|
|
439
|
+
obj = rbduckdb_time_to_ruby(((duckdb_time *)vector_data)[index]);
|
|
502
440
|
break;
|
|
503
441
|
case DUCKDB_TYPE_INTERVAL:
|
|
504
|
-
obj =
|
|
442
|
+
obj = rbduckdb_interval_to_ruby(((duckdb_interval *)vector_data)[index]);
|
|
505
443
|
break;
|
|
506
444
|
case DUCKDB_TYPE_HUGEINT:
|
|
507
|
-
obj =
|
|
445
|
+
obj = rbduckdb_hugeint_to_ruby(((duckdb_hugeint *)vector_data)[index]);
|
|
508
446
|
break;
|
|
509
447
|
case DUCKDB_TYPE_UHUGEINT:
|
|
510
|
-
obj =
|
|
448
|
+
obj = rbduckdb_uhugeint_to_ruby(((duckdb_uhugeint *)vector_data)[index]);
|
|
511
449
|
break;
|
|
512
450
|
case DUCKDB_TYPE_VARCHAR:
|
|
513
451
|
obj = vector_varchar(vector_data, index);
|
|
@@ -519,16 +457,16 @@ VALUE rbduckdb_vector_value_at(duckdb_vector vector, duckdb_logical_type element
|
|
|
519
457
|
obj = vector_decimal(element_type, vector_data, index);
|
|
520
458
|
break;
|
|
521
459
|
case DUCKDB_TYPE_TIMESTAMP_S:
|
|
522
|
-
obj =
|
|
460
|
+
obj = rbduckdb_timestamp_s_to_ruby(((duckdb_timestamp_s *)vector_data)[index]);
|
|
523
461
|
break;
|
|
524
462
|
case DUCKDB_TYPE_TIMESTAMP_MS:
|
|
525
|
-
obj =
|
|
463
|
+
obj = rbduckdb_timestamp_ms_to_ruby(((duckdb_timestamp_ms *)vector_data)[index]);
|
|
526
464
|
break;
|
|
527
465
|
case DUCKDB_TYPE_TIMESTAMP_NS:
|
|
528
|
-
obj =
|
|
466
|
+
obj = rbduckdb_timestamp_ns_to_ruby(((duckdb_timestamp_ns *)vector_data)[index]);
|
|
529
467
|
break;
|
|
530
468
|
case DUCKDB_TYPE_TIME_NS:
|
|
531
|
-
obj =
|
|
469
|
+
obj = rbduckdb_time_ns_to_ruby(((duckdb_time_ns *)vector_data)[index]);
|
|
532
470
|
break;
|
|
533
471
|
case DUCKDB_TYPE_ENUM:
|
|
534
472
|
obj = vector_enum(element_type, vector_data, index);
|
|
@@ -703,7 +641,7 @@ static VALUE str_concat_byte(VALUE str, unsigned char byte, int offset) {
|
|
|
703
641
|
return rb_str_cat(str, p, 8 - offset);
|
|
704
642
|
}
|
|
705
643
|
|
|
706
|
-
static VALUE bytes_to_string(char *bytes, uint32_t length, int offset) {
|
|
644
|
+
static VALUE bytes_to_string(const char *bytes, uint32_t length, int offset) {
|
|
707
645
|
VALUE str = rb_str_new_literal("");
|
|
708
646
|
str = str_concat_byte(str, bytes[0], offset);
|
|
709
647
|
for (uint32_t i = 1; i < length; i++) {
|
|
@@ -714,18 +652,11 @@ static VALUE bytes_to_string(char *bytes, uint32_t length, int offset) {
|
|
|
714
652
|
|
|
715
653
|
static VALUE vector_bit(void* vector_data, idx_t row_idx) {
|
|
716
654
|
duckdb_string_t s = (((duckdb_string_t *)vector_data)[row_idx]);
|
|
717
|
-
char *p;
|
|
655
|
+
const char *p = duckdb_string_t_data(&s);
|
|
656
|
+
uint32_t length = duckdb_string_t_length(s);
|
|
718
657
|
int offset;
|
|
719
|
-
uint32_t length;
|
|
720
658
|
VALUE str = Qnil;
|
|
721
659
|
|
|
722
|
-
if(duckdb_string_is_inlined(s)) {
|
|
723
|
-
length = s.value.inlined.length;
|
|
724
|
-
p = s.value.inlined.inlined;
|
|
725
|
-
} else {
|
|
726
|
-
length = s.value.pointer.length;
|
|
727
|
-
p = s.value.pointer.ptr;
|
|
728
|
-
}
|
|
729
660
|
if (length < 2 || (unsigned char)p[0] > 7) {
|
|
730
661
|
rb_raise(eDuckDBError, "invalid BIT value");
|
|
731
662
|
}
|