pg 1.5.9 → 1.7.0

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/{History.md → CHANGELOG.md} +126 -0
  4. data/Gemfile +11 -7
  5. data/README-Windows.rdoc +1 -1
  6. data/README.ja.md +83 -32
  7. data/README.md +79 -29
  8. data/Rakefile +84 -19
  9. data/certs/larskanis-2026.pem +24 -0
  10. data/ext/errorcodes.def +9 -0
  11. data/ext/errorcodes.rb +1 -1
  12. data/ext/errorcodes.txt +8 -1
  13. data/ext/extconf.rb +194 -30
  14. data/ext/gvl_wrappers.c +13 -2
  15. data/ext/gvl_wrappers.h +47 -134
  16. data/ext/pg.c +23 -16
  17. data/ext/pg.h +23 -24
  18. data/ext/pg_binary_decoder.c +157 -3
  19. data/ext/pg_binary_encoder.c +219 -9
  20. data/ext/pg_cancel_connection.c +360 -0
  21. data/ext/pg_coder.c +58 -9
  22. data/ext/pg_connection.c +558 -291
  23. data/ext/pg_copy_coder.c +36 -23
  24. data/ext/pg_record_coder.c +11 -7
  25. data/ext/pg_result.c +144 -76
  26. data/ext/pg_text_decoder.c +7 -7
  27. data/ext/pg_text_encoder.c +29 -11
  28. data/ext/pg_tuple.c +9 -9
  29. data/ext/pg_type_map.c +45 -3
  30. data/ext/pg_type_map_all_strings.c +3 -3
  31. data/ext/pg_type_map_by_class.c +2 -2
  32. data/ext/pg_type_map_by_column.c +4 -3
  33. data/ext/pg_type_map_by_mri_type.c +1 -1
  34. data/ext/pg_type_map_by_oid.c +4 -2
  35. data/ext/pg_type_map_in_ruby.c +2 -2
  36. data/ext/pg_util.c +2 -2
  37. data/ext/pg_util.h +2 -2
  38. data/lib/pg/basic_type_map_based_on_result.rb +5 -0
  39. data/lib/pg/basic_type_map_for_queries.rb +16 -5
  40. data/lib/pg/basic_type_map_for_results.rb +5 -0
  41. data/lib/pg/basic_type_registry.rb +2 -2
  42. data/lib/pg/cancel_connection.rb +53 -0
  43. data/lib/pg/coder.rb +4 -2
  44. data/lib/pg/connection.rb +393 -180
  45. data/lib/pg/text_decoder/date.rb +1 -1
  46. data/lib/pg/text_decoder/json.rb +1 -1
  47. data/lib/pg/text_encoder/date.rb +7 -1
  48. data/lib/pg/text_encoder/json.rb +1 -1
  49. data/lib/pg/version.rb +2 -1
  50. data/lib/pg.rb +156 -130
  51. data/misc/glibc/Dockerfile +20 -0
  52. data/misc/glibc/docker-compose.yml +9 -0
  53. data/misc/glibc/glibc_spec.rb +5 -0
  54. data/misc/yugabyte/Dockerfile +9 -0
  55. data/misc/yugabyte/docker-compose.yml +28 -0
  56. data/misc/yugabyte/pg-test.rb +45 -0
  57. data/pg.gemspec +5 -3
  58. data/ports/patches/krb5/1.22.2/0001-Allow-static-linking-krb5-library.patch +30 -0
  59. data/ports/patches/krb5/1.22.2/0002-unknown-command-line-option-on-clang.patch +12 -0
  60. data/ports/patches/postgresql/18.6/0001-Use-workaround-of-__builtin_setjmp-only-on-MINGW-on-.patch +42 -0
  61. data/rakelib/pg_gem_helper.rb +64 -0
  62. data/sample/async_mixed.rb +1 -1
  63. data.tar.gz.sig +0 -0
  64. metadata +36 -22
  65. metadata.gz.sig +0 -0
  66. data/Manifest.txt +0 -72
  67. data/Rakefile.cross +0 -303
data/ext/pg_coder.c CHANGED
@@ -95,13 +95,13 @@ const rb_data_type_t pg_coder_type = {
95
95
  (RUBY_DATA_FUNC) NULL,
96
96
  RUBY_TYPED_DEFAULT_FREE,
97
97
  pg_coder_memsize,
98
- pg_compact_callback(pg_coder_compact),
98
+ pg_coder_compact,
99
99
  },
100
100
  0,
101
101
  0,
102
102
  // IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
103
103
  // macro to update VALUE references, as to trigger write barriers.
104
- RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | PG_RUBY_TYPED_FROZEN_SHAREABLE,
104
+ RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE,
105
105
  };
106
106
 
107
107
  static VALUE
@@ -119,11 +119,11 @@ static const rb_data_type_t pg_composite_coder_type = {
119
119
  (RUBY_DATA_FUNC) NULL,
120
120
  RUBY_TYPED_DEFAULT_FREE,
121
121
  pg_composite_coder_memsize,
122
- pg_compact_callback(pg_composite_coder_compact),
122
+ pg_composite_coder_compact,
123
123
  },
124
124
  &pg_coder_type,
125
125
  0,
126
- RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | PG_RUBY_TYPED_FROZEN_SHAREABLE,
126
+ RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE,
127
127
  };
128
128
 
129
129
  static VALUE
@@ -135,6 +135,7 @@ pg_composite_encoder_allocate( VALUE klass )
135
135
  this->elem = NULL;
136
136
  this->needs_quotation = 1;
137
137
  this->delimiter = ',';
138
+ this->dimensions = -1;
138
139
  rb_iv_set( self, "@elements_type", Qnil );
139
140
  return self;
140
141
  }
@@ -157,6 +158,7 @@ pg_composite_decoder_allocate( VALUE klass )
157
158
  this->elem = NULL;
158
159
  this->needs_quotation = 1;
159
160
  this->delimiter = ',';
161
+ this->dimensions = -1;
160
162
  rb_iv_set( self, "@elements_type", Qnil );
161
163
  return self;
162
164
  }
@@ -175,7 +177,7 @@ static VALUE
175
177
  pg_coder_encode(int argc, VALUE *argv, VALUE self)
176
178
  {
177
179
  VALUE res;
178
- VALUE intermediate;
180
+ VALUE intermediate = Qnil;
179
181
  VALUE value;
180
182
  int len, len2;
181
183
  int enc_idx;
@@ -213,8 +215,6 @@ pg_coder_encode(int argc, VALUE *argv, VALUE self)
213
215
  }
214
216
  rb_str_set_len( res, len2 );
215
217
 
216
- RB_GC_GUARD(intermediate);
217
-
218
218
  return res;
219
219
  }
220
220
 
@@ -364,6 +364,7 @@ pg_coder_flags_get(VALUE self)
364
364
  * Specifies whether the assigned #elements_type requires quotation marks to
365
365
  * be transferred safely. Encoding with #needs_quotation=false is somewhat
366
366
  * faster.
367
+ * It is only used by text coders and ignored by binary coders.
367
368
  *
368
369
  * The default is +true+. This option is ignored for decoding of values.
369
370
  */
@@ -397,6 +398,7 @@ pg_coder_needs_quotation_get(VALUE self)
397
398
  * Specifies the character that separates values within the composite type.
398
399
  * The default is a comma.
399
400
  * This must be a single one-byte character.
401
+ * It is only used by text coders and ignored by binary coders.
400
402
  */
401
403
  static VALUE
402
404
  pg_coder_delimiter_set(VALUE self, VALUE delimiter)
@@ -423,6 +425,49 @@ pg_coder_delimiter_get(VALUE self)
423
425
  return rb_str_new(&this->delimiter, 1);
424
426
  }
425
427
 
428
+ /*
429
+ * call-seq:
430
+ * coder.dimensions = Integer
431
+ * coder.dimensions = nil
432
+ *
433
+ * Set number of array dimensions to be encoded.
434
+ *
435
+ * This property ensures, that this number of dimensions is always encoded.
436
+ * If less dimensions than this number are in the given value, an ArgumentError is raised.
437
+ * If more dimensions than this number are in the value, the Array value is passed to the next encoder.
438
+ *
439
+ * Setting dimensions is especially useful, when a Record shall be encoded into an Array, since the Array encoder can not distinguish if the array shall be encoded as a higher dimension or as a record otherwise.
440
+ *
441
+ * The default is +nil+.
442
+ *
443
+ * See #dimensions
444
+ */
445
+ static VALUE
446
+ pg_coder_dimensions_set(VALUE self, VALUE dimensions)
447
+ {
448
+ t_pg_composite_coder *this = RTYPEDDATA_DATA(self);
449
+ rb_check_frozen(self);
450
+ if(!NIL_P(dimensions) && NUM2INT(dimensions) < 0)
451
+ rb_raise( rb_eArgError, "dimensions must be nil or >= 0");
452
+ this->dimensions = NIL_P(dimensions) ? -1 : NUM2INT(dimensions);
453
+ return dimensions;
454
+ }
455
+
456
+ /*
457
+ * call-seq:
458
+ * coder.dimensions -> Integer | nil
459
+ *
460
+ * Get number of enforced array dimensions or +nil+ if not set.
461
+ *
462
+ * See #dimensions=
463
+ */
464
+ static VALUE
465
+ pg_coder_dimensions_get(VALUE self)
466
+ {
467
+ t_pg_composite_coder *this = RTYPEDDATA_DATA(self);
468
+ return this->dimensions < 0 ? Qnil : INT2NUM(this->dimensions);
469
+ }
470
+
426
471
  /*
427
472
  * call-seq:
428
473
  * coder.elements_type = coder
@@ -460,7 +505,7 @@ static const rb_data_type_t pg_coder_cfunc_type = {
460
505
  },
461
506
  0,
462
507
  0,
463
- RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | PG_RUBY_TYPED_FROZEN_SHAREABLE,
508
+ RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE,
464
509
  };
465
510
 
466
511
  VALUE
@@ -586,7 +631,7 @@ init_pg_coder(void)
586
631
  /*
587
632
  * Name of the coder or the corresponding data type.
588
633
  *
589
- * This accessor is only used in PG::Coder#inspect .
634
+ * This accessor is used by PG::Coder#inspect and PG::Connection#embed_params .
590
635
  */
591
636
  rb_define_attr( rb_cPG_Coder, "name", 1, 1 );
592
637
 
@@ -604,6 +649,8 @@ init_pg_coder(void)
604
649
  *
605
650
  * This is the base class for all type cast classes of PostgreSQL types,
606
651
  * that are made up of some sub type.
652
+ *
653
+ * See PG::TextEncoder::Array, PG::TextDecoder::Array, PG::BinaryEncoder::Array, PG::BinaryDecoder::Array, etc.
607
654
  */
608
655
  rb_cPG_CompositeCoder = rb_define_class_under( rb_mPG, "CompositeCoder", rb_cPG_Coder );
609
656
  rb_define_method( rb_cPG_CompositeCoder, "elements_type=", pg_coder_elements_type_set, 1 );
@@ -612,6 +659,8 @@ init_pg_coder(void)
612
659
  rb_define_method( rb_cPG_CompositeCoder, "needs_quotation?", pg_coder_needs_quotation_get, 0 );
613
660
  rb_define_method( rb_cPG_CompositeCoder, "delimiter=", pg_coder_delimiter_set, 1 );
614
661
  rb_define_method( rb_cPG_CompositeCoder, "delimiter", pg_coder_delimiter_get, 0 );
662
+ rb_define_method( rb_cPG_CompositeCoder, "dimensions=", pg_coder_dimensions_set, 1 );
663
+ rb_define_method( rb_cPG_CompositeCoder, "dimensions", pg_coder_dimensions_get, 0 );
615
664
 
616
665
  /* Document-class: PG::CompositeEncoder < PG::CompositeCoder */
617
666
  rb_cPG_CompositeEncoder = rb_define_class_under( rb_mPG, "CompositeEncoder", rb_cPG_CompositeCoder );