pg 0.21.0 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/ChangeLog +0 -6595
  5. data/History.rdoc +184 -0
  6. data/Manifest.txt +8 -3
  7. data/README-Windows.rdoc +4 -4
  8. data/README.ja.rdoc +1 -2
  9. data/README.rdoc +58 -13
  10. data/Rakefile +10 -9
  11. data/Rakefile.cross +68 -71
  12. data/ext/errorcodes.def +76 -0
  13. data/ext/errorcodes.rb +1 -1
  14. data/ext/errorcodes.txt +21 -2
  15. data/ext/extconf.rb +18 -36
  16. data/ext/gvl_wrappers.c +4 -0
  17. data/ext/gvl_wrappers.h +23 -39
  18. data/ext/pg.c +154 -144
  19. data/ext/pg.h +68 -95
  20. data/ext/pg_binary_decoder.c +82 -15
  21. data/ext/pg_binary_encoder.c +13 -12
  22. data/ext/pg_coder.c +73 -12
  23. data/ext/pg_connection.c +699 -459
  24. data/ext/pg_copy_coder.c +16 -8
  25. data/ext/pg_record_coder.c +491 -0
  26. data/ext/pg_result.c +571 -195
  27. data/ext/pg_text_decoder.c +606 -40
  28. data/ext/pg_text_encoder.c +185 -54
  29. data/ext/pg_tuple.c +549 -0
  30. data/ext/pg_type_map.c +1 -1
  31. data/ext/pg_type_map_all_strings.c +4 -4
  32. data/ext/pg_type_map_by_class.c +9 -4
  33. data/ext/pg_type_map_by_column.c +7 -6
  34. data/ext/pg_type_map_by_mri_type.c +1 -1
  35. data/ext/pg_type_map_by_oid.c +3 -2
  36. data/ext/pg_type_map_in_ruby.c +1 -1
  37. data/ext/{util.c → pg_util.c} +10 -10
  38. data/ext/{util.h → pg_util.h} +2 -2
  39. data/lib/pg.rb +8 -10
  40. data/lib/pg/basic_type_mapping.rb +121 -25
  41. data/lib/pg/binary_decoder.rb +23 -0
  42. data/lib/pg/coder.rb +23 -2
  43. data/lib/pg/connection.rb +28 -4
  44. data/lib/pg/constants.rb +2 -1
  45. data/lib/pg/exceptions.rb +2 -1
  46. data/lib/pg/result.rb +14 -2
  47. data/lib/pg/text_decoder.rb +21 -26
  48. data/lib/pg/text_encoder.rb +32 -8
  49. data/lib/pg/tuple.rb +30 -0
  50. data/lib/pg/type_map_by_column.rb +3 -2
  51. data/spec/helpers.rb +61 -33
  52. data/spec/pg/basic_type_mapping_spec.rb +362 -37
  53. data/spec/pg/connection_spec.rb +602 -329
  54. data/spec/pg/connection_sync_spec.rb +41 -0
  55. data/spec/pg/result_spec.rb +242 -17
  56. data/spec/pg/tuple_spec.rb +333 -0
  57. data/spec/pg/type_map_by_class_spec.rb +2 -2
  58. data/spec/pg/type_map_by_column_spec.rb +6 -2
  59. data/spec/pg/type_map_by_mri_type_spec.rb +1 -1
  60. data/spec/pg/type_map_by_oid_spec.rb +3 -3
  61. data/spec/pg/type_map_in_ruby_spec.rb +1 -1
  62. data/spec/pg/type_map_spec.rb +1 -1
  63. data/spec/pg/type_spec.rb +364 -18
  64. data/spec/pg_spec.rb +2 -2
  65. metadata +48 -43
  66. metadata.gz.sig +0 -0
  67. data/lib/pg/deprecated_constants.rb +0 -21
data/ext/gvl_wrappers.c CHANGED
@@ -5,6 +5,10 @@
5
5
 
6
6
  #include "pg.h"
7
7
 
8
+ #ifndef HAVE_PQENCRYPTPASSWORDCONN
9
+ char *PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm){return NULL;}
10
+ #endif
11
+
8
12
  FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_WRAPPER_STRUCT );
9
13
  FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_SKELETON );
10
14
  FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_STUB );
data/ext/gvl_wrappers.h CHANGED
@@ -15,14 +15,7 @@
15
15
  #ifndef __gvl_wrappers_h
16
16
  #define __gvl_wrappers_h
17
17
 
18
- #if defined(HAVE_RB_THREAD_CALL_WITH_GVL)
19
- extern void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1);
20
- #endif
21
-
22
- #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
23
- extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
24
- rb_unblock_function_t *ubf, void *data2);
25
- #endif
18
+ #include <ruby/thread.h>
26
19
 
27
20
  #define DEFINE_PARAM_LIST1(type, name) \
28
21
  name,
@@ -53,21 +46,14 @@ extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
53
46
  return NULL; \
54
47
  }
55
48
 
56
- #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
57
- #define DEFINE_GVL_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
58
- rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
59
- struct gvl_wrapper_##name##_params params = { \
60
- {FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname}, when_non_void((rettype)0) \
61
- }; \
62
- rb_thread_call_without_gvl(gvl_##name##_skeleton, &params, RUBY_UBF_IO, 0); \
63
- when_non_void( return params.retval; ) \
64
- }
65
- #else
66
- #define DEFINE_GVL_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
67
- rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
68
- return name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname ); \
69
- }
70
- #endif
49
+ #define DEFINE_GVL_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
50
+ rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
51
+ struct gvl_wrapper_##name##_params params = { \
52
+ {FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname}, when_non_void((rettype)0) \
53
+ }; \
54
+ rb_thread_call_without_gvl(gvl_##name##_skeleton, &params, RUBY_UBF_IO, 0); \
55
+ when_non_void( return params.retval; ) \
56
+ }
71
57
 
72
58
  #define DEFINE_GVL_STUB_DECL(name, when_non_void, rettype, lastparamtype, lastparamname) \
73
59
  rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname);
@@ -80,21 +66,14 @@ extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
80
66
  return NULL; \
81
67
  }
82
68
 
83
- #if defined(HAVE_RB_THREAD_CALL_WITH_GVL)
84
- #define DEFINE_GVLCB_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
85
- rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
86
- struct gvl_wrapper_##name##_params params = { \
87
- {FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname}, when_non_void((rettype)0) \
88
- }; \
89
- rb_thread_call_with_gvl(gvl_##name##_skeleton, &params); \
90
- when_non_void( return params.retval; ) \
91
- }
92
- #else
93
- #define DEFINE_GVLCB_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
94
- rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
95
- return name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname ); \
96
- }
97
- #endif
69
+ #define DEFINE_GVLCB_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
70
+ rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
71
+ struct gvl_wrapper_##name##_params params = { \
72
+ {FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname}, when_non_void((rettype)0) \
73
+ }; \
74
+ rb_thread_call_with_gvl(gvl_##name##_skeleton, &params); \
75
+ when_non_void( return params.retval; ) \
76
+ }
98
77
 
99
78
  #define GVL_TYPE_VOID(string)
100
79
  #define GVL_TYPE_NONVOID(string) string
@@ -200,6 +179,11 @@ extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
200
179
 
201
180
  #define FOR_EACH_PARAM_OF_PQisBusy(param)
202
181
 
182
+ #define FOR_EACH_PARAM_OF_PQencryptPasswordConn(param) \
183
+ param(PGconn *, conn) \
184
+ param(const char *, passwd) \
185
+ param(const char *, user)
186
+
203
187
  #define FOR_EACH_PARAM_OF_PQcancel(param) \
204
188
  param(PGcancel *, cancel) \
205
189
  param(char *, errbuf)
@@ -231,9 +215,9 @@ extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
231
215
  function(PQsendDescribePortal, GVL_TYPE_NONVOID, int, const char *, portal) \
232
216
  function(PQsetClientEncoding, GVL_TYPE_NONVOID, int, const char *, encoding) \
233
217
  function(PQisBusy, GVL_TYPE_NONVOID, int, PGconn *, conn) \
218
+ function(PQencryptPasswordConn, GVL_TYPE_NONVOID, char *, const char *, algorithm) \
234
219
  function(PQcancel, GVL_TYPE_NONVOID, int, int, errbufsize);
235
220
 
236
-
237
221
  FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_STUB_DECL );
238
222
 
239
223
 
data/ext/pg.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * pg.c - Toplevel extension
3
- * $Id: pg.c,v c77d0997b4e4 2016/08/20 17:30:03 ged $
3
+ * $Id$
4
4
  *
5
5
  * Author/s:
6
6
  *
@@ -16,7 +16,7 @@
16
16
  * See Contributors.rdoc for the many additional fine people that have contributed
17
17
  * to this library over the years.
18
18
  *
19
- * Copyright (c) 1997-2016 by the authors.
19
+ * Copyright (c) 1997-2019 by the authors.
20
20
  *
21
21
  * You may redistribute this software under the same terms as Ruby itself; see
22
22
  * https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source
@@ -48,6 +48,7 @@
48
48
 
49
49
  #include "pg.h"
50
50
 
51
+ int pg_skip_deprecation_warning;
51
52
  VALUE rb_mPG;
52
53
  VALUE rb_mPGconstants;
53
54
 
@@ -69,7 +70,6 @@ VALUE rb_mPGconstants;
69
70
  * M17n functions
70
71
  */
71
72
 
72
- #ifdef M17N_SUPPORTED
73
73
  /**
74
74
  * The mapping from canonical encoding names in PostgreSQL to ones in Ruby.
75
75
  */
@@ -143,9 +143,6 @@ pg_find_or_create_johab(void)
143
143
  }
144
144
 
145
145
  enc_index = rb_define_dummy_encoding(aliases[0]);
146
- for (i = 1; i < sizeof(aliases)/sizeof(aliases[0]); ++i) {
147
- ENC_ALIAS(aliases[i], aliases[0]);
148
- }
149
146
  return rb_enc_from_index(enc_index);
150
147
  }
151
148
 
@@ -229,8 +226,6 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
229
226
  return encname;
230
227
  }
231
228
 
232
- #endif /* M17N_SUPPORTED */
233
-
234
229
 
235
230
  /*
236
231
  * Ensures that the given string has enough capacity to take expand_len
@@ -260,45 +255,26 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
260
255
  * rb_str_set_len( string, current_out - RSTRING_PTR(string) );
261
256
  *
262
257
  */
263
- #ifdef HAVE_RB_STR_MODIFY_EXPAND
264
- /* Use somewhat faster version with access to string capacity on MRI */
265
- char *
266
- pg_rb_str_ensure_capa( VALUE str, long expand_len, char *curr_ptr, char **end_ptr )
267
- {
268
- long curr_len = curr_ptr - RSTRING_PTR(str);
269
- long curr_capa = rb_str_capacity( str );
270
- if( curr_capa < curr_len + expand_len ){
271
- rb_str_set_len( str, curr_len );
272
- rb_str_modify_expand( str, (curr_len + expand_len) * 2 - curr_capa );
273
- curr_ptr = RSTRING_PTR(str) + curr_len;
274
- }
275
- if( end_ptr )
276
- *end_ptr = RSTRING_PTR(str) + rb_str_capacity( str );
277
- return curr_ptr;
278
- }
279
- #else
280
- /* Use the more portable version */
281
- char *
282
- pg_rb_str_ensure_capa( VALUE str, long expand_len, char *curr_ptr, char **end_ptr )
283
- {
284
- long curr_len = curr_ptr - RSTRING_PTR(str);
285
- long curr_capa = RSTRING_LEN( str );
286
- if( curr_capa < curr_len + expand_len ){
287
- rb_str_resize( str, (curr_len + expand_len) * 2 - curr_capa );
288
- curr_ptr = RSTRING_PTR(str) + curr_len;
289
- }
290
- if( end_ptr )
291
- *end_ptr = RSTRING_PTR(str) + RSTRING_LEN(str);
292
- return curr_ptr;
258
+ char *
259
+ pg_rb_str_ensure_capa( VALUE str, long expand_len, char *curr_ptr, char **end_ptr )
260
+ {
261
+ long curr_len = curr_ptr - RSTRING_PTR(str);
262
+ long curr_capa = rb_str_capacity( str );
263
+ if( curr_capa < curr_len + expand_len ){
264
+ rb_str_set_len( str, curr_len );
265
+ rb_str_modify_expand( str, (curr_len + expand_len) * 2 - curr_capa );
266
+ curr_ptr = RSTRING_PTR(str) + curr_len;
293
267
  }
294
- #endif
268
+ if( end_ptr )
269
+ *end_ptr = RSTRING_PTR(str) + rb_str_capacity( str );
270
+ return curr_ptr;
271
+ }
295
272
 
296
273
 
297
274
  /**************************************************************************
298
275
  * Module Methods
299
276
  **************************************************************************/
300
277
 
301
- #ifdef HAVE_PQLIBVERSION
302
278
  /*
303
279
  * call-seq:
304
280
  * PG.library_version -> Integer
@@ -316,7 +292,6 @@ pg_s_library_version(VALUE self)
316
292
  UNUSED( self );
317
293
  return INT2NUM(PQlibVersion());
318
294
  }
319
- #endif
320
295
 
321
296
 
322
297
  /*
@@ -356,8 +331,7 @@ pg_to_bool_int(VALUE value)
356
331
  * If your application initializes libssl and/or libcrypto libraries and libpq is
357
332
  * built with SSL support, you should call PG.init_openssl() to tell libpq that the
358
333
  * libssl and/or libcrypto libraries have been initialized by your application,
359
- * so that libpq will not also initialize those libraries. See
360
- * http://h71000.www7.hp.com/doc/83final/BA554_90007/ch04.html for details on the SSL API.
334
+ * so that libpq will not also initialize those libraries.
361
335
  *
362
336
  * When do_ssl is +true+, libpq will initialize the OpenSSL library before first
363
337
  * opening a database connection. When do_crypto is +true+, the libcrypto library
@@ -404,15 +378,20 @@ pg_s_init_ssl(VALUE self, VALUE do_ssl)
404
378
  void
405
379
  Init_pg_ext()
406
380
  {
381
+ if( RTEST(rb_eval_string("ENV['PG_SKIP_DEPRECATION_WARNING']")) ){
382
+ /* Set all bits to disable all deprecation warnings. */
383
+ pg_skip_deprecation_warning = 0xFFFF;
384
+ } else {
385
+ pg_skip_deprecation_warning = 0;
386
+ }
387
+
407
388
  rb_mPG = rb_define_module( "PG" );
408
389
  rb_mPGconstants = rb_define_module_under( rb_mPG, "Constants" );
409
390
 
410
391
  /*************************
411
392
  * PG module methods
412
393
  *************************/
413
- #ifdef HAVE_PQLIBVERSION
414
394
  rb_define_singleton_method( rb_mPG, "library_version", pg_s_library_version, 0 );
415
- #endif
416
395
  rb_define_singleton_method( rb_mPG, "isthreadsafe", pg_s_threadsafe_p, 0 );
417
396
  SINGLETON_ALIAS( rb_mPG, "is_threadsafe?", "isthreadsafe" );
418
397
  SINGLETON_ALIAS( rb_mPG, "threadsafe?", "isthreadsafe" );
@@ -442,7 +421,7 @@ Init_pg_ext()
442
421
  rb_define_const(rb_mPGconstants, "CONNECTION_SSL_STARTUP", INT2FIX(CONNECTION_SSL_STARTUP));
443
422
  /* Negotiating environment-driven parameter settings. */
444
423
  rb_define_const(rb_mPGconstants, "CONNECTION_SETENV", INT2FIX(CONNECTION_SETENV));
445
- /* Internal state: connect() needed. */
424
+ /* Internal state - PG.connect() needed. */
446
425
  rb_define_const(rb_mPGconstants, "CONNECTION_NEEDED", INT2FIX(CONNECTION_NEEDED));
447
426
 
448
427
  /****** PG::Connection CLASS CONSTANTS: Nonblocking connection polling status ******/
@@ -458,27 +437,48 @@ Init_pg_ext()
458
437
 
459
438
  /****** PG::Connection CLASS CONSTANTS: Transaction Status ******/
460
439
 
461
- /* Transaction is currently idle (#transaction_status) */
440
+ /* Transaction is currently idle ( Connection#transaction_status ) */
462
441
  rb_define_const(rb_mPGconstants, "PQTRANS_IDLE", INT2FIX(PQTRANS_IDLE));
463
- /* Transaction is currently active; query has been sent to the server, but not yet completed. (#transaction_status) */
442
+ /* Transaction is currently active; query has been sent to the server, but not yet completed. ( Connection#transaction_status ) */
464
443
  rb_define_const(rb_mPGconstants, "PQTRANS_ACTIVE", INT2FIX(PQTRANS_ACTIVE));
465
- /* Transaction is currently idle, in a valid transaction block (#transaction_status) */
444
+ /* Transaction is currently idle, in a valid transaction block ( Connection#transaction_status ) */
466
445
  rb_define_const(rb_mPGconstants, "PQTRANS_INTRANS", INT2FIX(PQTRANS_INTRANS));
467
- /* Transaction is currently idle, in a failed transaction block (#transaction_status) */
446
+ /* Transaction is currently idle, in a failed transaction block ( Connection#transaction_status ) */
468
447
  rb_define_const(rb_mPGconstants, "PQTRANS_INERROR", INT2FIX(PQTRANS_INERROR));
469
- /* Transaction's connection is bad (#transaction_status) */
448
+ /* Transaction's connection is bad ( Connection#transaction_status ) */
470
449
  rb_define_const(rb_mPGconstants, "PQTRANS_UNKNOWN", INT2FIX(PQTRANS_UNKNOWN));
471
450
 
472
451
  /****** PG::Connection CLASS CONSTANTS: Error Verbosity ******/
473
452
 
474
- /* Terse error verbosity level (#set_error_verbosity) */
453
+ /* Error verbosity level ( Connection#set_error_verbosity ).
454
+ * In TERSE mode, returned messages include severity, primary text, and position only; this will normally fit on a single line. */
475
455
  rb_define_const(rb_mPGconstants, "PQERRORS_TERSE", INT2FIX(PQERRORS_TERSE));
476
- /* Default error verbosity level (#set_error_verbosity) */
456
+ /* Error verbosity level ( Connection#set_error_verbosity ).
457
+ * The DEFAULT mode produces messages that include the above plus any detail, hint, or context fields (these might span multiple lines). */
477
458
  rb_define_const(rb_mPGconstants, "PQERRORS_DEFAULT", INT2FIX(PQERRORS_DEFAULT));
478
- /* Verbose error verbosity level (#set_error_verbosity) */
459
+ /* Error verbosity level ( Connection#set_error_verbosity ).
460
+ * The VERBOSE mode includes all available fields. */
479
461
  rb_define_const(rb_mPGconstants, "PQERRORS_VERBOSE", INT2FIX(PQERRORS_VERBOSE));
480
462
 
481
- #ifdef HAVE_PQPING
463
+ /* PQERRORS_SQLSTATE was introduced in PG-12 together with PQresultMemorySize() */
464
+ #ifdef HAVE_PQRESULTMEMORYSIZE
465
+ /* Error verbosity level ( Connection#set_error_verbosity ).
466
+ * 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).
467
+ *
468
+ * Available since PostgreSQL-12.
469
+ */
470
+ rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
471
+ #endif
472
+
473
+ #ifdef HAVE_PQRESULTVERBOSEERRORMESSAGE
474
+ /* See Connection#set_error_context_visibility */
475
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_NEVER", INT2FIX(PQSHOW_CONTEXT_NEVER));
476
+ /* See Connection#set_error_context_visibility */
477
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_ERRORS", INT2FIX(PQSHOW_CONTEXT_ERRORS));
478
+ /* See Connection#set_error_context_visibility */
479
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_ALWAYS", INT2FIX(PQSHOW_CONTEXT_ALWAYS));
480
+ #endif
481
+
482
482
  /****** PG::Connection CLASS CONSTANTS: Check Server Status ******/
483
483
 
484
484
  /* Server is accepting connections. */
@@ -489,149 +489,159 @@ Init_pg_ext()
489
489
  rb_define_const(rb_mPGconstants, "PQPING_NO_RESPONSE", INT2FIX(PQPING_NO_RESPONSE));
490
490
  /* Connection not attempted (bad params). */
491
491
  rb_define_const(rb_mPGconstants, "PQPING_NO_ATTEMPT", INT2FIX(PQPING_NO_ATTEMPT));
492
- #endif
493
492
 
494
493
  /****** PG::Connection CLASS CONSTANTS: Large Objects ******/
495
494
 
496
- /* Flag for #lo_creat, #lo_open -- open for writing */
495
+ /* Flag for Connection#lo_creat, Connection#lo_open -- open for writing */
497
496
  rb_define_const(rb_mPGconstants, "INV_WRITE", INT2FIX(INV_WRITE));
498
- /* Flag for #lo_creat, #lo_open -- open for reading */
497
+ /* Flag for Connection#lo_creat, Connection#lo_open -- open for reading */
499
498
  rb_define_const(rb_mPGconstants, "INV_READ", INT2FIX(INV_READ));
500
- /* Flag for #lo_lseek -- seek from object start */
499
+ /* Flag for Connection#lo_lseek -- seek from object start */
501
500
  rb_define_const(rb_mPGconstants, "SEEK_SET", INT2FIX(SEEK_SET));
502
- /* Flag for #lo_lseek -- seek from current position */
501
+ /* Flag for Connection#lo_lseek -- seek from current position */
503
502
  rb_define_const(rb_mPGconstants, "SEEK_CUR", INT2FIX(SEEK_CUR));
504
- /* Flag for #lo_lseek -- seek from object end */
503
+ /* Flag for Connection#lo_lseek -- seek from object end */
505
504
  rb_define_const(rb_mPGconstants, "SEEK_END", INT2FIX(SEEK_END));
506
505
 
507
506
  /****** PG::Result CONSTANTS: result status ******/
508
507
 
509
- /* #result_status constant: The string sent to the server was empty. */
508
+ /* Result#result_status constant - The string sent to the server was empty. */
510
509
  rb_define_const(rb_mPGconstants, "PGRES_EMPTY_QUERY", INT2FIX(PGRES_EMPTY_QUERY));
511
- /* #result_status constant: Successful completion of a command returning no data. */
510
+ /* Result#result_status constant - Successful completion of a command returning no data. */
512
511
  rb_define_const(rb_mPGconstants, "PGRES_COMMAND_OK", INT2FIX(PGRES_COMMAND_OK));
513
- /* #result_status constant: Successful completion of a command returning data
514
- (such as a SELECT or SHOW). */
512
+ /* Result#result_status constant - Successful completion of a command returning data (such as a SELECT or SHOW). */
515
513
  rb_define_const(rb_mPGconstants, "PGRES_TUPLES_OK", INT2FIX(PGRES_TUPLES_OK));
516
- /* #result_status constant: Copy Out (from server) data transfer started. */
514
+ /* Result#result_status constant - Copy Out (from server) data transfer started. */
517
515
  rb_define_const(rb_mPGconstants, "PGRES_COPY_OUT", INT2FIX(PGRES_COPY_OUT));
518
- /* #result_status constant: Copy In (to server) data transfer started. */
516
+ /* Result#result_status constant - Copy In (to server) data transfer started. */
519
517
  rb_define_const(rb_mPGconstants, "PGRES_COPY_IN", INT2FIX(PGRES_COPY_IN));
520
- /* #result_status constant: The server’s response was not understood. */
518
+ /* Result#result_status constant - The server’s response was not understood. */
521
519
  rb_define_const(rb_mPGconstants, "PGRES_BAD_RESPONSE", INT2FIX(PGRES_BAD_RESPONSE));
522
- /* #result_status constant: A nonfatal error (a notice or warning) occurred. */
520
+ /* Result#result_status constant - A nonfatal error (a notice or warning) occurred. */
523
521
  rb_define_const(rb_mPGconstants, "PGRES_NONFATAL_ERROR",INT2FIX(PGRES_NONFATAL_ERROR));
524
- /* #result_status constant: A fatal error occurred. */
522
+ /* Result#result_status constant - A fatal error occurred. */
525
523
  rb_define_const(rb_mPGconstants, "PGRES_FATAL_ERROR", INT2FIX(PGRES_FATAL_ERROR));
526
- /* #result_status constant: Copy In/Out data transfer in progress. */
527
- #ifdef HAVE_CONST_PGRES_COPY_BOTH
524
+ /* Result#result_status constant - Copy In/Out data transfer in progress. */
528
525
  rb_define_const(rb_mPGconstants, "PGRES_COPY_BOTH", INT2FIX(PGRES_COPY_BOTH));
529
- #endif
530
- /* #result_status constant: Single tuple from larger resultset. */
531
- #ifdef HAVE_CONST_PGRES_SINGLE_TUPLE
526
+ /* Result#result_status constant - Single tuple from larger resultset. */
532
527
  rb_define_const(rb_mPGconstants, "PGRES_SINGLE_TUPLE", INT2FIX(PGRES_SINGLE_TUPLE));
533
- #endif
534
528
 
535
529
  /****** Result CONSTANTS: result error field codes ******/
536
530
 
537
- /* #result_error_field argument constant: The severity; the field contents
538
- * are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE,
539
- * DEBUG, INFO, or LOG (in a notice message), or a localized translation
540
- * of one of these. Always present.
531
+ /* Result#result_error_field argument constant
532
+ *
533
+ * 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
534
+ * of one of these.
535
+ * Always present.
541
536
  */
542
537
  rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY", INT2FIX(PG_DIAG_SEVERITY));
543
538
 
544
- /* #result_error_field argument constant: The SQLSTATE code for the
545
- * error. The SQLSTATE code identies the type of error that has occurred;
546
- * it can be used by front-end applications to perform specic operations
547
- * (such as er- ror handling) in response to a particular database
548
- * error. For a list of the possible SQLSTATE codes, see Appendix A.
549
- * This eld is not localizable, and is always present.
539
+ #ifdef PG_DIAG_SEVERITY_NONLOCALIZED
540
+ /* Result#result_error_field argument constant
541
+ *
542
+ * 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).
543
+ * This is identical to the PG_DIAG_SEVERITY field except that the contents are never localized.
544
+ *
545
+ * Available since PostgreSQL-9.6
546
+ */
547
+ rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY_NONLOCALIZED", INT2FIX(PG_DIAG_SEVERITY_NONLOCALIZED));
548
+ #endif
549
+ /* Result#result_error_field argument constant
550
+ *
551
+ * The SQLSTATE code for the error.
552
+ * The SQLSTATE code identies the type of error that has occurred; it can be used by front-end applications to perform specic operations (such as error handling) in response to a particular database error.
553
+ * For a list of the possible SQLSTATE codes, see Appendix A.
554
+ * This field is not localizable, and is always present.
550
555
  */
551
556
  rb_define_const(rb_mPGconstants, "PG_DIAG_SQLSTATE", INT2FIX(PG_DIAG_SQLSTATE));
552
-
553
- /* #result_error_field argument constant: The primary human-readable
554
- * error message (typically one line). Always present. */
557
+ /* Result#result_error_field argument constant
558
+ *
559
+ * The primary human-readable error message (typically one line).
560
+ * Always present. */
555
561
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_PRIMARY", INT2FIX(PG_DIAG_MESSAGE_PRIMARY));
556
-
557
- /* #result_error_field argument constant: Detail: an optional secondary
558
- * error message carrying more detail about the problem. Might run to
559
- * multiple lines.
562
+ /* Result#result_error_field argument constant
563
+ *
564
+ * Detail: an optional secondary error message carrying more detail about the problem.
565
+ * Might run to multiple lines.
560
566
  */
561
567
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_DETAIL", INT2FIX(PG_DIAG_MESSAGE_DETAIL));
562
-
563
- /* #result_error_field argument constant: Hint: an optional suggestion
564
- * what to do about the problem. This is intended to differ from detail
565
- * in that it offers advice (potentially inappropriate) rather than
566
- * hard facts. Might run to multiple lines.
568
+ /* Result#result_error_field argument constant
569
+ *
570
+ * Hint: an optional suggestion what to do about the problem.
571
+ * This is intended to differ from detail in that it offers advice (potentially inappropriate) rather than hard facts.
572
+ * Might run to multiple lines.
567
573
  */
568
-
569
574
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_HINT", INT2FIX(PG_DIAG_MESSAGE_HINT));
570
- /* #result_error_field argument constant: A string containing a decimal
571
- * integer indicating an error cursor position as an index into the
572
- * original statement string. The rst character has index 1, and
573
- * positions are measured in characters not bytes.
575
+ /* Result#result_error_field argument constant
576
+ *
577
+ * A string containing a decimal integer indicating an error cursor position as an index into the original statement string.
578
+ *
579
+ * The first character has index 1, and positions are measured in characters not bytes.
574
580
  */
575
-
576
581
  rb_define_const(rb_mPGconstants, "PG_DIAG_STATEMENT_POSITION", INT2FIX(PG_DIAG_STATEMENT_POSITION));
577
- /* #result_error_field argument constant: This is dened the same as
578
- * the PG_DIAG_STATEMENT_POSITION eld, but it is used when the cursor
579
- * position refers to an internally generated command rather than the
580
- * one submitted by the client. The PG_DIAG_INTERNAL_QUERY eld will
581
- * always appear when this eld appears.
582
+ /* Result#result_error_field argument constant
583
+ *
584
+ * 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.
585
+ * The PG_DIAG_INTERNAL_QUERY field will always appear when this field appears.
582
586
  */
583
-
584
587
  rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_POSITION", INT2FIX(PG_DIAG_INTERNAL_POSITION));
585
- /* #result_error_field argument constant: The text of a failed
586
- * internally-generated command. This could be, for example, a SQL
587
- * query issued by a PL/pgSQL function.
588
+ /* Result#result_error_field argument constant
589
+ *
590
+ * The text of a failed internally-generated command.
591
+ * This could be, for example, a SQL query issued by a PL/pgSQL function.
588
592
  */
589
-
590
593
  rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_QUERY", INT2FIX(PG_DIAG_INTERNAL_QUERY));
591
- /* #result_error_field argument constant: An indication of the context
592
- * in which the error occurred. Presently this includes a call stack
593
- * traceback of active procedural language functions and internally-generated
594
- * queries. The trace is one entry per line, most recent rst.
594
+ /* Result#result_error_field argument constant
595
+ *
596
+ * An indication of the context in which the error occurred.
597
+ * Presently this includes a call stack traceback of active procedural language functions and internally-generated queries.
598
+ * The trace is one entry per line, most recent first.
595
599
  */
596
-
597
600
  rb_define_const(rb_mPGconstants, "PG_DIAG_CONTEXT", INT2FIX(PG_DIAG_CONTEXT));
598
- /* #result_error_field argument constant: The le name of the source-code
599
- * location where the error was reported. */
601
+ /* Result#result_error_field argument constant
602
+ *
603
+ * The file name of the source-code location where the error was reported. */
600
604
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FILE", INT2FIX(PG_DIAG_SOURCE_FILE));
601
605
 
602
- /* #result_error_field argument constant: The line number of the
603
- * source-code location where the error was reported. */
606
+ /* Result#result_error_field argument constant
607
+ *
608
+ * The line number of the source-code location where the error was reported. */
604
609
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_LINE", INT2FIX(PG_DIAG_SOURCE_LINE));
605
610
 
606
- /* #result_error_field argument constant: The name of the source-code
607
- * function reporting the error. */
611
+ /* Result#result_error_field argument constant
612
+ *
613
+ * The name of the source-code function reporting the error. */
608
614
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FUNCTION", INT2FIX(PG_DIAG_SOURCE_FUNCTION));
609
615
 
610
- #ifdef HAVE_CONST_PG_DIAG_TABLE_NAME
611
- /* #result_error_field argument constant: If the error was associated with a
612
- * specific database object, the name of the schema containing that object, if any. */
616
+ #ifdef PG_DIAG_TABLE_NAME
617
+ /* Result#result_error_field argument constant
618
+ *
619
+ * If the error was associated with a specific database object, the name of the schema containing that object, if any. */
613
620
  rb_define_const(rb_mPGconstants, "PG_DIAG_SCHEMA_NAME", INT2FIX(PG_DIAG_SCHEMA_NAME));
614
621
 
615
- /* #result_error_field argument constant: If the error was associated with a
616
- *specific table, the name of the table. (When this field is present, the schema name
617
- * field provides the name of the table's schema.) */
622
+ /* Result#result_error_field argument constant
623
+ *
624
+ * If the error was associated with a specific table, the name of the table.
625
+ * (When this field is present, the schema name field provides the name of the table's schema.) */
618
626
  rb_define_const(rb_mPGconstants, "PG_DIAG_TABLE_NAME", INT2FIX(PG_DIAG_TABLE_NAME));
619
627
 
620
- /* #result_error_field argument constant: If the error was associated with a
621
- * specific table column, the name of the column. (When this field is present, the
622
- * schema and table name fields identify the table.) */
628
+ /* Result#result_error_field argument constant
629
+ *
630
+ * If the error was associated with a specific table column, the name of the column.
631
+ * (When this field is present, the schema and table name fields identify the table.) */
623
632
  rb_define_const(rb_mPGconstants, "PG_DIAG_COLUMN_NAME", INT2FIX(PG_DIAG_COLUMN_NAME));
624
633
 
625
- /* #result_error_field argument constant: If the error was associated with a
626
- * specific datatype, the name of the datatype. (When this field is present, the
627
- * schema name field provides the name of the datatype's schema.) */
634
+ /* Result#result_error_field argument constant
635
+ *
636
+ * If the error was associated with a specific datatype, the name of the datatype.
637
+ * (When this field is present, the schema name field provides the name of the datatype's schema.) */
628
638
  rb_define_const(rb_mPGconstants, "PG_DIAG_DATATYPE_NAME", INT2FIX(PG_DIAG_DATATYPE_NAME));
629
639
 
630
- /* #result_error_field argument constant: If the error was associated with a
631
- * specific constraint, the name of the constraint. The table or domain that the
632
- * constraint belongs to is reported using the fields listed above. (For this
633
- * purpose, indexes are treated as constraints, even if they weren't created with
634
- * constraint syntax.) */
640
+ /* Result#result_error_field argument constant
641
+ *
642
+ * If the error was associated with a specific constraint, the name of the constraint.
643
+ * The table or domain that the constraint belongs to is reported using the fields listed above.
644
+ * (For this purpose, indexes are treated as constraints, even if they weren't created with constraint syntax.) */
635
645
  rb_define_const(rb_mPGconstants, "PG_DIAG_CONSTRAINT_NAME", INT2FIX(PG_DIAG_CONSTRAINT_NAME));
636
646
  #endif
637
647
 
@@ -642,9 +652,7 @@ Init_pg_ext()
642
652
  /* Add the constants to the toplevel namespace */
643
653
  rb_include_module( rb_mPG, rb_mPGconstants );
644
654
 
645
- #ifdef M17N_SUPPORTED
646
655
  enc_pg2ruby = st_init_numtable();
647
- #endif
648
656
 
649
657
  /* Initialize the main extension classes */
650
658
  init_pg_connection();
@@ -663,5 +671,7 @@ Init_pg_ext()
663
671
  init_pg_binary_encoder();
664
672
  init_pg_binary_decoder();
665
673
  init_pg_copycoder();
674
+ init_pg_recordcoder();
675
+ init_pg_tuple();
666
676
  }
667
677