pg 1.1.3 → 1.3.3

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 (117) hide show
  1. checksums.yaml +4 -4
  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 +129 -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 +210 -6
  16. data/Manifest.txt +3 -3
  17. data/README-Windows.rdoc +4 -4
  18. data/README.ja.rdoc +1 -2
  19. data/README.rdoc +51 -15
  20. data/Rakefile +31 -140
  21. data/Rakefile.cross +60 -56
  22. data/certs/ged.pem +24 -0
  23. data/certs/larskanis-2022.pem +26 -0
  24. data/ext/errorcodes.def +76 -0
  25. data/ext/errorcodes.txt +21 -2
  26. data/ext/extconf.rb +101 -26
  27. data/ext/gvl_wrappers.c +4 -0
  28. data/ext/gvl_wrappers.h +23 -0
  29. data/ext/pg.c +190 -98
  30. data/ext/pg.h +42 -17
  31. data/ext/pg_binary_decoder.c +20 -16
  32. data/ext/pg_binary_encoder.c +13 -12
  33. data/ext/pg_coder.c +95 -29
  34. data/ext/pg_connection.c +1043 -769
  35. data/ext/pg_copy_coder.c +50 -18
  36. data/ext/pg_record_coder.c +519 -0
  37. data/ext/pg_result.c +326 -142
  38. data/ext/pg_text_decoder.c +15 -9
  39. data/ext/pg_text_encoder.c +185 -53
  40. data/ext/pg_tuple.c +61 -27
  41. data/ext/pg_type_map.c +42 -9
  42. data/ext/pg_type_map_all_strings.c +19 -5
  43. data/ext/pg_type_map_by_class.c +54 -24
  44. data/ext/pg_type_map_by_column.c +73 -34
  45. data/ext/pg_type_map_by_mri_type.c +48 -19
  46. data/ext/pg_type_map_by_oid.c +55 -25
  47. data/ext/pg_type_map_in_ruby.c +51 -20
  48. data/ext/{util.c → pg_util.c} +7 -7
  49. data/ext/{util.h → pg_util.h} +0 -0
  50. data/lib/pg/basic_type_map_based_on_result.rb +47 -0
  51. data/lib/pg/basic_type_map_for_queries.rb +193 -0
  52. data/lib/pg/basic_type_map_for_results.rb +81 -0
  53. data/lib/pg/basic_type_registry.rb +296 -0
  54. data/lib/pg/binary_decoder.rb +1 -0
  55. data/lib/pg/coder.rb +23 -2
  56. data/lib/pg/connection.rb +589 -59
  57. data/lib/pg/constants.rb +1 -0
  58. data/lib/pg/exceptions.rb +1 -0
  59. data/lib/pg/result.rb +13 -1
  60. data/lib/pg/text_decoder.rb +2 -3
  61. data/lib/pg/text_encoder.rb +8 -18
  62. data/lib/pg/type_map_by_column.rb +2 -1
  63. data/lib/pg/version.rb +4 -0
  64. data/lib/pg.rb +48 -33
  65. data/misc/openssl-pg-segfault.rb +31 -0
  66. data/misc/postgres/History.txt +9 -0
  67. data/misc/postgres/Manifest.txt +5 -0
  68. data/misc/postgres/README.txt +21 -0
  69. data/misc/postgres/Rakefile +21 -0
  70. data/misc/postgres/lib/postgres.rb +16 -0
  71. data/misc/ruby-pg/History.txt +9 -0
  72. data/misc/ruby-pg/Manifest.txt +5 -0
  73. data/misc/ruby-pg/README.txt +21 -0
  74. data/misc/ruby-pg/Rakefile +21 -0
  75. data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
  76. data/pg.gemspec +32 -0
  77. data/rakelib/task_extension.rb +46 -0
  78. data/sample/array_insert.rb +20 -0
  79. data/sample/async_api.rb +106 -0
  80. data/sample/async_copyto.rb +39 -0
  81. data/sample/async_mixed.rb +56 -0
  82. data/sample/check_conn.rb +21 -0
  83. data/sample/copydata.rb +71 -0
  84. data/sample/copyfrom.rb +81 -0
  85. data/sample/copyto.rb +19 -0
  86. data/sample/cursor.rb +21 -0
  87. data/sample/disk_usage_report.rb +177 -0
  88. data/sample/issue-119.rb +94 -0
  89. data/sample/losample.rb +69 -0
  90. data/sample/minimal-testcase.rb +17 -0
  91. data/sample/notify_wait.rb +72 -0
  92. data/sample/pg_statistics.rb +285 -0
  93. data/sample/replication_monitor.rb +222 -0
  94. data/sample/test_binary_values.rb +33 -0
  95. data/sample/wal_shipper.rb +434 -0
  96. data/sample/warehouse_partitions.rb +311 -0
  97. data.tar.gz.sig +0 -0
  98. metadata +94 -237
  99. metadata.gz.sig +0 -0
  100. data/ChangeLog +0 -6595
  101. data/lib/pg/basic_type_mapping.rb +0 -459
  102. data/spec/data/expected_trace.out +0 -26
  103. data/spec/data/random_binary_data +0 -0
  104. data/spec/helpers.rb +0 -381
  105. data/spec/pg/basic_type_mapping_spec.rb +0 -508
  106. data/spec/pg/connection_spec.rb +0 -1849
  107. data/spec/pg/connection_sync_spec.rb +0 -41
  108. data/spec/pg/result_spec.rb +0 -491
  109. data/spec/pg/tuple_spec.rb +0 -280
  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 -949
  117. data/spec/pg_spec.rb +0 -50
data/ext/gvl_wrappers.h CHANGED
@@ -17,6 +17,10 @@
17
17
 
18
18
  #include <ruby/thread.h>
19
19
 
20
+ #ifdef RUBY_EXTCONF_H
21
+ # include RUBY_EXTCONF_H
22
+ #endif
23
+
20
24
  #define DEFINE_PARAM_LIST1(type, name) \
21
25
  name,
22
26
 
@@ -46,6 +50,7 @@
46
50
  return NULL; \
47
51
  }
48
52
 
53
+ #ifdef ENABLE_GVL_UNLOCK
49
54
  #define DEFINE_GVL_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
50
55
  rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
51
56
  struct gvl_wrapper_##name##_params params = { \
@@ -54,6 +59,13 @@
54
59
  rb_thread_call_without_gvl(gvl_##name##_skeleton, &params, RUBY_UBF_IO, 0); \
55
60
  when_non_void( return params.retval; ) \
56
61
  }
62
+ #else
63
+ #define DEFINE_GVL_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
64
+ rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
65
+ when_non_void( return ) \
66
+ name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname ); \
67
+ }
68
+ #endif
57
69
 
58
70
  #define DEFINE_GVL_STUB_DECL(name, when_non_void, rettype, lastparamtype, lastparamname) \
59
71
  rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname);
@@ -66,6 +78,7 @@
66
78
  return NULL; \
67
79
  }
68
80
 
81
+ #ifdef ENABLE_GVL_UNLOCK
69
82
  #define DEFINE_GVLCB_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
70
83
  rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
71
84
  struct gvl_wrapper_##name##_params params = { \
@@ -74,6 +87,13 @@
74
87
  rb_thread_call_with_gvl(gvl_##name##_skeleton, &params); \
75
88
  when_non_void( return params.retval; ) \
76
89
  }
90
+ #else
91
+ #define DEFINE_GVLCB_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
92
+ rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
93
+ when_non_void( return ) \
94
+ name( FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST1) lastparamname ); \
95
+ }
96
+ #endif
77
97
 
78
98
  #define GVL_TYPE_VOID(string)
79
99
  #define GVL_TYPE_NONVOID(string) string
@@ -95,6 +115,8 @@
95
115
 
96
116
  #define FOR_EACH_PARAM_OF_PQresetPoll(param)
97
117
 
118
+ #define FOR_EACH_PARAM_OF_PQping(param)
119
+
98
120
  #define FOR_EACH_PARAM_OF_PQexec(param) \
99
121
  param(PGconn *, conn)
100
122
 
@@ -196,6 +218,7 @@
196
218
  function(PQreset, GVL_TYPE_VOID, void, PGconn *, conn) \
197
219
  function(PQresetStart, GVL_TYPE_NONVOID, int, PGconn *, conn) \
198
220
  function(PQresetPoll, GVL_TYPE_NONVOID, PostgresPollingStatusType, PGconn *, conn) \
221
+ function(PQping, GVL_TYPE_NONVOID, PGPing, const char *, conninfo) \
199
222
  function(PQexec, GVL_TYPE_NONVOID, PGresult *, const char *, command) \
200
223
  function(PQexecParams, GVL_TYPE_NONVOID, PGresult *, int, resultFormat) \
201
224
  function(PQexecPrepared, GVL_TYPE_NONVOID, PGresult *, int, resultFormat) \
data/ext/pg.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * pg.c - Toplevel extension
3
- * $Id: pg.c,v 2d334508484a 2018/08/27 11:33:43 lars $
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
@@ -47,6 +47,7 @@
47
47
  */
48
48
 
49
49
  #include "pg.h"
50
+ #include "pg_config.h"
50
51
 
51
52
  int pg_skip_deprecation_warning;
52
53
  VALUE rb_mPG;
@@ -331,8 +332,7 @@ pg_to_bool_int(VALUE value)
331
332
  * If your application initializes libssl and/or libcrypto libraries and libpq is
332
333
  * built with SSL support, you should call PG.init_openssl() to tell libpq that the
333
334
  * libssl and/or libcrypto libraries have been initialized by your application,
334
- * so that libpq will not also initialize those libraries. See
335
- * http://h71000.www7.hp.com/doc/83final/BA554_90007/ch04.html for details on the SSL API.
335
+ * so that libpq will not also initialize those libraries.
336
336
  *
337
337
  * When do_ssl is +true+, libpq will initialize the OpenSSL library before first
338
338
  * opening a database connection. When do_crypto is +true+, the libcrypto library
@@ -416,14 +416,34 @@ Init_pg_ext()
416
416
  rb_define_const(rb_mPGconstants, "CONNECTION_MADE", INT2FIX(CONNECTION_MADE));
417
417
  /* Waiting for a response from the server. */
418
418
  rb_define_const(rb_mPGconstants, "CONNECTION_AWAITING_RESPONSE", INT2FIX(CONNECTION_AWAITING_RESPONSE));
419
- /* Received authentication; waiting for backend start-up to finish. */
419
+ /* Received authentication; waiting for backend startup. */
420
420
  rb_define_const(rb_mPGconstants, "CONNECTION_AUTH_OK", INT2FIX(CONNECTION_AUTH_OK));
421
+ /* This state is no longer used. */
422
+ rb_define_const(rb_mPGconstants, "CONNECTION_SETENV", INT2FIX(CONNECTION_SETENV));
421
423
  /* Negotiating SSL encryption. */
422
424
  rb_define_const(rb_mPGconstants, "CONNECTION_SSL_STARTUP", INT2FIX(CONNECTION_SSL_STARTUP));
423
- /* Negotiating environment-driven parameter settings. */
424
- rb_define_const(rb_mPGconstants, "CONNECTION_SETENV", INT2FIX(CONNECTION_SETENV));
425
- /* Internal state: connect() needed. */
425
+ /* Internal state - PG.connect() needed. */
426
426
  rb_define_const(rb_mPGconstants, "CONNECTION_NEEDED", INT2FIX(CONNECTION_NEEDED));
427
+ #if PG_MAJORVERSION_NUM >= 10
428
+ /* Checking if session is read-write. Available since PostgreSQL-10. */
429
+ rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_WRITABLE", INT2FIX(CONNECTION_CHECK_WRITABLE));
430
+ #endif
431
+ #if PG_MAJORVERSION_NUM >= 10
432
+ /* Consuming any extra messages. Available since PostgreSQL-10. */
433
+ rb_define_const(rb_mPGconstants, "CONNECTION_CONSUME", INT2FIX(CONNECTION_CONSUME));
434
+ #endif
435
+ #if PG_MAJORVERSION_NUM >= 12
436
+ /* Negotiating GSSAPI. Available since PostgreSQL-12. */
437
+ rb_define_const(rb_mPGconstants, "CONNECTION_GSS_STARTUP", INT2FIX(CONNECTION_GSS_STARTUP));
438
+ #endif
439
+ #if PG_MAJORVERSION_NUM >= 13
440
+ /* Checking target server properties. Available since PostgreSQL-13. */
441
+ rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_TARGET", INT2FIX(CONNECTION_CHECK_TARGET));
442
+ #endif
443
+ #if PG_MAJORVERSION_NUM >= 14
444
+ /* Checking if server is in standby mode. Available since PostgreSQL-14. */
445
+ rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_STANDBY", INT2FIX(CONNECTION_CHECK_STANDBY));
446
+ #endif
427
447
 
428
448
  /****** PG::Connection CLASS CONSTANTS: Nonblocking connection polling status ******/
429
449
 
@@ -438,26 +458,48 @@ Init_pg_ext()
438
458
 
439
459
  /****** PG::Connection CLASS CONSTANTS: Transaction Status ******/
440
460
 
441
- /* Transaction is currently idle (#transaction_status) */
461
+ /* Transaction is currently idle ( Connection#transaction_status ) */
442
462
  rb_define_const(rb_mPGconstants, "PQTRANS_IDLE", INT2FIX(PQTRANS_IDLE));
443
- /* Transaction is currently active; query has been sent to the server, but not yet completed. (#transaction_status) */
463
+ /* Transaction is currently active; query has been sent to the server, but not yet completed. ( Connection#transaction_status ) */
444
464
  rb_define_const(rb_mPGconstants, "PQTRANS_ACTIVE", INT2FIX(PQTRANS_ACTIVE));
445
- /* Transaction is currently idle, in a valid transaction block (#transaction_status) */
465
+ /* Transaction is currently idle, in a valid transaction block ( Connection#transaction_status ) */
446
466
  rb_define_const(rb_mPGconstants, "PQTRANS_INTRANS", INT2FIX(PQTRANS_INTRANS));
447
- /* Transaction is currently idle, in a failed transaction block (#transaction_status) */
467
+ /* Transaction is currently idle, in a failed transaction block ( Connection#transaction_status ) */
448
468
  rb_define_const(rb_mPGconstants, "PQTRANS_INERROR", INT2FIX(PQTRANS_INERROR));
449
- /* Transaction's connection is bad (#transaction_status) */
469
+ /* Transaction's connection is bad ( Connection#transaction_status ) */
450
470
  rb_define_const(rb_mPGconstants, "PQTRANS_UNKNOWN", INT2FIX(PQTRANS_UNKNOWN));
451
471
 
452
472
  /****** PG::Connection CLASS CONSTANTS: Error Verbosity ******/
453
473
 
454
- /* Terse error verbosity level (#set_error_verbosity) */
474
+ /* Error verbosity level ( Connection#set_error_verbosity ).
475
+ * In TERSE mode, returned messages include severity, primary text, and position only; this will normally fit on a single line. */
455
476
  rb_define_const(rb_mPGconstants, "PQERRORS_TERSE", INT2FIX(PQERRORS_TERSE));
456
- /* Default error verbosity level (#set_error_verbosity) */
477
+ /* Error verbosity level ( Connection#set_error_verbosity ).
478
+ * The DEFAULT mode produces messages that include the above plus any detail, hint, or context fields (these might span multiple lines). */
457
479
  rb_define_const(rb_mPGconstants, "PQERRORS_DEFAULT", INT2FIX(PQERRORS_DEFAULT));
458
- /* Verbose error verbosity level (#set_error_verbosity) */
480
+ /* Error verbosity level ( Connection#set_error_verbosity ).
481
+ * The VERBOSE mode includes all available fields. */
459
482
  rb_define_const(rb_mPGconstants, "PQERRORS_VERBOSE", INT2FIX(PQERRORS_VERBOSE));
460
483
 
484
+ /* PQERRORS_SQLSTATE was introduced in PG-12 together with PQresultMemorySize() */
485
+ #ifdef HAVE_PQRESULTMEMORYSIZE
486
+ /* Error verbosity level ( Connection#set_error_verbosity ).
487
+ * 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).
488
+ *
489
+ * Available since PostgreSQL-12.
490
+ */
491
+ rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
492
+ #endif
493
+
494
+ #ifdef HAVE_PQRESULTVERBOSEERRORMESSAGE
495
+ /* See Connection#set_error_context_visibility */
496
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_NEVER", INT2FIX(PQSHOW_CONTEXT_NEVER));
497
+ /* See Connection#set_error_context_visibility */
498
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_ERRORS", INT2FIX(PQSHOW_CONTEXT_ERRORS));
499
+ /* See Connection#set_error_context_visibility */
500
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_ALWAYS", INT2FIX(PQSHOW_CONTEXT_ALWAYS));
501
+ #endif
502
+
461
503
  /****** PG::Connection CLASS CONSTANTS: Check Server Status ******/
462
504
 
463
505
  /* Server is accepting connections. */
@@ -471,144 +513,193 @@ Init_pg_ext()
471
513
 
472
514
  /****** PG::Connection CLASS CONSTANTS: Large Objects ******/
473
515
 
474
- /* Flag for #lo_creat, #lo_open -- open for writing */
516
+ /* Flag for Connection#lo_creat, Connection#lo_open -- open for writing */
475
517
  rb_define_const(rb_mPGconstants, "INV_WRITE", INT2FIX(INV_WRITE));
476
- /* Flag for #lo_creat, #lo_open -- open for reading */
518
+ /* Flag for Connection#lo_creat, Connection#lo_open -- open for reading */
477
519
  rb_define_const(rb_mPGconstants, "INV_READ", INT2FIX(INV_READ));
478
- /* Flag for #lo_lseek -- seek from object start */
520
+ /* Flag for Connection#lo_lseek -- seek from object start */
479
521
  rb_define_const(rb_mPGconstants, "SEEK_SET", INT2FIX(SEEK_SET));
480
- /* Flag for #lo_lseek -- seek from current position */
522
+ /* Flag for Connection#lo_lseek -- seek from current position */
481
523
  rb_define_const(rb_mPGconstants, "SEEK_CUR", INT2FIX(SEEK_CUR));
482
- /* Flag for #lo_lseek -- seek from object end */
524
+ /* Flag for Connection#lo_lseek -- seek from object end */
483
525
  rb_define_const(rb_mPGconstants, "SEEK_END", INT2FIX(SEEK_END));
484
526
 
485
527
  /****** PG::Result CONSTANTS: result status ******/
486
528
 
487
- /* #result_status constant: The string sent to the server was empty. */
529
+ /* Result#result_status constant - The string sent to the server was empty. */
488
530
  rb_define_const(rb_mPGconstants, "PGRES_EMPTY_QUERY", INT2FIX(PGRES_EMPTY_QUERY));
489
- /* #result_status constant: Successful completion of a command returning no data. */
531
+ /* Result#result_status constant - Successful completion of a command returning no data. */
490
532
  rb_define_const(rb_mPGconstants, "PGRES_COMMAND_OK", INT2FIX(PGRES_COMMAND_OK));
491
- /* #result_status constant: Successful completion of a command returning data
492
- (such as a SELECT or SHOW). */
533
+ /* Result#result_status constant - Successful completion of a command returning data (such as a SELECT or SHOW). */
493
534
  rb_define_const(rb_mPGconstants, "PGRES_TUPLES_OK", INT2FIX(PGRES_TUPLES_OK));
494
- /* #result_status constant: Copy Out (from server) data transfer started. */
535
+ /* Result#result_status constant - Copy Out (from server) data transfer started. */
495
536
  rb_define_const(rb_mPGconstants, "PGRES_COPY_OUT", INT2FIX(PGRES_COPY_OUT));
496
- /* #result_status constant: Copy In (to server) data transfer started. */
537
+ /* Result#result_status constant - Copy In (to server) data transfer started. */
497
538
  rb_define_const(rb_mPGconstants, "PGRES_COPY_IN", INT2FIX(PGRES_COPY_IN));
498
- /* #result_status constant: The server’s response was not understood. */
539
+ /* Result#result_status constant - The server’s response was not understood. */
499
540
  rb_define_const(rb_mPGconstants, "PGRES_BAD_RESPONSE", INT2FIX(PGRES_BAD_RESPONSE));
500
- /* #result_status constant: A nonfatal error (a notice or warning) occurred. */
541
+ /* Result#result_status constant - A nonfatal error (a notice or warning) occurred. */
501
542
  rb_define_const(rb_mPGconstants, "PGRES_NONFATAL_ERROR",INT2FIX(PGRES_NONFATAL_ERROR));
502
- /* #result_status constant: A fatal error occurred. */
543
+ /* Result#result_status constant - A fatal error occurred. */
503
544
  rb_define_const(rb_mPGconstants, "PGRES_FATAL_ERROR", INT2FIX(PGRES_FATAL_ERROR));
504
- /* #result_status constant: Copy In/Out data transfer in progress. */
545
+ /* Result#result_status constant - Copy In/Out data transfer in progress. */
505
546
  rb_define_const(rb_mPGconstants, "PGRES_COPY_BOTH", INT2FIX(PGRES_COPY_BOTH));
506
- /* #result_status constant: Single tuple from larger resultset. */
547
+ /* Result#result_status constant - Single tuple from larger resultset. */
507
548
  rb_define_const(rb_mPGconstants, "PGRES_SINGLE_TUPLE", INT2FIX(PGRES_SINGLE_TUPLE));
508
549
 
550
+ #ifdef HAVE_PQENTERPIPELINEMODE
551
+ /* Result#result_status constant - The PG::Result represents a synchronization point in pipeline mode, requested by Connection#pipeline_sync.
552
+ *
553
+ * This status occurs only when pipeline mode has been selected. */
554
+ rb_define_const(rb_mPGconstants, "PGRES_PIPELINE_SYNC", INT2FIX(PGRES_PIPELINE_SYNC));
555
+
556
+ /* Result#result_status constant - The PG::Result represents a pipeline that has received an error from the server.
557
+ *
558
+ * 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.
559
+ */
560
+ rb_define_const(rb_mPGconstants, "PGRES_PIPELINE_ABORTED", INT2FIX(PGRES_PIPELINE_ABORTED));
561
+ #endif
562
+
509
563
  /****** Result CONSTANTS: result error field codes ******/
510
564
 
511
- /* #result_error_field argument constant: The severity; the field contents
512
- * are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE,
513
- * DEBUG, INFO, or LOG (in a notice message), or a localized translation
514
- * of one of these. Always present.
565
+ /* Result#result_error_field argument constant
566
+ *
567
+ * 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
568
+ * of one of these.
569
+ * Always present.
515
570
  */
516
571
  rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY", INT2FIX(PG_DIAG_SEVERITY));
517
572
 
518
- /* #result_error_field argument constant: The SQLSTATE code for the
519
- * error. The SQLSTATE code identies the type of error that has occurred;
520
- * it can be used by front-end applications to perform specic operations
521
- * (such as er- ror handling) in response to a particular database
522
- * error. For a list of the possible SQLSTATE codes, see Appendix A.
523
- * This eld is not localizable, and is always present.
573
+ #ifdef PG_DIAG_SEVERITY_NONLOCALIZED
574
+ /* Result#result_error_field argument constant
575
+ *
576
+ * 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).
577
+ * This is identical to the PG_DIAG_SEVERITY field except that the contents are never localized.
578
+ *
579
+ * Available since PostgreSQL-9.6
580
+ */
581
+ rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY_NONLOCALIZED", INT2FIX(PG_DIAG_SEVERITY_NONLOCALIZED));
582
+ #endif
583
+ /* Result#result_error_field argument constant
584
+ *
585
+ * The SQLSTATE code for the error.
586
+ * 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.
587
+ * For a list of the possible SQLSTATE codes, see Appendix A.
588
+ * This field is not localizable, and is always present.
524
589
  */
525
590
  rb_define_const(rb_mPGconstants, "PG_DIAG_SQLSTATE", INT2FIX(PG_DIAG_SQLSTATE));
526
-
527
- /* #result_error_field argument constant: The primary human-readable
528
- * error message (typically one line). Always present. */
591
+ /* Result#result_error_field argument constant
592
+ *
593
+ * The primary human-readable error message (typically one line).
594
+ * Always present. */
529
595
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_PRIMARY", INT2FIX(PG_DIAG_MESSAGE_PRIMARY));
530
-
531
- /* #result_error_field argument constant: Detail: an optional secondary
532
- * error message carrying more detail about the problem. Might run to
533
- * multiple lines.
596
+ /* Result#result_error_field argument constant
597
+ *
598
+ * Detail: an optional secondary error message carrying more detail about the problem.
599
+ * Might run to multiple lines.
534
600
  */
535
601
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_DETAIL", INT2FIX(PG_DIAG_MESSAGE_DETAIL));
536
-
537
- /* #result_error_field argument constant: Hint: an optional suggestion
538
- * what to do about the problem. This is intended to differ from detail
539
- * in that it offers advice (potentially inappropriate) rather than
540
- * hard facts. Might run to multiple lines.
602
+ /* Result#result_error_field argument constant
603
+ *
604
+ * Hint: an optional suggestion what to do about the problem.
605
+ * This is intended to differ from detail in that it offers advice (potentially inappropriate) rather than hard facts.
606
+ * Might run to multiple lines.
541
607
  */
542
-
543
608
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_HINT", INT2FIX(PG_DIAG_MESSAGE_HINT));
544
- /* #result_error_field argument constant: A string containing a decimal
545
- * integer indicating an error cursor position as an index into the
546
- * original statement string. The rst character has index 1, and
547
- * positions are measured in characters not bytes.
609
+ /* Result#result_error_field argument constant
610
+ *
611
+ * A string containing a decimal integer indicating an error cursor position as an index into the original statement string.
612
+ *
613
+ * The first character has index 1, and positions are measured in characters not bytes.
548
614
  */
549
-
550
615
  rb_define_const(rb_mPGconstants, "PG_DIAG_STATEMENT_POSITION", INT2FIX(PG_DIAG_STATEMENT_POSITION));
551
- /* #result_error_field argument constant: This is dened the same as
552
- * the PG_DIAG_STATEMENT_POSITION eld, but it is used when the cursor
553
- * position refers to an internally generated command rather than the
554
- * one submitted by the client. The PG_DIAG_INTERNAL_QUERY eld will
555
- * always appear when this eld appears.
616
+ /* Result#result_error_field argument constant
617
+ *
618
+ * 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.
619
+ * The PG_DIAG_INTERNAL_QUERY field will always appear when this field appears.
556
620
  */
557
-
558
621
  rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_POSITION", INT2FIX(PG_DIAG_INTERNAL_POSITION));
559
- /* #result_error_field argument constant: The text of a failed
560
- * internally-generated command. This could be, for example, a SQL
561
- * query issued by a PL/pgSQL function.
622
+ /* Result#result_error_field argument constant
623
+ *
624
+ * The text of a failed internally-generated command.
625
+ * This could be, for example, a SQL query issued by a PL/pgSQL function.
562
626
  */
563
-
564
627
  rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_QUERY", INT2FIX(PG_DIAG_INTERNAL_QUERY));
565
- /* #result_error_field argument constant: An indication of the context
566
- * in which the error occurred. Presently this includes a call stack
567
- * traceback of active procedural language functions and internally-generated
568
- * queries. The trace is one entry per line, most recent rst.
628
+ /* Result#result_error_field argument constant
629
+ *
630
+ * An indication of the context in which the error occurred.
631
+ * Presently this includes a call stack traceback of active procedural language functions and internally-generated queries.
632
+ * The trace is one entry per line, most recent first.
569
633
  */
570
-
571
634
  rb_define_const(rb_mPGconstants, "PG_DIAG_CONTEXT", INT2FIX(PG_DIAG_CONTEXT));
572
- /* #result_error_field argument constant: The le name of the source-code
573
- * location where the error was reported. */
635
+ /* Result#result_error_field argument constant
636
+ *
637
+ * The file name of the source-code location where the error was reported. */
574
638
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FILE", INT2FIX(PG_DIAG_SOURCE_FILE));
575
639
 
576
- /* #result_error_field argument constant: The line number of the
577
- * source-code location where the error was reported. */
640
+ /* Result#result_error_field argument constant
641
+ *
642
+ * The line number of the source-code location where the error was reported. */
578
643
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_LINE", INT2FIX(PG_DIAG_SOURCE_LINE));
579
644
 
580
- /* #result_error_field argument constant: The name of the source-code
581
- * function reporting the error. */
645
+ /* Result#result_error_field argument constant
646
+ *
647
+ * The name of the source-code function reporting the error. */
582
648
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FUNCTION", INT2FIX(PG_DIAG_SOURCE_FUNCTION));
583
649
 
584
- #ifdef HAVE_CONST_PG_DIAG_TABLE_NAME
585
- /* #result_error_field argument constant: If the error was associated with a
586
- * specific database object, the name of the schema containing that object, if any. */
650
+ #ifdef PG_DIAG_TABLE_NAME
651
+ /* Result#result_error_field argument constant
652
+ *
653
+ * If the error was associated with a specific database object, the name of the schema containing that object, if any. */
587
654
  rb_define_const(rb_mPGconstants, "PG_DIAG_SCHEMA_NAME", INT2FIX(PG_DIAG_SCHEMA_NAME));
588
655
 
589
- /* #result_error_field argument constant: If the error was associated with a
590
- *specific table, the name of the table. (When this field is present, the schema name
591
- * field provides the name of the table's schema.) */
656
+ /* Result#result_error_field argument constant
657
+ *
658
+ * If the error was associated with a specific table, the name of the table.
659
+ * (When this field is present, the schema name field provides the name of the table's schema.) */
592
660
  rb_define_const(rb_mPGconstants, "PG_DIAG_TABLE_NAME", INT2FIX(PG_DIAG_TABLE_NAME));
593
661
 
594
- /* #result_error_field argument constant: If the error was associated with a
595
- * specific table column, the name of the column. (When this field is present, the
596
- * schema and table name fields identify the table.) */
662
+ /* Result#result_error_field argument constant
663
+ *
664
+ * If the error was associated with a specific table column, the name of the column.
665
+ * (When this field is present, the schema and table name fields identify the table.) */
597
666
  rb_define_const(rb_mPGconstants, "PG_DIAG_COLUMN_NAME", INT2FIX(PG_DIAG_COLUMN_NAME));
598
667
 
599
- /* #result_error_field argument constant: If the error was associated with a
600
- * specific datatype, the name of the datatype. (When this field is present, the
601
- * schema name field provides the name of the datatype's schema.) */
668
+ /* Result#result_error_field argument constant
669
+ *
670
+ * If the error was associated with a specific datatype, the name of the datatype.
671
+ * (When this field is present, the schema name field provides the name of the datatype's schema.) */
602
672
  rb_define_const(rb_mPGconstants, "PG_DIAG_DATATYPE_NAME", INT2FIX(PG_DIAG_DATATYPE_NAME));
603
673
 
604
- /* #result_error_field argument constant: If the error was associated with a
605
- * specific constraint, the name of the constraint. The table or domain that the
606
- * constraint belongs to is reported using the fields listed above. (For this
607
- * purpose, indexes are treated as constraints, even if they weren't created with
608
- * constraint syntax.) */
674
+ /* Result#result_error_field argument constant
675
+ *
676
+ * If the error was associated with a specific constraint, the name of the constraint.
677
+ * The table or domain that the constraint belongs to is reported using the fields listed above.
678
+ * (For this purpose, indexes are treated as constraints, even if they weren't created with constraint syntax.) */
609
679
  rb_define_const(rb_mPGconstants, "PG_DIAG_CONSTRAINT_NAME", INT2FIX(PG_DIAG_CONSTRAINT_NAME));
610
680
  #endif
611
681
 
682
+ #ifdef HAVE_PQENTERPIPELINEMODE
683
+ /* Connection#pipeline_status constant
684
+ *
685
+ * The libpq connection is in pipeline mode.
686
+ */
687
+ rb_define_const(rb_mPGconstants, "PQ_PIPELINE_ON", INT2FIX(PQ_PIPELINE_ON));
688
+
689
+ /* Connection#pipeline_status constant
690
+ *
691
+ * The libpq connection is not in pipeline mode.
692
+ */
693
+ rb_define_const(rb_mPGconstants, "PQ_PIPELINE_OFF", INT2FIX(PQ_PIPELINE_OFF));
694
+
695
+ /* Connection#pipeline_status constant
696
+ *
697
+ * The libpq connection is in pipeline mode and an error occurred while processing the current pipeline.
698
+ * The aborted flag is cleared when PQgetResult returns a result of type PGRES_PIPELINE_SYNC.
699
+ */
700
+ rb_define_const(rb_mPGconstants, "PQ_PIPELINE_ABORTED", INT2FIX(PQ_PIPELINE_ABORTED));
701
+ #endif
702
+
612
703
  /* Invalid OID constant */
613
704
  rb_define_const(rb_mPGconstants, "INVALID_OID", INT2FIX(InvalidOid));
614
705
  rb_define_const(rb_mPGconstants, "InvalidOid", INT2FIX(InvalidOid));
@@ -635,6 +726,7 @@ Init_pg_ext()
635
726
  init_pg_binary_encoder();
636
727
  init_pg_binary_decoder();
637
728
  init_pg_copycoder();
729
+ init_pg_recordcoder();
638
730
  init_pg_tuple();
639
731
  }
640
732
 
data/ext/pg.h CHANGED
@@ -11,6 +11,7 @@
11
11
  #include <sys/types.h>
12
12
  #if !defined(_WIN32)
13
13
  # include <sys/time.h>
14
+ # include <sys/socket.h>
14
15
  #endif
15
16
  #if defined(HAVE_UNISTD_H) && !defined(_WIN32)
16
17
  # include <unistd.h>
@@ -78,6 +79,17 @@ typedef long suseconds_t;
78
79
  #define RARRAY_AREF(a, i) (RARRAY_PTR(a)[i])
79
80
  #endif
80
81
 
82
+ #ifdef HAVE_RB_GC_MARK_MOVABLE
83
+ #define pg_compact_callback(x) (x)
84
+ #define pg_gc_location(x) x = rb_gc_location(x)
85
+ #else
86
+ #define rb_gc_mark_movable(x) rb_gc_mark(x)
87
+ #define pg_compact_callback(x) {(x)}
88
+ #define pg_gc_location(x) UNUSED(x)
89
+ #endif
90
+
91
+ #define PG_ENC_IDX_BITS 28
92
+
81
93
  /* The data behind each PG::Connection object */
82
94
  typedef struct {
83
95
  PGconn *pgconn;
@@ -94,15 +106,21 @@ typedef struct {
94
106
  VALUE type_map_for_results;
95
107
  /* IO object internally used for the trace stream */
96
108
  VALUE trace_stream;
97
- /* Cached Encoding object */
98
- VALUE external_encoding;
99
109
  /* Kind of PG::Coder object for casting ruby values to COPY rows */
100
110
  VALUE encoder_for_put_copy_data;
101
111
  /* Kind of PG::Coder object for casting COPY rows to ruby values */
102
112
  VALUE decoder_for_get_copy_data;
113
+ /* Ruby encoding index of the client/internal encoding */
114
+ int enc_idx : PG_ENC_IDX_BITS;
115
+ /* flags controlling Symbol/String field names */
116
+ unsigned int flags : 2;
117
+ /* enable automatic flushing of send data at the end of send_query calls */
118
+ unsigned int flush_data : 1;
103
119
 
104
- /* enable/disable guessing size of PGresult's allocated memory */
105
- int guess_result_memsize;
120
+ #if defined(_WIN32)
121
+ /* File descriptor to be used for rb_w32_unwrap_io_handle() */
122
+ int ruby_sd;
123
+ #endif
106
124
  } t_pg_connection;
107
125
 
108
126
  typedef struct pg_coder t_pg_coder;
@@ -123,10 +141,16 @@ typedef struct {
123
141
  */
124
142
  t_typemap *p_typemap;
125
143
 
144
+ /* Ruby encoding index of the client/internal encoding */
145
+ int enc_idx : PG_ENC_IDX_BITS;
146
+
126
147
  /* 0 = PGresult is cleared by PG::Result#clear or by the GC
127
148
  * 1 = PGresult is cleared internally by libpq
128
149
  */
129
- int autoclear;
150
+ unsigned int autoclear : 1;
151
+
152
+ /* flags controlling Symbol/String field names */
153
+ unsigned int flags : 2;
130
154
 
131
155
  /* Number of fields in fnames[] .
132
156
  * Set to -1 if fnames[] is not yet initialized.
@@ -142,7 +166,7 @@ typedef struct {
142
166
  /* Hash with fnames[] to field number mapping. */
143
167
  VALUE field_map;
144
168
 
145
- /* List of field names as frozen String objects.
169
+ /* List of field names as frozen String or Symbol objects.
146
170
  * Only valid if nfields != -1
147
171
  */
148
172
  VALUE fnames[0];
@@ -158,6 +182,10 @@ typedef VALUE (* t_pg_typecast_result)(t_typemap *, VALUE, int, int);
158
182
  typedef t_pg_coder *(* t_pg_typecast_query_param)(t_typemap *, VALUE, int);
159
183
  typedef VALUE (* t_pg_typecast_copy_get)( t_typemap *, VALUE, int, int, int );
160
184
 
185
+ #define PG_RESULT_FIELD_NAMES_MASK 0x03
186
+ #define PG_RESULT_FIELD_NAMES_SYMBOL 0x01
187
+ #define PG_RESULT_FIELD_NAMES_STATIC_SYMBOL 0x02
188
+
161
189
  #define PG_CODER_TIMESTAMP_DB_UTC 0x0
162
190
  #define PG_CODER_TIMESTAMP_DB_LOCAL 0x1
163
191
  #define PG_CODER_TIMESTAMP_APP_UTC 0x0
@@ -204,6 +232,8 @@ typedef struct {
204
232
  } convs[0];
205
233
  } t_tmbc;
206
234
 
235
+ extern const rb_data_type_t pg_typemap_type;
236
+ extern const rb_data_type_t pg_coder_type;
207
237
 
208
238
  #include "gvl_wrappers.h"
209
239
 
@@ -270,6 +300,7 @@ void init_pg_type_map_by_oid _(( void ));
270
300
  void init_pg_type_map_in_ruby _(( void ));
271
301
  void init_pg_coder _(( void ));
272
302
  void init_pg_copycoder _(( void ));
303
+ void init_pg_recordcoder _(( void ));
273
304
  void init_pg_text_encoder _(( void ));
274
305
  void init_pg_text_decoder _(( void ));
275
306
  void init_pg_binary_encoder _(( void ));
@@ -287,6 +318,7 @@ VALUE pg_obj_to_i _(( VALUE ));
287
318
  VALUE pg_tmbc_allocate _(( void ));
288
319
  void pg_coder_init_encoder _(( VALUE ));
289
320
  void pg_coder_init_decoder _(( VALUE ));
321
+ void pg_coder_compact _(( void * ));
290
322
  char *pg_rb_str_ensure_capa _(( VALUE, long, char *, char ** ));
291
323
 
292
324
  #define PG_RB_STR_ENSURE_CAPA( str, expand_len, curr_ptr, end_ptr ) \
@@ -300,17 +332,15 @@ char *pg_rb_str_ensure_capa _(( VALUE, long, char *,
300
332
  (curr_ptr) = (end_ptr) = RSTRING_PTR(str) \
301
333
  )
302
334
 
303
- #define PG_RB_TAINTED_STR_NEW( str, curr_ptr, end_ptr ) ( \
304
- (str) = rb_tainted_str_new( NULL, 0 ), \
305
- (curr_ptr) = (end_ptr) = RSTRING_PTR(str) \
306
- )
307
-
308
335
  VALUE pg_typemap_fit_to_result _(( VALUE, VALUE ));
309
336
  VALUE pg_typemap_fit_to_query _(( VALUE, VALUE ));
310
337
  int pg_typemap_fit_to_copy_get _(( VALUE ));
311
338
  VALUE pg_typemap_result_value _(( t_typemap *, VALUE, int, int ));
312
339
  t_pg_coder *pg_typemap_typecast_query_param _(( t_typemap *, VALUE, int ));
313
340
  VALUE pg_typemap_typecast_copy_get _(( t_typemap *, VALUE, int, int, int ));
341
+ void pg_typemap_mark _(( void * ));
342
+ size_t pg_typemap_memsize _(( const void * ));
343
+ void pg_typemap_compact _(( void * ));
314
344
 
315
345
  PGconn *pg_get_pgconn _(( VALUE ));
316
346
  t_pg_connection *pg_get_connection _(( VALUE ));
@@ -328,12 +358,7 @@ VALUE pg_tuple_new _(( VALUE, int ));
328
358
  static inline t_pg_result *
329
359
  pgresult_get_this( VALUE self )
330
360
  {
331
- t_pg_result *this = RTYPEDDATA_DATA(self);
332
-
333
- if( this == NULL )
334
- rb_raise(rb_ePGerror, "result has been cleared");
335
-
336
- return this;
361
+ return RTYPEDDATA_DATA(self);
337
362
  }
338
363
 
339
364