pg 0.18.1 → 1.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.appveyor.yml +42 -0
  4. data/.gems +6 -0
  5. data/.github/workflows/binary-gems.yml +117 -0
  6. data/.github/workflows/source-gem.yml +141 -0
  7. data/.gitignore +22 -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/BSDL +2 -2
  15. data/Gemfile +17 -0
  16. data/History.md +901 -0
  17. data/Manifest.txt +8 -21
  18. data/README-Windows.rdoc +17 -28
  19. data/README.ja.md +300 -0
  20. data/README.md +286 -0
  21. data/Rakefile +43 -131
  22. data/Rakefile.cross +89 -70
  23. data/certs/ged.pem +24 -0
  24. data/certs/kanis@comcard.de.pem +20 -0
  25. data/certs/larskanis-2022.pem +26 -0
  26. data/certs/larskanis-2023.pem +24 -0
  27. data/certs/larskanis-2024.pem +24 -0
  28. data/ext/errorcodes.def +113 -0
  29. data/ext/errorcodes.rb +1 -1
  30. data/ext/errorcodes.txt +36 -2
  31. data/ext/extconf.rb +128 -55
  32. data/ext/gvl_wrappers.c +8 -0
  33. data/ext/gvl_wrappers.h +44 -33
  34. data/ext/pg.c +228 -202
  35. data/ext/pg.h +108 -99
  36. data/ext/pg_binary_decoder.c +164 -16
  37. data/ext/pg_binary_encoder.c +249 -22
  38. data/ext/pg_coder.c +189 -44
  39. data/ext/pg_connection.c +1889 -1195
  40. data/ext/pg_copy_coder.c +398 -42
  41. data/ext/pg_errors.c +1 -1
  42. data/ext/pg_record_coder.c +522 -0
  43. data/ext/pg_result.c +729 -234
  44. data/ext/pg_text_decoder.c +635 -52
  45. data/ext/pg_text_encoder.c +294 -130
  46. data/ext/pg_tuple.c +572 -0
  47. data/ext/pg_type_map.c +64 -23
  48. data/ext/pg_type_map_all_strings.c +21 -7
  49. data/ext/pg_type_map_by_class.c +59 -27
  50. data/ext/pg_type_map_by_column.c +86 -43
  51. data/ext/pg_type_map_by_mri_type.c +50 -21
  52. data/ext/pg_type_map_by_oid.c +62 -29
  53. data/ext/pg_type_map_in_ruby.c +59 -28
  54. data/ext/{util.c → pg_util.c} +13 -13
  55. data/ext/{util.h → pg_util.h} +3 -3
  56. data/lib/pg/basic_type_map_based_on_result.rb +67 -0
  57. data/lib/pg/basic_type_map_for_queries.rb +202 -0
  58. data/lib/pg/basic_type_map_for_results.rb +104 -0
  59. data/lib/pg/basic_type_registry.rb +303 -0
  60. data/lib/pg/binary_decoder/date.rb +9 -0
  61. data/lib/pg/binary_decoder/timestamp.rb +26 -0
  62. data/lib/pg/binary_encoder/timestamp.rb +20 -0
  63. data/lib/pg/coder.rb +36 -13
  64. data/lib/pg/connection.rb +813 -74
  65. data/lib/pg/exceptions.rb +16 -2
  66. data/lib/pg/result.rb +24 -7
  67. data/lib/pg/text_decoder/date.rb +18 -0
  68. data/lib/pg/text_decoder/inet.rb +9 -0
  69. data/lib/pg/text_decoder/json.rb +14 -0
  70. data/lib/pg/text_decoder/numeric.rb +9 -0
  71. data/lib/pg/text_decoder/timestamp.rb +30 -0
  72. data/lib/pg/text_encoder/date.rb +12 -0
  73. data/lib/pg/text_encoder/inet.rb +28 -0
  74. data/lib/pg/text_encoder/json.rb +14 -0
  75. data/lib/pg/text_encoder/numeric.rb +9 -0
  76. data/lib/pg/text_encoder/timestamp.rb +24 -0
  77. data/lib/pg/tuple.rb +30 -0
  78. data/lib/pg/type_map_by_column.rb +3 -2
  79. data/lib/pg/version.rb +4 -0
  80. data/lib/pg.rb +106 -41
  81. data/misc/openssl-pg-segfault.rb +31 -0
  82. data/misc/postgres/History.txt +9 -0
  83. data/misc/postgres/Manifest.txt +5 -0
  84. data/misc/postgres/README.txt +21 -0
  85. data/misc/postgres/Rakefile +21 -0
  86. data/misc/postgres/lib/postgres.rb +16 -0
  87. data/misc/ruby-pg/History.txt +9 -0
  88. data/misc/ruby-pg/Manifest.txt +5 -0
  89. data/misc/ruby-pg/README.txt +21 -0
  90. data/misc/ruby-pg/Rakefile +21 -0
  91. data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
  92. data/pg.gemspec +34 -0
  93. data/rakelib/task_extension.rb +46 -0
  94. data/sample/array_insert.rb +1 -1
  95. data/sample/async_api.rb +4 -8
  96. data/sample/async_copyto.rb +1 -1
  97. data/sample/async_mixed.rb +1 -1
  98. data/sample/check_conn.rb +1 -1
  99. data/sample/copydata.rb +71 -0
  100. data/sample/copyfrom.rb +1 -1
  101. data/sample/copyto.rb +1 -1
  102. data/sample/cursor.rb +1 -1
  103. data/sample/disk_usage_report.rb +6 -15
  104. data/sample/issue-119.rb +2 -2
  105. data/sample/losample.rb +1 -1
  106. data/sample/minimal-testcase.rb +2 -2
  107. data/sample/notify_wait.rb +1 -1
  108. data/sample/pg_statistics.rb +6 -15
  109. data/sample/replication_monitor.rb +9 -18
  110. data/sample/test_binary_values.rb +1 -1
  111. data/sample/wal_shipper.rb +2 -2
  112. data/sample/warehouse_partitions.rb +8 -17
  113. data.tar.gz.sig +0 -0
  114. metadata +135 -207
  115. metadata.gz.sig +0 -0
  116. data/ChangeLog +0 -5378
  117. data/History.rdoc +0 -297
  118. data/README.ja.rdoc +0 -14
  119. data/README.rdoc +0 -161
  120. data/lib/pg/basic_type_mapping.rb +0 -399
  121. data/lib/pg/constants.rb +0 -11
  122. data/lib/pg/text_decoder.rb +0 -42
  123. data/lib/pg/text_encoder.rb +0 -27
  124. data/spec/data/expected_trace.out +0 -26
  125. data/spec/data/random_binary_data +0 -0
  126. data/spec/helpers.rb +0 -355
  127. data/spec/pg/basic_type_mapping_spec.rb +0 -251
  128. data/spec/pg/connection_spec.rb +0 -1459
  129. data/spec/pg/result_spec.rb +0 -449
  130. data/spec/pg/type_map_by_class_spec.rb +0 -138
  131. data/spec/pg/type_map_by_column_spec.rb +0 -222
  132. data/spec/pg/type_map_by_mri_type_spec.rb +0 -136
  133. data/spec/pg/type_map_by_oid_spec.rb +0 -149
  134. data/spec/pg/type_map_in_ruby_spec.rb +0 -164
  135. data/spec/pg/type_map_spec.rb +0 -22
  136. data/spec/pg/type_spec.rb +0 -665
  137. data/spec/pg_spec.rb +0 -50
data/ext/pg.c CHANGED
@@ -1,12 +1,13 @@
1
1
  /*
2
2
  * pg.c - Toplevel extension
3
- * $Id: pg.c,v a9724aef9116 2014/12/12 21:03:27 lars $
3
+ * $Id$
4
4
  *
5
5
  * Author/s:
6
6
  *
7
7
  * - Jeff Davis <ruby-pg@j-davis.com>
8
8
  * - Guy Decoux (ts) <decoux@moulon.inra.fr>
9
9
  * - Michael Granger <ged@FaerieMUD.org>
10
+ * - Lars Kanis <lars@greiz-reinsdorf.de>
10
11
  * - Dave Lee
11
12
  * - Eiji Matsumoto <usagi@ruby.club.or.jp>
12
13
  * - Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -15,10 +16,10 @@
15
16
  * See Contributors.rdoc for the many additional fine people that have contributed
16
17
  * to this library over the years.
17
18
  *
18
- * Copyright (c) 1997-2012 by the authors.
19
+ * Copyright (c) 1997-2019 by the authors.
19
20
  *
20
21
  * You may redistribute this software under the same terms as Ruby itself; see
21
- * http://www.ruby-lang.org/en/LICENSE.txt or the LICENSE file in the source
22
+ * https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source
22
23
  * for details.
23
24
  *
24
25
  * Portions of the code are from the PostgreSQL project, and are distributed
@@ -32,7 +33,6 @@
32
33
  *
33
34
  * - PQfreemem -- unnecessary: copied to ruby object, then freed. Ruby object's
34
35
  * memory is freed when it is garbage collected.
35
- * - PQbinaryTuples -- better to use PQfformat
36
36
  * - PQprint -- not very useful
37
37
  * - PQsetdb -- not very useful
38
38
  * - PQoidStatus -- deprecated, use PQoidValue
@@ -47,6 +47,7 @@
47
47
 
48
48
  #include "pg.h"
49
49
 
50
+ int pg_skip_deprecation_warning;
50
51
  VALUE rb_mPG;
51
52
  VALUE rb_mPGconstants;
52
53
 
@@ -68,11 +69,11 @@ VALUE rb_mPGconstants;
68
69
  * M17n functions
69
70
  */
70
71
 
71
- #ifdef M17N_SUPPORTED
72
72
  /**
73
73
  * The mapping from canonical encoding names in PostgreSQL to ones in Ruby.
74
74
  */
75
75
  const char * const (pg_enc_pg2ruby_mapping[][2]) = {
76
+ {"UTF8", "UTF-8" },
76
77
  {"BIG5", "Big5" },
77
78
  {"EUC_CN", "GB2312" },
78
79
  {"EUC_JP", "EUC-JP" },
@@ -104,7 +105,6 @@ const char * const (pg_enc_pg2ruby_mapping[][2]) = {
104
105
  {"SHIFT_JIS_2004","Windows-31J" },
105
106
  /* {"SQL_ASCII", NULL }, special case*/
106
107
  {"UHC", "CP949" },
107
- {"UTF8", "UTF-8" },
108
108
  {"WIN866", "IBM866" },
109
109
  {"WIN874", "Windows-874" },
110
110
  {"WIN1250", "Windows-1250"},
@@ -119,59 +119,17 @@ const char * const (pg_enc_pg2ruby_mapping[][2]) = {
119
119
  };
120
120
 
121
121
 
122
- /*
123
- * A cache of mapping from PostgreSQL's encoding indices to Ruby's rb_encoding*s.
124
- */
125
- static struct st_table *enc_pg2ruby;
126
-
127
-
128
- /*
129
- * Look up the JOHAB encoding, creating it as a dummy encoding if it's not
130
- * already defined.
131
- */
132
- static rb_encoding *
133
- pg_find_or_create_johab(void)
134
- {
135
- static const char * const aliases[] = { "JOHAB", "Windows-1361", "CP1361" };
136
- int enc_index;
137
- size_t i;
138
-
139
- for (i = 0; i < sizeof(aliases)/sizeof(aliases[0]); ++i) {
140
- enc_index = rb_enc_find_index(aliases[i]);
141
- if (enc_index > 0) return rb_enc_from_index(enc_index);
142
- }
143
-
144
- enc_index = rb_define_dummy_encoding(aliases[0]);
145
- for (i = 1; i < sizeof(aliases)/sizeof(aliases[0]); ++i) {
146
- ENC_ALIAS(aliases[i], aliases[0]);
147
- }
148
- return rb_enc_from_index(enc_index);
149
- }
150
-
151
122
  /*
152
123
  * Return the given PostgreSQL encoding ID as an rb_encoding.
153
124
  *
154
125
  * - returns NULL if the client encoding is 'SQL_ASCII'.
155
126
  * - returns ASCII-8BIT if the client encoding is unknown.
156
127
  */
157
- rb_encoding *
128
+ static rb_encoding *
158
129
  pg_get_pg_encoding_as_rb_encoding( int enc_id )
159
130
  {
160
- rb_encoding *enc;
161
-
162
- /* Use the cached value if it exists */
163
- if ( st_lookup(enc_pg2ruby, (st_data_t)enc_id, (st_data_t*)&enc) ) {
164
- return enc;
165
- }
166
- else {
167
- const char *name = pg_encoding_to_char( enc_id );
168
-
169
- enc = pg_get_pg_encname_as_rb_encoding( name );
170
- st_insert( enc_pg2ruby, (st_data_t)enc_id, (st_data_t)enc );
171
-
172
- return enc;
173
- }
174
-
131
+ const char *name = pg_encoding_to_char( enc_id );
132
+ return pg_get_pg_encname_as_rb_encoding( name );
175
133
  }
176
134
 
177
135
  /*
@@ -188,10 +146,6 @@ pg_get_pg_encname_as_rb_encoding( const char *pg_encname )
188
146
  return rb_enc_find( pg_enc_pg2ruby_mapping[i][1] );
189
147
  }
190
148
 
191
- /* JOHAB isn't a builtin encoding, so make up a dummy encoding if it's seen */
192
- if ( strncmp(pg_encname, "JOHAB", 5) == 0 )
193
- return pg_find_or_create_johab();
194
-
195
149
  /* Fallthrough to ASCII-8BIT */
196
150
  return rb_ascii8bit_encoding();
197
151
  }
@@ -228,8 +182,6 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
228
182
  return encname;
229
183
  }
230
184
 
231
- #endif /* M17N_SUPPORTED */
232
-
233
185
 
234
186
  /*
235
187
  * Ensures that the given string has enough capacity to take expand_len
@@ -252,52 +204,33 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
252
204
  * char *current_out, *end_capa;
253
205
  * PG_RB_STR_NEW( string, current_out, end_capa );
254
206
  * while( data_is_going_to_be_processed ){
255
- * PG_RB_STR_ENSURE_CAPA( string, 2 current_out, end_capa );
207
+ * PG_RB_STR_ENSURE_CAPA( string, 2, current_out, end_capa );
256
208
  * *current_out++ = databyte1;
257
209
  * *current_out++ = databyte2;
258
210
  * }
259
211
  * rb_str_set_len( string, current_out - RSTRING_PTR(string) );
260
212
  *
261
213
  */
262
- #ifdef HAVE_RB_STR_MODIFY_EXPAND
263
- /* Use somewhat faster version with access to string capacity on MRI */
264
- char *
265
- pg_rb_str_ensure_capa( VALUE str, long expand_len, char *curr_ptr, char **end_ptr )
266
- {
267
- long curr_len = curr_ptr - RSTRING_PTR(str);
268
- long curr_capa = rb_str_capacity( str );
269
- if( curr_capa < curr_len + expand_len ){
270
- rb_str_set_len( str, curr_len );
271
- rb_str_modify_expand( str, (curr_len + expand_len) * 2 - curr_capa );
272
- curr_ptr = RSTRING_PTR(str) + curr_len;
273
- }
274
- if( end_ptr )
275
- *end_ptr = RSTRING_PTR(str) + rb_str_capacity( str );
276
- return curr_ptr;
277
- }
278
- #else
279
- /* Use the more portable version */
280
- char *
281
- pg_rb_str_ensure_capa( VALUE str, long expand_len, char *curr_ptr, char **end_ptr )
282
- {
283
- long curr_len = curr_ptr - RSTRING_PTR(str);
284
- long curr_capa = RSTRING_LEN( str );
285
- if( curr_capa < curr_len + expand_len ){
286
- rb_str_resize( str, (curr_len + expand_len) * 2 - curr_capa );
287
- curr_ptr = RSTRING_PTR(str) + curr_len;
288
- }
289
- if( end_ptr )
290
- *end_ptr = RSTRING_PTR(str) + RSTRING_LEN(str);
291
- return curr_ptr;
214
+ char *
215
+ pg_rb_str_ensure_capa( VALUE str, long expand_len, char *curr_ptr, char **end_ptr )
216
+ {
217
+ long curr_len = curr_ptr - RSTRING_PTR(str);
218
+ long curr_capa = rb_str_capacity( str );
219
+ if( curr_capa < curr_len + expand_len ){
220
+ rb_str_set_len( str, curr_len );
221
+ rb_str_modify_expand( str, (curr_len + expand_len) * 2 - curr_capa );
222
+ curr_ptr = RSTRING_PTR(str) + curr_len;
292
223
  }
293
- #endif
224
+ if( end_ptr )
225
+ *end_ptr = RSTRING_PTR(str) + rb_str_capacity( str );
226
+ return curr_ptr;
227
+ }
294
228
 
295
229
 
296
230
  /**************************************************************************
297
231
  * Module Methods
298
232
  **************************************************************************/
299
233
 
300
- #ifdef HAVE_PQLIBVERSION
301
234
  /*
302
235
  * call-seq:
303
236
  * PG.library_version -> Integer
@@ -315,7 +248,6 @@ pg_s_library_version(VALUE self)
315
248
  UNUSED( self );
316
249
  return INT2NUM(PQlibVersion());
317
250
  }
318
- #endif
319
251
 
320
252
 
321
253
  /*
@@ -355,8 +287,7 @@ pg_to_bool_int(VALUE value)
355
287
  * If your application initializes libssl and/or libcrypto libraries and libpq is
356
288
  * built with SSL support, you should call PG.init_openssl() to tell libpq that the
357
289
  * libssl and/or libcrypto libraries have been initialized by your application,
358
- * so that libpq will not also initialize those libraries. See
359
- * http://h71000.www7.hp.com/doc/83final/BA554_90007/ch04.html for details on the SSL API.
290
+ * so that libpq will not also initialize those libraries.
360
291
  *
361
292
  * When do_ssl is +true+, libpq will initialize the OpenSSL library before first
362
293
  * opening a database connection. When do_crypto is +true+, the libcrypto library
@@ -401,23 +332,33 @@ pg_s_init_ssl(VALUE self, VALUE do_ssl)
401
332
  **************************************************************************/
402
333
 
403
334
  void
404
- Init_pg_ext()
335
+ Init_pg_ext(void)
405
336
  {
337
+
338
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
339
+ rb_ext_ractor_safe(PQisthreadsafe());
340
+ #endif
341
+
342
+ if( RTEST(rb_eval_string("ENV['PG_SKIP_DEPRECATION_WARNING']")) ){
343
+ /* Set all bits to disable all deprecation warnings. */
344
+ pg_skip_deprecation_warning = 0xFFFF;
345
+ } else {
346
+ pg_skip_deprecation_warning = 0;
347
+ }
348
+
406
349
  rb_mPG = rb_define_module( "PG" );
407
350
  rb_mPGconstants = rb_define_module_under( rb_mPG, "Constants" );
408
351
 
409
352
  /*************************
410
353
  * PG module methods
411
354
  *************************/
412
- #ifdef HAVE_PQLIBVERSION
413
355
  rb_define_singleton_method( rb_mPG, "library_version", pg_s_library_version, 0 );
414
- #endif
415
356
  rb_define_singleton_method( rb_mPG, "isthreadsafe", pg_s_threadsafe_p, 0 );
416
357
  SINGLETON_ALIAS( rb_mPG, "is_threadsafe?", "isthreadsafe" );
417
358
  SINGLETON_ALIAS( rb_mPG, "threadsafe?", "isthreadsafe" );
418
359
 
419
- rb_define_singleton_method( rb_mPG, "init_openssl", pg_s_init_openssl, 2 );
420
- rb_define_singleton_method( rb_mPG, "init_ssl", pg_s_init_ssl, 1 );
360
+ rb_define_singleton_method( rb_mPG, "init_openssl", pg_s_init_openssl, 2 );
361
+ rb_define_singleton_method( rb_mPG, "init_ssl", pg_s_init_ssl, 1 );
421
362
 
422
363
 
423
364
  /****** PG::Connection CLASS CONSTANTS: Connection Status ******/
@@ -435,14 +376,34 @@ Init_pg_ext()
435
376
  rb_define_const(rb_mPGconstants, "CONNECTION_MADE", INT2FIX(CONNECTION_MADE));
436
377
  /* Waiting for a response from the server. */
437
378
  rb_define_const(rb_mPGconstants, "CONNECTION_AWAITING_RESPONSE", INT2FIX(CONNECTION_AWAITING_RESPONSE));
438
- /* Received authentication; waiting for backend start-up to finish. */
379
+ /* Received authentication; waiting for backend startup. */
439
380
  rb_define_const(rb_mPGconstants, "CONNECTION_AUTH_OK", INT2FIX(CONNECTION_AUTH_OK));
381
+ /* This state is no longer used. */
382
+ rb_define_const(rb_mPGconstants, "CONNECTION_SETENV", INT2FIX(CONNECTION_SETENV));
440
383
  /* Negotiating SSL encryption. */
441
384
  rb_define_const(rb_mPGconstants, "CONNECTION_SSL_STARTUP", INT2FIX(CONNECTION_SSL_STARTUP));
442
- /* Negotiating environment-driven parameter settings. */
443
- rb_define_const(rb_mPGconstants, "CONNECTION_SETENV", INT2FIX(CONNECTION_SETENV));
444
- /* Internal state: connect() needed. */
385
+ /* Internal state - PG.connect() needed. */
445
386
  rb_define_const(rb_mPGconstants, "CONNECTION_NEEDED", INT2FIX(CONNECTION_NEEDED));
387
+ #if PG_MAJORVERSION_NUM >= 10
388
+ /* Checking if session is read-write. Available since PostgreSQL-10. */
389
+ rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_WRITABLE", INT2FIX(CONNECTION_CHECK_WRITABLE));
390
+ #endif
391
+ #if PG_MAJORVERSION_NUM >= 10
392
+ /* Consuming any extra messages. Available since PostgreSQL-10. */
393
+ rb_define_const(rb_mPGconstants, "CONNECTION_CONSUME", INT2FIX(CONNECTION_CONSUME));
394
+ #endif
395
+ #if PG_MAJORVERSION_NUM >= 12
396
+ /* Negotiating GSSAPI. Available since PostgreSQL-12. */
397
+ rb_define_const(rb_mPGconstants, "CONNECTION_GSS_STARTUP", INT2FIX(CONNECTION_GSS_STARTUP));
398
+ #endif
399
+ #if PG_MAJORVERSION_NUM >= 13
400
+ /* Checking target server properties. Available since PostgreSQL-13. */
401
+ rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_TARGET", INT2FIX(CONNECTION_CHECK_TARGET));
402
+ #endif
403
+ #if PG_MAJORVERSION_NUM >= 14
404
+ /* Checking if server is in standby mode. Available since PostgreSQL-14. */
405
+ rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_STANDBY", INT2FIX(CONNECTION_CHECK_STANDBY));
406
+ #endif
446
407
 
447
408
  /****** PG::Connection CLASS CONSTANTS: Nonblocking connection polling status ******/
448
409
 
@@ -457,27 +418,48 @@ Init_pg_ext()
457
418
 
458
419
  /****** PG::Connection CLASS CONSTANTS: Transaction Status ******/
459
420
 
460
- /* Transaction is currently idle (#transaction_status) */
421
+ /* Transaction is currently idle ( Connection#transaction_status ) */
461
422
  rb_define_const(rb_mPGconstants, "PQTRANS_IDLE", INT2FIX(PQTRANS_IDLE));
462
- /* Transaction is currently active; query has been sent to the server, but not yet completed. (#transaction_status) */
423
+ /* Transaction is currently active; query has been sent to the server, but not yet completed. ( Connection#transaction_status ) */
463
424
  rb_define_const(rb_mPGconstants, "PQTRANS_ACTIVE", INT2FIX(PQTRANS_ACTIVE));
464
- /* Transaction is currently idle, in a valid transaction block (#transaction_status) */
425
+ /* Transaction is currently idle, in a valid transaction block ( Connection#transaction_status ) */
465
426
  rb_define_const(rb_mPGconstants, "PQTRANS_INTRANS", INT2FIX(PQTRANS_INTRANS));
466
- /* Transaction is currently idle, in a failed transaction block (#transaction_status) */
427
+ /* Transaction is currently idle, in a failed transaction block ( Connection#transaction_status ) */
467
428
  rb_define_const(rb_mPGconstants, "PQTRANS_INERROR", INT2FIX(PQTRANS_INERROR));
468
- /* Transaction's connection is bad (#transaction_status) */
429
+ /* Transaction's connection is bad ( Connection#transaction_status ) */
469
430
  rb_define_const(rb_mPGconstants, "PQTRANS_UNKNOWN", INT2FIX(PQTRANS_UNKNOWN));
470
431
 
471
432
  /****** PG::Connection CLASS CONSTANTS: Error Verbosity ******/
472
433
 
473
- /* Terse error verbosity level (#set_error_verbosity) */
434
+ /* Error verbosity level ( Connection#set_error_verbosity ).
435
+ * In TERSE mode, returned messages include severity, primary text, and position only; this will normally fit on a single line. */
474
436
  rb_define_const(rb_mPGconstants, "PQERRORS_TERSE", INT2FIX(PQERRORS_TERSE));
475
- /* Default error verbosity level (#set_error_verbosity) */
437
+ /* Error verbosity level ( Connection#set_error_verbosity ).
438
+ * The DEFAULT mode produces messages that include the above plus any detail, hint, or context fields (these might span multiple lines). */
476
439
  rb_define_const(rb_mPGconstants, "PQERRORS_DEFAULT", INT2FIX(PQERRORS_DEFAULT));
477
- /* Verbose error verbosity level (#set_error_verbosity) */
440
+ /* Error verbosity level ( Connection#set_error_verbosity ).
441
+ * The VERBOSE mode includes all available fields. */
478
442
  rb_define_const(rb_mPGconstants, "PQERRORS_VERBOSE", INT2FIX(PQERRORS_VERBOSE));
479
443
 
480
- #ifdef HAVE_PQPING
444
+ /* PQERRORS_SQLSTATE was introduced in PG-12 together with PQresultMemorySize() */
445
+ #ifdef HAVE_PQRESULTMEMORYSIZE
446
+ /* Error verbosity level ( Connection#set_error_verbosity ).
447
+ * The SQLSTATE mode includes only the error severity and the SQLSTATE error code, if one is available (if not, the output is like TERSE mode).
448
+ *
449
+ * Available since PostgreSQL-12.
450
+ */
451
+ rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
452
+ #endif
453
+
454
+ #ifdef HAVE_PQRESULTVERBOSEERRORMESSAGE
455
+ /* See Connection#set_error_context_visibility */
456
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_NEVER", INT2FIX(PQSHOW_CONTEXT_NEVER));
457
+ /* See Connection#set_error_context_visibility */
458
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_ERRORS", INT2FIX(PQSHOW_CONTEXT_ERRORS));
459
+ /* See Connection#set_error_context_visibility */
460
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_ALWAYS", INT2FIX(PQSHOW_CONTEXT_ALWAYS));
461
+ #endif
462
+
481
463
  /****** PG::Connection CLASS CONSTANTS: Check Server Status ******/
482
464
 
483
465
  /* Server is accepting connections. */
@@ -488,163 +470,206 @@ Init_pg_ext()
488
470
  rb_define_const(rb_mPGconstants, "PQPING_NO_RESPONSE", INT2FIX(PQPING_NO_RESPONSE));
489
471
  /* Connection not attempted (bad params). */
490
472
  rb_define_const(rb_mPGconstants, "PQPING_NO_ATTEMPT", INT2FIX(PQPING_NO_ATTEMPT));
491
- #endif
492
473
 
493
474
  /****** PG::Connection CLASS CONSTANTS: Large Objects ******/
494
475
 
495
- /* Flag for #lo_creat, #lo_open -- open for writing */
476
+ /* Flag for Connection#lo_creat, Connection#lo_open -- open for writing */
496
477
  rb_define_const(rb_mPGconstants, "INV_WRITE", INT2FIX(INV_WRITE));
497
- /* Flag for #lo_creat, #lo_open -- open for reading */
478
+ /* Flag for Connection#lo_creat, Connection#lo_open -- open for reading */
498
479
  rb_define_const(rb_mPGconstants, "INV_READ", INT2FIX(INV_READ));
499
- /* Flag for #lo_lseek -- seek from object start */
480
+ /* Flag for Connection#lo_lseek -- seek from object start */
500
481
  rb_define_const(rb_mPGconstants, "SEEK_SET", INT2FIX(SEEK_SET));
501
- /* Flag for #lo_lseek -- seek from current position */
482
+ /* Flag for Connection#lo_lseek -- seek from current position */
502
483
  rb_define_const(rb_mPGconstants, "SEEK_CUR", INT2FIX(SEEK_CUR));
503
- /* Flag for #lo_lseek -- seek from object end */
484
+ /* Flag for Connection#lo_lseek -- seek from object end */
504
485
  rb_define_const(rb_mPGconstants, "SEEK_END", INT2FIX(SEEK_END));
505
486
 
506
487
  /****** PG::Result CONSTANTS: result status ******/
507
488
 
508
- /* #result_status constant: The string sent to the server was empty. */
489
+ /* Result#result_status constant - The string sent to the server was empty. */
509
490
  rb_define_const(rb_mPGconstants, "PGRES_EMPTY_QUERY", INT2FIX(PGRES_EMPTY_QUERY));
510
- /* #result_status constant: Successful completion of a command returning no data. */
491
+ /* Result#result_status constant - Successful completion of a command returning no data. */
511
492
  rb_define_const(rb_mPGconstants, "PGRES_COMMAND_OK", INT2FIX(PGRES_COMMAND_OK));
512
- /* #result_status constant: Successful completion of a command returning data
513
- (such as a SELECT or SHOW). */
493
+ /* Result#result_status constant - Successful completion of a command returning data (such as a SELECT or SHOW). */
514
494
  rb_define_const(rb_mPGconstants, "PGRES_TUPLES_OK", INT2FIX(PGRES_TUPLES_OK));
515
- /* #result_status constant: Copy Out (from server) data transfer started. */
495
+ /* Result#result_status constant - Copy Out (from server) data transfer started. */
516
496
  rb_define_const(rb_mPGconstants, "PGRES_COPY_OUT", INT2FIX(PGRES_COPY_OUT));
517
- /* #result_status constant: Copy In (to server) data transfer started. */
497
+ /* Result#result_status constant - Copy In (to server) data transfer started. */
518
498
  rb_define_const(rb_mPGconstants, "PGRES_COPY_IN", INT2FIX(PGRES_COPY_IN));
519
- /* #result_status constant: The server’s response was not understood. */
499
+ /* Result#result_status constant - The server’s response was not understood. */
520
500
  rb_define_const(rb_mPGconstants, "PGRES_BAD_RESPONSE", INT2FIX(PGRES_BAD_RESPONSE));
521
- /* #result_status constant: A nonfatal error (a notice or warning) occurred. */
501
+ /* Result#result_status constant - A nonfatal error (a notice or warning) occurred. */
522
502
  rb_define_const(rb_mPGconstants, "PGRES_NONFATAL_ERROR",INT2FIX(PGRES_NONFATAL_ERROR));
523
- /* #result_status constant: A fatal error occurred. */
503
+ /* Result#result_status constant - A fatal error occurred. */
524
504
  rb_define_const(rb_mPGconstants, "PGRES_FATAL_ERROR", INT2FIX(PGRES_FATAL_ERROR));
525
- /* #result_status constant: Copy In/Out data transfer in progress. */
526
- #ifdef HAVE_CONST_PGRES_COPY_BOTH
505
+ /* Result#result_status constant - Copy In/Out data transfer in progress. */
527
506
  rb_define_const(rb_mPGconstants, "PGRES_COPY_BOTH", INT2FIX(PGRES_COPY_BOTH));
528
- #endif
529
- /* #result_status constant: Single tuple from larger resultset. */
530
- #ifdef HAVE_CONST_PGRES_SINGLE_TUPLE
507
+ /* Result#result_status constant - Single tuple from larger resultset. */
531
508
  rb_define_const(rb_mPGconstants, "PGRES_SINGLE_TUPLE", INT2FIX(PGRES_SINGLE_TUPLE));
509
+
510
+ #ifdef HAVE_PQENTERPIPELINEMODE
511
+ /* Result#result_status constant - The PG::Result represents a synchronization point in pipeline mode, requested by Connection#pipeline_sync.
512
+ *
513
+ * This status occurs only when pipeline mode has been selected. */
514
+ rb_define_const(rb_mPGconstants, "PGRES_PIPELINE_SYNC", INT2FIX(PGRES_PIPELINE_SYNC));
515
+
516
+ /* Result#result_status constant - The PG::Result represents a pipeline that has received an error from the server.
517
+ *
518
+ * Connection#get_result must be called repeatedly, and each time it will return this status code until the end of the current pipeline, at which point it will return PG::PGRES_PIPELINE_SYNC and normal processing can resume.
519
+ */
520
+ rb_define_const(rb_mPGconstants, "PGRES_PIPELINE_ABORTED", INT2FIX(PGRES_PIPELINE_ABORTED));
532
521
  #endif
533
522
 
534
523
  /****** Result CONSTANTS: result error field codes ******/
535
524
 
536
- /* #result_error_field argument constant: The severity; the field contents
537
- * are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE,
538
- * DEBUG, INFO, or LOG (in a notice message), or a localized translation
539
- * of one of these. Always present.
525
+ /* Result#result_error_field argument constant
526
+ *
527
+ * The severity; the field contents are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message), or a localized translation
528
+ * of one of these.
529
+ * Always present.
540
530
  */
541
531
  rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY", INT2FIX(PG_DIAG_SEVERITY));
542
532
 
543
- /* #result_error_field argument constant: The SQLSTATE code for the
544
- * error. The SQLSTATE code identies the type of error that has occurred;
545
- * it can be used by front-end applications to perform specic operations
546
- * (such as er- ror handling) in response to a particular database
547
- * error. For a list of the possible SQLSTATE codes, see Appendix A.
548
- * This eld is not localizable, and is always present.
533
+ #ifdef PG_DIAG_SEVERITY_NONLOCALIZED
534
+ /* Result#result_error_field argument constant
535
+ *
536
+ * The severity; the field contents are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message).
537
+ * This is identical to the PG_DIAG_SEVERITY field except that the contents are never localized.
538
+ *
539
+ * Available since PostgreSQL-9.6
540
+ */
541
+ rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY_NONLOCALIZED", INT2FIX(PG_DIAG_SEVERITY_NONLOCALIZED));
542
+ #endif
543
+ /* Result#result_error_field argument constant
544
+ *
545
+ * The SQLSTATE code for the error.
546
+ * The SQLSTATE code identies the type of error that has occurred; it can be used by front-end applications to perform specific operations (such as error handling) in response to a particular database error.
547
+ * For a list of the possible SQLSTATE codes, see Appendix A.
548
+ * This field is not localizable, and is always present.
549
549
  */
550
550
  rb_define_const(rb_mPGconstants, "PG_DIAG_SQLSTATE", INT2FIX(PG_DIAG_SQLSTATE));
551
-
552
- /* #result_error_field argument constant: The primary human-readable
553
- * error message (typically one line). Always present. */
551
+ /* Result#result_error_field argument constant
552
+ *
553
+ * The primary human-readable error message (typically one line).
554
+ * Always present. */
554
555
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_PRIMARY", INT2FIX(PG_DIAG_MESSAGE_PRIMARY));
555
-
556
- /* #result_error_field argument constant: Detail: an optional secondary
557
- * error message carrying more detail about the problem. Might run to
558
- * multiple lines.
556
+ /* Result#result_error_field argument constant
557
+ *
558
+ * Detail: an optional secondary error message carrying more detail about the problem.
559
+ * Might run to multiple lines.
559
560
  */
560
561
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_DETAIL", INT2FIX(PG_DIAG_MESSAGE_DETAIL));
561
-
562
- /* #result_error_field argument constant: Hint: an optional suggestion
563
- * what to do about the problem. This is intended to differ from detail
564
- * in that it offers advice (potentially inappropriate) rather than
565
- * hard facts. Might run to multiple lines.
562
+ /* Result#result_error_field argument constant
563
+ *
564
+ * Hint: an optional suggestion what to do about the problem.
565
+ * This is intended to differ from detail in that it offers advice (potentially inappropriate) rather than hard facts.
566
+ * Might run to multiple lines.
566
567
  */
567
-
568
568
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_HINT", INT2FIX(PG_DIAG_MESSAGE_HINT));
569
- /* #result_error_field argument constant: A string containing a decimal
570
- * integer indicating an error cursor position as an index into the
571
- * original statement string. The rst character has index 1, and
572
- * positions are measured in characters not bytes.
569
+ /* Result#result_error_field argument constant
570
+ *
571
+ * A string containing a decimal integer indicating an error cursor position as an index into the original statement string.
572
+ *
573
+ * The first character has index 1, and positions are measured in characters not bytes.
573
574
  */
574
-
575
575
  rb_define_const(rb_mPGconstants, "PG_DIAG_STATEMENT_POSITION", INT2FIX(PG_DIAG_STATEMENT_POSITION));
576
- /* #result_error_field argument constant: This is dened the same as
577
- * the PG_DIAG_STATEMENT_POSITION eld, but it is used when the cursor
578
- * position refers to an internally generated command rather than the
579
- * one submitted by the client. The PG_DIAG_INTERNAL_QUERY eld will
580
- * always appear when this eld appears.
576
+ /* Result#result_error_field argument constant
577
+ *
578
+ * This is defined the same as the PG_DIAG_STATEMENT_POSITION field, but it is used when the cursor position refers to an internally generated command rather than the one submitted by the client.
579
+ * The PG_DIAG_INTERNAL_QUERY field will always appear when this field appears.
581
580
  */
582
-
583
581
  rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_POSITION", INT2FIX(PG_DIAG_INTERNAL_POSITION));
584
- /* #result_error_field argument constant: The text of a failed
585
- * internally-generated command. This could be, for example, a SQL
586
- * query issued by a PL/pgSQL function.
582
+ /* Result#result_error_field argument constant
583
+ *
584
+ * The text of a failed internally-generated command.
585
+ * This could be, for example, a SQL query issued by a PL/pgSQL function.
587
586
  */
588
-
589
587
  rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_QUERY", INT2FIX(PG_DIAG_INTERNAL_QUERY));
590
- /* #result_error_field argument constant: An indication of the context
591
- * in which the error occurred. Presently this includes a call stack
592
- * traceback of active procedural language functions and internally-generated
593
- * queries. The trace is one entry per line, most recent rst.
588
+ /* Result#result_error_field argument constant
589
+ *
590
+ * An indication of the context in which the error occurred.
591
+ * Presently this includes a call stack traceback of active procedural language functions and internally-generated queries.
592
+ * The trace is one entry per line, most recent first.
594
593
  */
595
-
596
594
  rb_define_const(rb_mPGconstants, "PG_DIAG_CONTEXT", INT2FIX(PG_DIAG_CONTEXT));
597
- /* #result_error_field argument constant: The le name of the source-code
598
- * location where the error was reported. */
595
+ /* Result#result_error_field argument constant
596
+ *
597
+ * The file name of the source-code location where the error was reported. */
599
598
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FILE", INT2FIX(PG_DIAG_SOURCE_FILE));
600
599
 
601
- /* #result_error_field argument constant: The line number of the
602
- * source-code location where the error was reported. */
600
+ /* Result#result_error_field argument constant
601
+ *
602
+ * The line number of the source-code location where the error was reported. */
603
603
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_LINE", INT2FIX(PG_DIAG_SOURCE_LINE));
604
604
 
605
- /* #result_error_field argument constant: The name of the source-code
606
- * function reporting the error. */
605
+ /* Result#result_error_field argument constant
606
+ *
607
+ * The name of the source-code function reporting the error. */
607
608
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FUNCTION", INT2FIX(PG_DIAG_SOURCE_FUNCTION));
608
609
 
609
- #ifdef HAVE_CONST_PG_DIAG_TABLE_NAME
610
- /* #result_error_field argument constant: If the error was associated with a
611
- * specific database object, the name of the schema containing that object, if any. */
610
+ #ifdef PG_DIAG_TABLE_NAME
611
+ /* Result#result_error_field argument constant
612
+ *
613
+ * If the error was associated with a specific database object, the name of the schema containing that object, if any. */
612
614
  rb_define_const(rb_mPGconstants, "PG_DIAG_SCHEMA_NAME", INT2FIX(PG_DIAG_SCHEMA_NAME));
613
615
 
614
- /* #result_error_field argument constant: If the error was associated with a
615
- *specific table, the name of the table. (When this field is present, the schema name
616
- * field provides the name of the table's schema.) */
616
+ /* Result#result_error_field argument constant
617
+ *
618
+ * If the error was associated with a specific table, the name of the table.
619
+ * (When this field is present, the schema name field provides the name of the table's schema.) */
617
620
  rb_define_const(rb_mPGconstants, "PG_DIAG_TABLE_NAME", INT2FIX(PG_DIAG_TABLE_NAME));
618
621
 
619
- /* #result_error_field argument constant: If the error was associated with a
620
- * specific table column, the name of the column. (When this field is present, the
621
- * schema and table name fields identify the table.) */
622
+ /* Result#result_error_field argument constant
623
+ *
624
+ * If the error was associated with a specific table column, the name of the column.
625
+ * (When this field is present, the schema and table name fields identify the table.) */
622
626
  rb_define_const(rb_mPGconstants, "PG_DIAG_COLUMN_NAME", INT2FIX(PG_DIAG_COLUMN_NAME));
623
627
 
624
- /* #result_error_field argument constant: If the error was associated with a
625
- * specific datatype, the name of the datatype. (When this field is present, the
626
- * schema name field provides the name of the datatype's schema.) */
628
+ /* Result#result_error_field argument constant
629
+ *
630
+ * If the error was associated with a specific datatype, the name of the datatype.
631
+ * (When this field is present, the schema name field provides the name of the datatype's schema.) */
627
632
  rb_define_const(rb_mPGconstants, "PG_DIAG_DATATYPE_NAME", INT2FIX(PG_DIAG_DATATYPE_NAME));
628
633
 
629
- /* #result_error_field argument constant: If the error was associated with a
630
- * specific constraint, the name of the constraint. The table or domain that the
631
- * constraint belongs to is reported using the fields listed above. (For this
632
- * purpose, indexes are treated as constraints, even if they weren't created with
633
- * constraint syntax.) */
634
+ /* Result#result_error_field argument constant
635
+ *
636
+ * If the error was associated with a specific constraint, the name of the constraint.
637
+ * The table or domain that the constraint belongs to is reported using the fields listed above.
638
+ * (For this purpose, indexes are treated as constraints, even if they weren't created with constraint syntax.) */
634
639
  rb_define_const(rb_mPGconstants, "PG_DIAG_CONSTRAINT_NAME", INT2FIX(PG_DIAG_CONSTRAINT_NAME));
635
640
  #endif
636
641
 
642
+ #ifdef HAVE_PQENTERPIPELINEMODE
643
+ /* Connection#pipeline_status constant
644
+ *
645
+ * The libpq connection is in pipeline mode.
646
+ */
647
+ rb_define_const(rb_mPGconstants, "PQ_PIPELINE_ON", INT2FIX(PQ_PIPELINE_ON));
648
+
649
+ /* Connection#pipeline_status constant
650
+ *
651
+ * The libpq connection is not in pipeline mode.
652
+ */
653
+ rb_define_const(rb_mPGconstants, "PQ_PIPELINE_OFF", INT2FIX(PQ_PIPELINE_OFF));
654
+
655
+ /* Connection#pipeline_status constant
656
+ *
657
+ * The libpq connection is in pipeline mode and an error occurred while processing the current pipeline.
658
+ * The aborted flag is cleared when PQgetResult returns a result of type PGRES_PIPELINE_SYNC.
659
+ */
660
+ rb_define_const(rb_mPGconstants, "PQ_PIPELINE_ABORTED", INT2FIX(PQ_PIPELINE_ABORTED));
661
+ #endif
662
+
637
663
  /* Invalid OID constant */
638
664
  rb_define_const(rb_mPGconstants, "INVALID_OID", INT2FIX(InvalidOid));
639
665
  rb_define_const(rb_mPGconstants, "InvalidOid", INT2FIX(InvalidOid));
640
666
 
667
+ /* PostgreSQL compiled in default port */
668
+ rb_define_const(rb_mPGconstants, "DEF_PGPORT", INT2FIX(DEF_PGPORT));
669
+
641
670
  /* Add the constants to the toplevel namespace */
642
671
  rb_include_module( rb_mPG, rb_mPGconstants );
643
672
 
644
- #ifdef M17N_SUPPORTED
645
- enc_pg2ruby = st_init_numtable();
646
- #endif
647
-
648
673
  /* Initialize the main extension classes */
649
674
  init_pg_connection();
650
675
  init_pg_result();
@@ -662,5 +687,6 @@ Init_pg_ext()
662
687
  init_pg_binary_encoder();
663
688
  init_pg_binary_decoder();
664
689
  init_pg_copycoder();
690
+ init_pg_recordcoder();
691
+ init_pg_tuple();
665
692
  }
666
-