duckdb 1.5.6.1 → 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.
@@ -253,140 +253,102 @@ static VALUE prepared_statement_clear_bindings(VALUE self) {
253
253
  return self;
254
254
  }
255
255
 
256
- static VALUE prepared_statement_bind_bool(VALUE self, VALUE vidx, VALUE val) {
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
- if (duckdb_bind_boolean(ctx->prepared_statement, idx, (val == Qtrue)) == DuckDBError) {
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- if (duckdb_bind_varchar_length(ctx->prepared_statement, idx, pstr, (idx_t)len) == DuckDBError) {
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
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
- if (duckdb_bind_timestamp(ctx->prepared_statement, idx, timestamp) == DuckDBError) {
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
- if (duckdb_bind_timestamp_tz(ctx->prepared_statement, idx, timestamp_tz) == DuckDBError) {
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
- if (duckdb_bind_interval(ctx->prepared_statement, idx, interval) == DuckDBError) {
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
- if (duckdb_bind_hugeint(ctx->prepared_statement, idx, hugeint) == DuckDBError) {
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
- if (duckdb_bind_uhugeint(ctx->prepared_statement, idx, uhugeint) == DuckDBError) {
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
- if (duckdb_bind_decimal(ctx->prepared_statement, idx, decimal) == DuckDBError) {
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(ctx->prepared_statement, idx, uuid_val);
600
+ state = duckdb_bind_value(prepared_statement_of(self), idx, uuid_val);
696
601
  duckdb_destroy_value(&uuid_val);
697
- if (state == DuckDBError) {
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
- if (duckdb_bind_value(ctx->prepared_statement, idx, val_ctx->value) == DuckDBError) {
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