pg 0.21.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.appveyor.yml +36 -0
  4. data/.gems +6 -0
  5. data/.github/workflows/binary-gems.yml +86 -0
  6. data/.github/workflows/source-gem.yml +130 -0
  7. data/.gitignore +13 -0
  8. data/.hgsigs +34 -0
  9. data/.hgtags +41 -0
  10. data/.irbrc +23 -0
  11. data/.pryrc +23 -0
  12. data/.tm_properties +21 -0
  13. data/.travis.yml +49 -0
  14. data/Gemfile +14 -0
  15. data/History.rdoc +291 -4
  16. data/Manifest.txt +8 -4
  17. data/README-Windows.rdoc +4 -4
  18. data/README.ja.rdoc +1 -2
  19. data/README.rdoc +62 -16
  20. data/Rakefile +32 -142
  21. data/Rakefile.cross +69 -71
  22. data/certs/ged.pem +24 -0
  23. data/certs/larskanis-2022.pem +26 -0
  24. data/ext/errorcodes.def +84 -0
  25. data/ext/errorcodes.rb +1 -1
  26. data/ext/errorcodes.txt +23 -2
  27. data/ext/extconf.rb +109 -52
  28. data/ext/gvl_wrappers.c +8 -0
  29. data/ext/gvl_wrappers.h +40 -33
  30. data/ext/pg.c +211 -146
  31. data/ext/pg.h +85 -95
  32. data/ext/pg_binary_decoder.c +82 -15
  33. data/ext/pg_binary_encoder.c +13 -12
  34. data/ext/pg_coder.c +145 -30
  35. data/ext/pg_connection.c +1349 -929
  36. data/ext/pg_copy_coder.c +60 -23
  37. data/ext/pg_record_coder.c +519 -0
  38. data/ext/pg_result.c +613 -207
  39. data/ext/pg_text_decoder.c +606 -40
  40. data/ext/pg_text_encoder.c +190 -59
  41. data/ext/pg_tuple.c +575 -0
  42. data/ext/pg_type_map.c +42 -9
  43. data/ext/pg_type_map_all_strings.c +19 -5
  44. data/ext/pg_type_map_by_class.c +54 -24
  45. data/ext/pg_type_map_by_column.c +73 -34
  46. data/ext/pg_type_map_by_mri_type.c +48 -19
  47. data/ext/pg_type_map_by_oid.c +55 -25
  48. data/ext/pg_type_map_in_ruby.c +51 -20
  49. data/ext/{util.c → pg_util.c} +12 -12
  50. data/ext/{util.h → pg_util.h} +2 -2
  51. data/lib/pg/basic_type_map_based_on_result.rb +47 -0
  52. data/lib/pg/basic_type_map_for_queries.rb +193 -0
  53. data/lib/pg/basic_type_map_for_results.rb +81 -0
  54. data/lib/pg/basic_type_registry.rb +296 -0
  55. data/lib/pg/binary_decoder.rb +23 -0
  56. data/lib/pg/coder.rb +24 -3
  57. data/lib/pg/connection.rb +600 -46
  58. data/lib/pg/constants.rb +2 -1
  59. data/lib/pg/exceptions.rb +2 -1
  60. data/lib/pg/result.rb +14 -2
  61. data/lib/pg/text_decoder.rb +21 -26
  62. data/lib/pg/text_encoder.rb +32 -8
  63. data/lib/pg/tuple.rb +30 -0
  64. data/lib/pg/type_map_by_column.rb +3 -2
  65. data/lib/pg/version.rb +4 -0
  66. data/lib/pg.rb +51 -38
  67. data/misc/openssl-pg-segfault.rb +31 -0
  68. data/misc/postgres/History.txt +9 -0
  69. data/misc/postgres/Manifest.txt +5 -0
  70. data/misc/postgres/README.txt +21 -0
  71. data/misc/postgres/Rakefile +21 -0
  72. data/misc/postgres/lib/postgres.rb +16 -0
  73. data/misc/ruby-pg/History.txt +9 -0
  74. data/misc/ruby-pg/Manifest.txt +5 -0
  75. data/misc/ruby-pg/README.txt +21 -0
  76. data/misc/ruby-pg/Rakefile +21 -0
  77. data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
  78. data/pg.gemspec +32 -0
  79. data/sample/array_insert.rb +20 -0
  80. data/sample/async_api.rb +106 -0
  81. data/sample/async_copyto.rb +39 -0
  82. data/sample/async_mixed.rb +56 -0
  83. data/sample/check_conn.rb +21 -0
  84. data/sample/copydata.rb +71 -0
  85. data/sample/copyfrom.rb +81 -0
  86. data/sample/copyto.rb +19 -0
  87. data/sample/cursor.rb +21 -0
  88. data/sample/disk_usage_report.rb +177 -0
  89. data/sample/issue-119.rb +94 -0
  90. data/sample/losample.rb +69 -0
  91. data/sample/minimal-testcase.rb +17 -0
  92. data/sample/notify_wait.rb +72 -0
  93. data/sample/pg_statistics.rb +285 -0
  94. data/sample/replication_monitor.rb +222 -0
  95. data/sample/test_binary_values.rb +33 -0
  96. data/sample/wal_shipper.rb +434 -0
  97. data/sample/warehouse_partitions.rb +311 -0
  98. data.tar.gz.sig +0 -0
  99. metadata +96 -229
  100. metadata.gz.sig +0 -0
  101. data/ChangeLog +0 -6595
  102. data/lib/pg/basic_type_mapping.rb +0 -426
  103. data/lib/pg/deprecated_constants.rb +0 -21
  104. data/spec/data/expected_trace.out +0 -26
  105. data/spec/data/random_binary_data +0 -0
  106. data/spec/helpers.rb +0 -352
  107. data/spec/pg/basic_type_mapping_spec.rb +0 -305
  108. data/spec/pg/connection_spec.rb +0 -1676
  109. data/spec/pg/result_spec.rb +0 -456
  110. data/spec/pg/type_map_by_class_spec.rb +0 -138
  111. data/spec/pg/type_map_by_column_spec.rb +0 -222
  112. data/spec/pg/type_map_by_mri_type_spec.rb +0 -136
  113. data/spec/pg/type_map_by_oid_spec.rb +0 -149
  114. data/spec/pg/type_map_in_ruby_spec.rb +0 -164
  115. data/spec/pg/type_map_spec.rb +0 -22
  116. data/spec/pg/type_spec.rb +0 -777
  117. data/spec/pg_spec.rb +0 -50
data/ext/pg_copy_coder.c CHANGED
@@ -21,17 +21,47 @@ typedef struct {
21
21
 
22
22
 
23
23
  static void
24
- pg_copycoder_mark( t_pg_copycoder *this )
24
+ pg_copycoder_mark( void *_this )
25
25
  {
26
- rb_gc_mark(this->typemap);
27
- rb_gc_mark(this->null_string);
26
+ t_pg_copycoder *this = (t_pg_copycoder *)_this;
27
+ rb_gc_mark_movable(this->typemap);
28
+ rb_gc_mark_movable(this->null_string);
28
29
  }
29
30
 
31
+ static size_t
32
+ pg_copycoder_memsize( const void *_this )
33
+ {
34
+ const t_pg_copycoder *this = (const t_pg_copycoder *)_this;
35
+ return sizeof(*this);
36
+ }
37
+
38
+ static void
39
+ pg_copycoder_compact( void *_this )
40
+ {
41
+ t_pg_copycoder *this = (t_pg_copycoder *)_this;
42
+ pg_coder_compact(&this->comp);
43
+ pg_gc_location(this->typemap);
44
+ pg_gc_location(this->null_string);
45
+ }
46
+
47
+ static const rb_data_type_t pg_copycoder_type = {
48
+ "PG::CopyCoder",
49
+ {
50
+ pg_copycoder_mark,
51
+ RUBY_TYPED_DEFAULT_FREE,
52
+ pg_copycoder_memsize,
53
+ pg_compact_callback(pg_copycoder_compact),
54
+ },
55
+ &pg_coder_type,
56
+ 0,
57
+ RUBY_TYPED_FREE_IMMEDIATELY,
58
+ };
59
+
30
60
  static VALUE
31
61
  pg_copycoder_encoder_allocate( VALUE klass )
32
62
  {
33
63
  t_pg_copycoder *this;
34
- VALUE self = Data_Make_Struct( klass, t_pg_copycoder, pg_copycoder_mark, -1, this );
64
+ VALUE self = TypedData_Make_Struct( klass, t_pg_copycoder, &pg_copycoder_type, this );
35
65
  pg_coder_init_encoder( self );
36
66
  this->typemap = pg_typemap_all_strings;
37
67
  this->delimiter = '\t';
@@ -43,7 +73,7 @@ static VALUE
43
73
  pg_copycoder_decoder_allocate( VALUE klass )
44
74
  {
45
75
  t_pg_copycoder *this;
46
- VALUE self = Data_Make_Struct( klass, t_pg_copycoder, pg_copycoder_mark, -1, this );
76
+ VALUE self = TypedData_Make_Struct( klass, t_pg_copycoder, &pg_copycoder_type, this );
47
77
  pg_coder_init_decoder( self );
48
78
  this->typemap = pg_typemap_all_strings;
49
79
  this->delimiter = '\t';
@@ -62,7 +92,7 @@ pg_copycoder_decoder_allocate( VALUE klass )
62
92
  static VALUE
63
93
  pg_copycoder_delimiter_set(VALUE self, VALUE delimiter)
64
94
  {
65
- t_pg_copycoder *this = DATA_PTR(self);
95
+ t_pg_copycoder *this = RTYPEDDATA_DATA(self);
66
96
  StringValue(delimiter);
67
97
  if(RSTRING_LEN(delimiter) != 1)
68
98
  rb_raise( rb_eArgError, "delimiter size must be one byte");
@@ -79,7 +109,7 @@ pg_copycoder_delimiter_set(VALUE self, VALUE delimiter)
79
109
  static VALUE
80
110
  pg_copycoder_delimiter_get(VALUE self)
81
111
  {
82
- t_pg_copycoder *this = DATA_PTR(self);
112
+ t_pg_copycoder *this = RTYPEDDATA_DATA(self);
83
113
  return rb_str_new(&this->delimiter, 1);
84
114
  }
85
115
 
@@ -92,7 +122,7 @@ pg_copycoder_delimiter_get(VALUE self)
92
122
  static VALUE
93
123
  pg_copycoder_null_string_set(VALUE self, VALUE null_string)
94
124
  {
95
- t_pg_copycoder *this = DATA_PTR(self);
125
+ t_pg_copycoder *this = RTYPEDDATA_DATA(self);
96
126
  StringValue(null_string);
97
127
  this->null_string = null_string;
98
128
  return null_string;
@@ -104,7 +134,7 @@ pg_copycoder_null_string_set(VALUE self, VALUE null_string)
104
134
  static VALUE
105
135
  pg_copycoder_null_string_get(VALUE self)
106
136
  {
107
- t_pg_copycoder *this = DATA_PTR(self);
137
+ t_pg_copycoder *this = RTYPEDDATA_DATA(self);
108
138
  return this->null_string;
109
139
  }
110
140
 
@@ -112,16 +142,17 @@ pg_copycoder_null_string_get(VALUE self)
112
142
  * call-seq:
113
143
  * coder.type_map = map
114
144
  *
145
+ * Defines how single columns are encoded or decoded.
115
146
  * +map+ must be a kind of PG::TypeMap .
116
147
  *
117
148
  * Defaults to a PG::TypeMapAllStrings , so that PG::TextEncoder::String respectively
118
- * PG::TextDecoder::String is used for encoding/decoding of all columns.
149
+ * PG::TextDecoder::String is used for encoding/decoding of each column.
119
150
  *
120
151
  */
121
152
  static VALUE
122
153
  pg_copycoder_type_map_set(VALUE self, VALUE type_map)
123
154
  {
124
- t_pg_copycoder *this = DATA_PTR( self );
155
+ t_pg_copycoder *this = RTYPEDDATA_DATA( self );
125
156
 
126
157
  if ( !rb_obj_is_kind_of(type_map, rb_cTypeMap) ){
127
158
  rb_raise( rb_eTypeError, "wrong elements type %s (expected some kind of PG::TypeMap)",
@@ -136,11 +167,12 @@ pg_copycoder_type_map_set(VALUE self, VALUE type_map)
136
167
  * call-seq:
137
168
  * coder.type_map -> PG::TypeMap
138
169
  *
170
+ * The PG::TypeMap that will be used for encoding and decoding of columns.
139
171
  */
140
172
  static VALUE
141
173
  pg_copycoder_type_map_get(VALUE self)
142
174
  {
143
- t_pg_copycoder *this = DATA_PTR( self );
175
+ t_pg_copycoder *this = RTYPEDDATA_DATA( self );
144
176
 
145
177
  return this->typemap;
146
178
  }
@@ -185,7 +217,7 @@ pg_text_enc_copy_row(t_pg_coder *conv, VALUE value, char *out, VALUE *intermedia
185
217
  char *current_out;
186
218
  char *end_capa_ptr;
187
219
 
188
- p_typemap = DATA_PTR( this->typemap );
220
+ p_typemap = RTYPEDDATA_DATA( this->typemap );
189
221
  p_typemap->funcs.fit_to_query( this->typemap, value );
190
222
 
191
223
  /* Allocate a new string with embedded capacity and realloc exponential when needed. */
@@ -222,7 +254,7 @@ pg_text_enc_copy_row(t_pg_coder *conv, VALUE value, char *out, VALUE *intermedia
222
254
 
223
255
  if( strlen == -1 ){
224
256
  /* we can directly use String value in subint */
225
- strlen = RSTRING_LEN(subint);
257
+ strlen = RSTRING_LENINT(subint);
226
258
 
227
259
  /* size of string assuming the worst case, that every character must be escaped. */
228
260
  PG_RB_STR_ENSURE_CAPA( *intermediate, strlen * 2, current_out, end_capa_ptr );
@@ -354,7 +386,7 @@ GetDecimalFromHex(char hex)
354
386
  * src/backend/commands/copy.c
355
387
  */
356
388
  static VALUE
357
- pg_text_dec_copy_row(t_pg_coder *conv, char *input_line, int len, int _tuple, int _field, int enc_idx)
389
+ pg_text_dec_copy_row(t_pg_coder *conv, const char *input_line, int len, int _tuple, int _field, int enc_idx)
358
390
  {
359
391
  t_pg_copycoder *this = (t_pg_copycoder *)conv;
360
392
 
@@ -368,12 +400,12 @@ pg_text_dec_copy_row(t_pg_coder *conv, char *input_line, int len, int _tuple, in
368
400
  int fieldno;
369
401
  int expected_fields;
370
402
  char *output_ptr;
371
- char *cur_ptr;
372
- char *line_end_ptr;
403
+ const char *cur_ptr;
404
+ const char *line_end_ptr;
373
405
  char *end_capa_ptr;
374
406
  t_typemap *p_typemap;
375
407
 
376
- p_typemap = DATA_PTR( this->typemap );
408
+ p_typemap = RTYPEDDATA_DATA( this->typemap );
377
409
  expected_fields = p_typemap->funcs.fit_to_copy_get( this->typemap );
378
410
 
379
411
  /* The received input string will probably have this->nfields fields. */
@@ -381,7 +413,7 @@ pg_text_dec_copy_row(t_pg_coder *conv, char *input_line, int len, int _tuple, in
381
413
 
382
414
  /* Allocate a new string with embedded capacity and realloc later with
383
415
  * exponential growing size when needed. */
384
- PG_RB_TAINTED_STR_NEW( field_str, output_ptr, end_capa_ptr );
416
+ PG_RB_STR_NEW( field_str, output_ptr, end_capa_ptr );
385
417
 
386
418
  /* set pointer variables for loop */
387
419
  cur_ptr = input_line;
@@ -392,9 +424,9 @@ pg_text_dec_copy_row(t_pg_coder *conv, char *input_line, int len, int _tuple, in
392
424
  for (;;)
393
425
  {
394
426
  int found_delim = 0;
395
- char *start_ptr;
396
- char *end_ptr;
397
- int input_len;
427
+ const char *start_ptr;
428
+ const char *end_ptr;
429
+ long input_len;
398
430
 
399
431
  /* Remember start of field on input side */
400
432
  start_ptr = cur_ptr;
@@ -543,7 +575,7 @@ pg_text_dec_copy_row(t_pg_coder *conv, char *input_line, int len, int _tuple, in
543
575
  if( field_value == field_str ){
544
576
  /* Our output string will be send to the user, so we can not reuse
545
577
  * it for the next field. */
546
- PG_RB_TAINTED_STR_NEW( field_str, output_ptr, end_capa_ptr );
578
+ PG_RB_STR_NEW( field_str, output_ptr, end_capa_ptr );
547
579
  }
548
580
  }
549
581
  /* Reset the pointer to the start of the output/buffer string. */
@@ -585,7 +617,12 @@ init_pg_copycoder()
585
617
  /* rb_mPG_TextEncoder = rb_define_module_under( rb_mPG, "TextEncoder" ); */
586
618
  /* dummy = rb_define_class_under( rb_mPG_TextEncoder, "CopyRow", rb_cPG_CopyEncoder ); */
587
619
  pg_define_coder( "CopyRow", pg_text_enc_copy_row, rb_cPG_CopyEncoder, rb_mPG_TextEncoder );
620
+ rb_include_module( rb_cPG_CopyEncoder, rb_mPG_BinaryFormatting );
621
+
588
622
  /* rb_mPG_TextDecoder = rb_define_module_under( rb_mPG, "TextDecoder" ); */
589
623
  /* dummy = rb_define_class_under( rb_mPG_TextDecoder, "CopyRow", rb_cPG_CopyDecoder ); */
590
624
  pg_define_coder( "CopyRow", pg_text_dec_copy_row, rb_cPG_CopyDecoder, rb_mPG_TextDecoder );
625
+ /* Although CopyRow is a text decoder, data can contain zero bytes and are not zero terminated.
626
+ * They are handled like binaries. So format is set to 1 (binary). */
627
+ rb_include_module( rb_cPG_CopyDecoder, rb_mPG_BinaryFormatting );
591
628
  }