pg 0.18.4 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/BSDL +2 -2
  5. data/ChangeLog +0 -5911
  6. data/History.rdoc +240 -0
  7. data/Manifest.txt +8 -20
  8. data/README-Windows.rdoc +4 -4
  9. data/README.ja.rdoc +1 -2
  10. data/README.rdoc +64 -15
  11. data/Rakefile +20 -21
  12. data/Rakefile.cross +67 -69
  13. data/ext/errorcodes.def +101 -0
  14. data/ext/errorcodes.rb +1 -1
  15. data/ext/errorcodes.txt +33 -2
  16. data/ext/extconf.rb +26 -36
  17. data/ext/gvl_wrappers.c +4 -0
  18. data/ext/gvl_wrappers.h +27 -39
  19. data/ext/pg.c +156 -145
  20. data/ext/pg.h +74 -98
  21. data/ext/pg_binary_decoder.c +82 -15
  22. data/ext/pg_binary_encoder.c +20 -19
  23. data/ext/pg_coder.c +103 -21
  24. data/ext/pg_connection.c +917 -523
  25. data/ext/pg_copy_coder.c +50 -12
  26. data/ext/pg_record_coder.c +491 -0
  27. data/ext/pg_result.c +590 -208
  28. data/ext/pg_text_decoder.c +606 -40
  29. data/ext/pg_text_encoder.c +245 -94
  30. data/ext/pg_tuple.c +549 -0
  31. data/ext/pg_type_map.c +14 -7
  32. data/ext/pg_type_map_all_strings.c +4 -4
  33. data/ext/pg_type_map_by_class.c +9 -4
  34. data/ext/pg_type_map_by_column.c +7 -6
  35. data/ext/pg_type_map_by_mri_type.c +1 -1
  36. data/ext/pg_type_map_by_oid.c +3 -2
  37. data/ext/pg_type_map_in_ruby.c +1 -1
  38. data/ext/{util.c → pg_util.c} +10 -10
  39. data/ext/{util.h → pg_util.h} +2 -2
  40. data/lib/pg.rb +23 -13
  41. data/lib/pg/basic_type_mapping.rb +155 -32
  42. data/lib/pg/binary_decoder.rb +23 -0
  43. data/lib/pg/coder.rb +23 -2
  44. data/lib/pg/connection.rb +73 -13
  45. data/lib/pg/constants.rb +2 -1
  46. data/lib/pg/exceptions.rb +2 -1
  47. data/lib/pg/result.rb +24 -7
  48. data/lib/pg/text_decoder.rb +24 -22
  49. data/lib/pg/text_encoder.rb +40 -8
  50. data/lib/pg/tuple.rb +30 -0
  51. data/lib/pg/type_map_by_column.rb +3 -2
  52. data/spec/helpers.rb +61 -36
  53. data/spec/pg/basic_type_mapping_spec.rb +415 -36
  54. data/spec/pg/connection_spec.rb +732 -327
  55. data/spec/pg/connection_sync_spec.rb +41 -0
  56. data/spec/pg/result_spec.rb +253 -21
  57. data/spec/pg/tuple_spec.rb +333 -0
  58. data/spec/pg/type_map_by_class_spec.rb +4 -4
  59. data/spec/pg/type_map_by_column_spec.rb +6 -2
  60. data/spec/pg/type_map_by_mri_type_spec.rb +2 -2
  61. data/spec/pg/type_map_by_oid_spec.rb +3 -3
  62. data/spec/pg/type_map_in_ruby_spec.rb +1 -1
  63. data/spec/pg/type_map_spec.rb +1 -1
  64. data/spec/pg/type_spec.rb +446 -20
  65. data/spec/pg_spec.rb +2 -2
  66. metadata +63 -72
  67. metadata.gz.sig +0 -0
  68. data/sample/array_insert.rb +0 -20
  69. data/sample/async_api.rb +0 -106
  70. data/sample/async_copyto.rb +0 -39
  71. data/sample/async_mixed.rb +0 -56
  72. data/sample/check_conn.rb +0 -21
  73. data/sample/copyfrom.rb +0 -81
  74. data/sample/copyto.rb +0 -19
  75. data/sample/cursor.rb +0 -21
  76. data/sample/disk_usage_report.rb +0 -186
  77. data/sample/issue-119.rb +0 -94
  78. data/sample/losample.rb +0 -69
  79. data/sample/minimal-testcase.rb +0 -17
  80. data/sample/notify_wait.rb +0 -72
  81. data/sample/pg_statistics.rb +0 -294
  82. data/sample/replication_monitor.rb +0 -231
  83. data/sample/test_binary_values.rb +0 -33
  84. data/sample/wal_shipper.rb +0 -434
  85. data/sample/warehouse_partitions.rb +0 -320
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
 
3
3
  def camelize(lower_case_and_underscored_word)
4
4
  lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
@@ -2,7 +2,7 @@
2
2
  # errcodes.txt
3
3
  # PostgreSQL error codes
4
4
  #
5
- # Copyright (c) 2003-2013, PostgreSQL Global Development Group
5
+ # Copyright (c) 2003-2019, PostgreSQL Global Development Group
6
6
  #
7
7
  # This list serves as the basis for generating source files containing error
8
8
  # codes. It is kept in a common format to make sure all these source files have
@@ -15,7 +15,10 @@
15
15
  # src/pl/plpgsql/src/plerrcodes.h
16
16
  # a list of PL/pgSQL condition names and their SQLSTATE codes
17
17
  #
18
- # doc/src/sgml/errcodes-list.sgml
18
+ # src/pl/tcl/pltclerrcodes.h
19
+ # the same, for PL/Tcl
20
+ #
21
+ # doc/src/sgml/errcodes-table.sgml
19
22
  # a SGML table of error codes for inclusion in the documentation
20
23
  #
21
24
  # The format of this file is one error code per line, with the following
@@ -174,15 +177,19 @@ Section: Class 22 - Data Exception
174
177
  22P06 E ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER nonstandard_use_of_escape_character
175
178
  22010 E ERRCODE_INVALID_INDICATOR_PARAMETER_VALUE invalid_indicator_parameter_value
176
179
  22023 E ERRCODE_INVALID_PARAMETER_VALUE invalid_parameter_value
180
+ 22013 E ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE invalid_preceding_or_following_size
177
181
  2201B E ERRCODE_INVALID_REGULAR_EXPRESSION invalid_regular_expression
178
182
  2201W E ERRCODE_INVALID_ROW_COUNT_IN_LIMIT_CLAUSE invalid_row_count_in_limit_clause
179
183
  2201X E ERRCODE_INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE invalid_row_count_in_result_offset_clause
184
+ 2202H E ERRCODE_INVALID_TABLESAMPLE_ARGUMENT invalid_tablesample_argument
185
+ 2202G E ERRCODE_INVALID_TABLESAMPLE_REPEAT invalid_tablesample_repeat
180
186
  22009 E ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE invalid_time_zone_displacement_value
181
187
  2200C E ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER invalid_use_of_escape_character
182
188
  2200G E ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH most_specific_type_mismatch
183
189
  22004 E ERRCODE_NULL_VALUE_NOT_ALLOWED null_value_not_allowed
184
190
  22002 E ERRCODE_NULL_VALUE_NO_INDICATOR_PARAMETER null_value_no_indicator_parameter
185
191
  22003 E ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE numeric_value_out_of_range
192
+ 2200H E ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED sequence_generator_limit_exceeded
186
193
  22026 E ERRCODE_STRING_DATA_LENGTH_MISMATCH string_data_length_mismatch
187
194
  22001 E ERRCODE_STRING_DATA_RIGHT_TRUNCATION string_data_right_truncation
188
195
  22011 E ERRCODE_SUBSTRING_ERROR substring_error
@@ -199,6 +206,21 @@ Section: Class 22 - Data Exception
199
206
  2200N E ERRCODE_INVALID_XML_CONTENT invalid_xml_content
200
207
  2200S E ERRCODE_INVALID_XML_COMMENT invalid_xml_comment
201
208
  2200T E ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION invalid_xml_processing_instruction
209
+ 22030 E ERRCODE_DUPLICATE_JSON_OBJECT_KEY_VALUE duplicate_json_object_key_value
210
+ 22032 E ERRCODE_INVALID_JSON_TEXT invalid_json_text
211
+ 22033 E ERRCODE_INVALID_SQL_JSON_SUBSCRIPT invalid_sql_json_subscript
212
+ 22034 E ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM more_than_one_sql_json_item
213
+ 22035 E ERRCODE_NO_SQL_JSON_ITEM no_sql_json_item
214
+ 22036 E ERRCODE_NON_NUMERIC_SQL_JSON_ITEM non_numeric_sql_json_item
215
+ 22037 E ERRCODE_NON_UNIQUE_KEYS_IN_A_JSON_OBJECT non_unique_keys_in_a_json_object
216
+ 22038 E ERRCODE_SINGLETON_SQL_JSON_ITEM_REQUIRED singleton_sql_json_item_required
217
+ 22039 E ERRCODE_SQL_JSON_ARRAY_NOT_FOUND sql_json_array_not_found
218
+ 2203A E ERRCODE_SQL_JSON_MEMBER_NOT_FOUND sql_json_member_not_found
219
+ 2203B E ERRCODE_SQL_JSON_NUMBER_NOT_FOUND sql_json_number_not_found
220
+ 2203C E ERRCODE_SQL_JSON_OBJECT_NOT_FOUND sql_json_object_not_found
221
+ 2203D E ERRCODE_TOO_MANY_JSON_ARRAY_ELEMENTS too_many_json_array_elements
222
+ 2203E E ERRCODE_TOO_MANY_JSON_OBJECT_MEMBERS too_many_json_object_members
223
+ 2203F E ERRCODE_SQL_JSON_SCALAR_REQUIRED sql_json_scalar_required
202
224
 
203
225
  Section: Class 23 - Integrity Constraint Violation
204
226
 
@@ -227,6 +249,7 @@ Section: Class 25 - Invalid Transaction State
227
249
  25007 E ERRCODE_SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED schema_and_data_statement_mixing_not_supported
228
250
  25P01 E ERRCODE_NO_ACTIVE_SQL_TRANSACTION no_active_sql_transaction
229
251
  25P02 E ERRCODE_IN_FAILED_SQL_TRANSACTION in_failed_sql_transaction
252
+ 25P03 E ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT idle_in_transaction_session_timeout
230
253
 
231
254
  Section: Class 26 - Invalid SQL Statement Name
232
255
 
@@ -278,6 +301,7 @@ Section: Class 39 - External Routine Invocation Exception
278
301
  39004 E ERRCODE_E_R_I_E_NULL_VALUE_NOT_ALLOWED null_value_not_allowed
279
302
  39P01 E ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED trigger_protocol_violated
280
303
  39P02 E ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED srf_protocol_violated
304
+ 39P03 E ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED event_trigger_protocol_violated
281
305
 
282
306
  Section: Class 3B - Savepoint Exception
283
307
 
@@ -319,6 +343,7 @@ Section: Class 42 - Syntax Error or Access Rule Violation
319
343
  42P21 E ERRCODE_COLLATION_MISMATCH collation_mismatch
320
344
  42P22 E ERRCODE_INDETERMINATE_COLLATION indeterminate_collation
321
345
  42809 E ERRCODE_WRONG_OBJECT_TYPE wrong_object_type
346
+ 428C9 E ERRCODE_GENERATED_ALWAYS generated_always
322
347
 
323
348
  # Note: for ERRCODE purposes, we divide namable objects into these categories:
324
349
  # databases, schemas, prepared statements, cursors, tables, columns,
@@ -391,6 +416,7 @@ Section: Class 55 - Object Not In Prerequisite State
391
416
  55006 E ERRCODE_OBJECT_IN_USE object_in_use
392
417
  55P02 E ERRCODE_CANT_CHANGE_RUNTIME_PARAM cant_change_runtime_param
393
418
  55P03 E ERRCODE_LOCK_NOT_AVAILABLE lock_not_available
419
+ 55P04 E ERRCODE_UNSAFE_NEW_ENUM_VALUE_USAGE unsafe_new_enum_value_usage
394
420
 
395
421
  Section: Class 57 - Operator Intervention
396
422
 
@@ -410,6 +436,10 @@ Section: Class 58 - System Error (errors external to PostgreSQL itself)
410
436
  58P01 E ERRCODE_UNDEFINED_FILE undefined_file
411
437
  58P02 E ERRCODE_DUPLICATE_FILE duplicate_file
412
438
 
439
+ Section: Class 72 - Snapshot Failure
440
+ # (class borrowed from Oracle)
441
+ 72000 E ERRCODE_SNAPSHOT_TOO_OLD snapshot_too_old
442
+
413
443
  Section: Class F0 - Configuration File Error
414
444
 
415
445
  # (PostgreSQL-specific error class)
@@ -454,6 +484,7 @@ P0000 E ERRCODE_PLPGSQL_ERROR plp
454
484
  P0001 E ERRCODE_RAISE_EXCEPTION raise_exception
455
485
  P0002 E ERRCODE_NO_DATA_FOUND no_data_found
456
486
  P0003 E ERRCODE_TOO_MANY_ROWS too_many_rows
487
+ P0004 E ERRCODE_ASSERT_FAILURE assert_failure
457
488
 
458
489
  Section: Class XX - Internal Error
459
490
 
@@ -24,7 +24,11 @@ if enable_config("windows-cross")
24
24
  else
25
25
  # Native build
26
26
 
27
- if pgconfig = ( with_config('pg-config') || with_config('pg_config') || find_executable('pg_config') )
27
+ pgconfig = with_config('pg-config') ||
28
+ with_config('pg_config') ||
29
+ find_executable('pg_config')
30
+
31
+ if pgconfig && pgconfig != 'ignore'
28
32
  $stderr.puts "Using config values from %s" % [ pgconfig ]
29
33
  incdir = `"#{pgconfig}" --includedir`.chomp
30
34
  libdir = `"#{pgconfig}" --libdir`.chomp
@@ -43,6 +47,9 @@ else
43
47
  end
44
48
  end
45
49
 
50
+ if RUBY_VERSION >= '2.3.0' && /solaris/ =~ RUBY_PLATFORM
51
+ append_cppflags( '-D__EXTENSIONS__' )
52
+ end
46
53
 
47
54
  find_header( 'libpq-fe.h' ) or abort "Can't find the 'libpq-fe.h header"
48
55
  find_header( 'libpq/libpq-fs.h' ) or abort "Can't find the 'libpq/libpq-fs.h header"
@@ -53,47 +60,30 @@ abort "Can't find the PostgreSQL client library (libpq)" unless
53
60
  have_library( 'libpq', 'PQconnectdb', ['libpq-fe.h'] ) ||
54
61
  have_library( 'ms/libpq', 'PQconnectdb', ['libpq-fe.h'] )
55
62
 
63
+ if /mingw/ =~ RUBY_PLATFORM && RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc/
64
+ # Work around: https://sourceware.org/bugzilla/show_bug.cgi?id=22504
65
+ checking_for "workaround gcc version with link issue" do
66
+ `#{RbConfig::MAKEFILE_CONFIG['CC']} --version`.chomp =~ /\s(\d+)\.\d+\.\d+(\s|$)/ &&
67
+ $1.to_i >= 6 &&
68
+ have_library(':libpq.lib') # Prefer linking to libpq.lib over libpq.dll if available
69
+ end
70
+ end
71
+
56
72
  # optional headers/functions
57
- have_func 'PQconnectionUsedPassword' or
73
+ have_func 'PQsetSingleRowMode' or
58
74
  abort "Your PostgreSQL is too old. Either install an older version " +
59
- "of this gem or upgrade your database."
60
- have_func 'PQisthreadsafe'
61
- have_func 'PQprepare'
62
- have_func 'PQexecParams'
63
- have_func 'PQescapeString'
64
- have_func 'PQescapeStringConn'
65
- have_func 'PQescapeLiteral'
66
- have_func 'PQescapeIdentifier'
67
- have_func 'PQgetCancel'
68
- have_func 'lo_create'
69
- have_func 'pg_encoding_to_char'
70
- have_func 'pg_char_to_encoding'
71
- have_func 'PQsetClientEncoding'
72
- have_func 'PQlibVersion'
73
- have_func 'PQping'
74
- have_func 'PQsetSingleRowMode'
75
- have_func 'PQconninfo'
76
-
77
- have_func 'rb_encdb_alias'
78
- have_func 'rb_enc_alias'
79
- have_func 'rb_thread_call_without_gvl'
80
- have_func 'rb_thread_call_with_gvl'
81
- have_func 'rb_thread_fd_select'
82
- have_func 'rb_w32_wrap_io_handle'
83
- have_func 'rb_str_modify_expand'
84
- have_func 'rb_hash_dup'
85
-
86
- have_const 'PGRES_COPY_BOTH', 'libpq-fe.h'
87
- have_const 'PGRES_SINGLE_TUPLE', 'libpq-fe.h'
88
- have_const 'PG_DIAG_TABLE_NAME', 'libpq-fe.h'
89
-
90
- $defs.push( "-DHAVE_ST_NOTIFY_EXTRA" ) if
91
- have_struct_member 'struct pgNotify', 'extra', 'libpq-fe.h'
75
+ "of this gem or upgrade your database to at least PostgreSQL-9.2."
76
+ have_func 'PQconninfo' # since PostgreSQL-9.3
77
+ have_func 'PQsslAttribute' # since PostgreSQL-9.5
78
+ have_func 'PQresultVerboseErrorMessage' # since PostgreSQL-9.6
79
+ have_func 'PQencryptPasswordConn' # since PostgreSQL-10
80
+ have_func 'PQresultMemorySize' # since PostgreSQL-12
81
+ have_func 'timegm'
82
+ have_func 'rb_gc_adjust_memory_usage' # since ruby-2.4
92
83
 
93
84
  # unistd.h confilicts with ruby/win32.h when cross compiling for win32 and ruby 1.9.1
94
85
  have_header 'unistd.h'
95
86
  have_header 'inttypes.h'
96
- have_header 'ruby/st.h' or have_header 'st.h' or abort "pg currently requires the ruby/st.h header"
97
87
 
98
88
  checking_for "C99 variable length arrays" do
99
89
  $defs.push( "-DHAVE_VARIABLE_LENGTH_ARRAYS" ) if try_compile('void test_vla(int l){ int vla[l]; }')
@@ -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 );
@@ -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
@@ -195,8 +174,16 @@ extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
195
174
  #define FOR_EACH_PARAM_OF_PQsendDescribePortal(param) \
196
175
  param(PGconn *, conn)
197
176
 
177
+ #define FOR_EACH_PARAM_OF_PQsetClientEncoding(param) \
178
+ param(PGconn *, conn)
179
+
198
180
  #define FOR_EACH_PARAM_OF_PQisBusy(param)
199
181
 
182
+ #define FOR_EACH_PARAM_OF_PQencryptPasswordConn(param) \
183
+ param(PGconn *, conn) \
184
+ param(const char *, passwd) \
185
+ param(const char *, user)
186
+
200
187
  #define FOR_EACH_PARAM_OF_PQcancel(param) \
201
188
  param(PGcancel *, cancel) \
202
189
  param(char *, errbuf)
@@ -226,10 +213,11 @@ extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
226
213
  function(PQsendQueryPrepared, GVL_TYPE_NONVOID, int, int, resultFormat) \
227
214
  function(PQsendDescribePrepared, GVL_TYPE_NONVOID, int, const char *, stmt) \
228
215
  function(PQsendDescribePortal, GVL_TYPE_NONVOID, int, const char *, portal) \
216
+ function(PQsetClientEncoding, GVL_TYPE_NONVOID, int, const char *, encoding) \
229
217
  function(PQisBusy, GVL_TYPE_NONVOID, int, PGconn *, conn) \
218
+ function(PQencryptPasswordConn, GVL_TYPE_NONVOID, char *, const char *, algorithm) \
230
219
  function(PQcancel, GVL_TYPE_NONVOID, int, int, errbufsize);
231
220
 
232
-
233
221
  FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_STUB_DECL );
234
222
 
235
223
 
data/ext/pg.c CHANGED
@@ -1,12 +1,13 @@
1
1
  /*
2
2
  * pg.c - Toplevel extension
3
- * $Id: pg.c,v b60c89ee93c8 2015/02/11 20:59:36 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-2015 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
@@ -47,6 +48,7 @@
47
48
 
48
49
  #include "pg.h"
49
50
 
51
+ int pg_skip_deprecation_warning;
50
52
  VALUE rb_mPG;
51
53
  VALUE rb_mPGconstants;
52
54
 
@@ -68,7 +70,6 @@ VALUE rb_mPGconstants;
68
70
  * M17n functions
69
71
  */
70
72
 
71
- #ifdef M17N_SUPPORTED
72
73
  /**
73
74
  * The mapping from canonical encoding names in PostgreSQL to ones in Ruby.
74
75
  */
@@ -142,9 +143,6 @@ pg_find_or_create_johab(void)
142
143
  }
143
144
 
144
145
  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
146
  return rb_enc_from_index(enc_index);
149
147
  }
150
148
 
@@ -228,8 +226,6 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
228
226
  return encname;
229
227
  }
230
228
 
231
- #endif /* M17N_SUPPORTED */
232
-
233
229
 
234
230
  /*
235
231
  * Ensures that the given string has enough capacity to take expand_len
@@ -259,45 +255,26 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
259
255
  * rb_str_set_len( string, current_out - RSTRING_PTR(string) );
260
256
  *
261
257
  */
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;
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;
292
267
  }
293
- #endif
268
+ if( end_ptr )
269
+ *end_ptr = RSTRING_PTR(str) + rb_str_capacity( str );
270
+ return curr_ptr;
271
+ }
294
272
 
295
273
 
296
274
  /**************************************************************************
297
275
  * Module Methods
298
276
  **************************************************************************/
299
277
 
300
- #ifdef HAVE_PQLIBVERSION
301
278
  /*
302
279
  * call-seq:
303
280
  * PG.library_version -> Integer
@@ -315,7 +292,6 @@ pg_s_library_version(VALUE self)
315
292
  UNUSED( self );
316
293
  return INT2NUM(PQlibVersion());
317
294
  }
318
- #endif
319
295
 
320
296
 
321
297
  /*
@@ -355,8 +331,7 @@ pg_to_bool_int(VALUE value)
355
331
  * If your application initializes libssl and/or libcrypto libraries and libpq is
356
332
  * built with SSL support, you should call PG.init_openssl() to tell libpq that the
357
333
  * 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.
334
+ * so that libpq will not also initialize those libraries.
360
335
  *
361
336
  * When do_ssl is +true+, libpq will initialize the OpenSSL library before first
362
337
  * opening a database connection. When do_crypto is +true+, the libcrypto library
@@ -403,15 +378,20 @@ pg_s_init_ssl(VALUE self, VALUE do_ssl)
403
378
  void
404
379
  Init_pg_ext()
405
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
+
406
388
  rb_mPG = rb_define_module( "PG" );
407
389
  rb_mPGconstants = rb_define_module_under( rb_mPG, "Constants" );
408
390
 
409
391
  /*************************
410
392
  * PG module methods
411
393
  *************************/
412
- #ifdef HAVE_PQLIBVERSION
413
394
  rb_define_singleton_method( rb_mPG, "library_version", pg_s_library_version, 0 );
414
- #endif
415
395
  rb_define_singleton_method( rb_mPG, "isthreadsafe", pg_s_threadsafe_p, 0 );
416
396
  SINGLETON_ALIAS( rb_mPG, "is_threadsafe?", "isthreadsafe" );
417
397
  SINGLETON_ALIAS( rb_mPG, "threadsafe?", "isthreadsafe" );
@@ -441,7 +421,7 @@ Init_pg_ext()
441
421
  rb_define_const(rb_mPGconstants, "CONNECTION_SSL_STARTUP", INT2FIX(CONNECTION_SSL_STARTUP));
442
422
  /* Negotiating environment-driven parameter settings. */
443
423
  rb_define_const(rb_mPGconstants, "CONNECTION_SETENV", INT2FIX(CONNECTION_SETENV));
444
- /* Internal state: connect() needed. */
424
+ /* Internal state - PG.connect() needed. */
445
425
  rb_define_const(rb_mPGconstants, "CONNECTION_NEEDED", INT2FIX(CONNECTION_NEEDED));
446
426
 
447
427
  /****** PG::Connection CLASS CONSTANTS: Nonblocking connection polling status ******/
@@ -457,27 +437,48 @@ Init_pg_ext()
457
437
 
458
438
  /****** PG::Connection CLASS CONSTANTS: Transaction Status ******/
459
439
 
460
- /* Transaction is currently idle (#transaction_status) */
440
+ /* Transaction is currently idle ( Connection#transaction_status ) */
461
441
  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) */
442
+ /* Transaction is currently active; query has been sent to the server, but not yet completed. ( Connection#transaction_status ) */
463
443
  rb_define_const(rb_mPGconstants, "PQTRANS_ACTIVE", INT2FIX(PQTRANS_ACTIVE));
464
- /* Transaction is currently idle, in a valid transaction block (#transaction_status) */
444
+ /* Transaction is currently idle, in a valid transaction block ( Connection#transaction_status ) */
465
445
  rb_define_const(rb_mPGconstants, "PQTRANS_INTRANS", INT2FIX(PQTRANS_INTRANS));
466
- /* Transaction is currently idle, in a failed transaction block (#transaction_status) */
446
+ /* Transaction is currently idle, in a failed transaction block ( Connection#transaction_status ) */
467
447
  rb_define_const(rb_mPGconstants, "PQTRANS_INERROR", INT2FIX(PQTRANS_INERROR));
468
- /* Transaction's connection is bad (#transaction_status) */
448
+ /* Transaction's connection is bad ( Connection#transaction_status ) */
469
449
  rb_define_const(rb_mPGconstants, "PQTRANS_UNKNOWN", INT2FIX(PQTRANS_UNKNOWN));
470
450
 
471
451
  /****** PG::Connection CLASS CONSTANTS: Error Verbosity ******/
472
452
 
473
- /* 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. */
474
455
  rb_define_const(rb_mPGconstants, "PQERRORS_TERSE", INT2FIX(PQERRORS_TERSE));
475
- /* 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). */
476
458
  rb_define_const(rb_mPGconstants, "PQERRORS_DEFAULT", INT2FIX(PQERRORS_DEFAULT));
477
- /* Verbose error verbosity level (#set_error_verbosity) */
459
+ /* Error verbosity level ( Connection#set_error_verbosity ).
460
+ * The VERBOSE mode includes all available fields. */
478
461
  rb_define_const(rb_mPGconstants, "PQERRORS_VERBOSE", INT2FIX(PQERRORS_VERBOSE));
479
462
 
480
- #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
+
481
482
  /****** PG::Connection CLASS CONSTANTS: Check Server Status ******/
482
483
 
483
484
  /* Server is accepting connections. */
@@ -488,149 +489,159 @@ Init_pg_ext()
488
489
  rb_define_const(rb_mPGconstants, "PQPING_NO_RESPONSE", INT2FIX(PQPING_NO_RESPONSE));
489
490
  /* Connection not attempted (bad params). */
490
491
  rb_define_const(rb_mPGconstants, "PQPING_NO_ATTEMPT", INT2FIX(PQPING_NO_ATTEMPT));
491
- #endif
492
492
 
493
493
  /****** PG::Connection CLASS CONSTANTS: Large Objects ******/
494
494
 
495
- /* Flag for #lo_creat, #lo_open -- open for writing */
495
+ /* Flag for Connection#lo_creat, Connection#lo_open -- open for writing */
496
496
  rb_define_const(rb_mPGconstants, "INV_WRITE", INT2FIX(INV_WRITE));
497
- /* Flag for #lo_creat, #lo_open -- open for reading */
497
+ /* Flag for Connection#lo_creat, Connection#lo_open -- open for reading */
498
498
  rb_define_const(rb_mPGconstants, "INV_READ", INT2FIX(INV_READ));
499
- /* Flag for #lo_lseek -- seek from object start */
499
+ /* Flag for Connection#lo_lseek -- seek from object start */
500
500
  rb_define_const(rb_mPGconstants, "SEEK_SET", INT2FIX(SEEK_SET));
501
- /* Flag for #lo_lseek -- seek from current position */
501
+ /* Flag for Connection#lo_lseek -- seek from current position */
502
502
  rb_define_const(rb_mPGconstants, "SEEK_CUR", INT2FIX(SEEK_CUR));
503
- /* Flag for #lo_lseek -- seek from object end */
503
+ /* Flag for Connection#lo_lseek -- seek from object end */
504
504
  rb_define_const(rb_mPGconstants, "SEEK_END", INT2FIX(SEEK_END));
505
505
 
506
506
  /****** PG::Result CONSTANTS: result status ******/
507
507
 
508
- /* #result_status constant: The string sent to the server was empty. */
508
+ /* Result#result_status constant - The string sent to the server was empty. */
509
509
  rb_define_const(rb_mPGconstants, "PGRES_EMPTY_QUERY", INT2FIX(PGRES_EMPTY_QUERY));
510
- /* #result_status constant: Successful completion of a command returning no data. */
510
+ /* Result#result_status constant - Successful completion of a command returning no data. */
511
511
  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). */
512
+ /* Result#result_status constant - Successful completion of a command returning data (such as a SELECT or SHOW). */
514
513
  rb_define_const(rb_mPGconstants, "PGRES_TUPLES_OK", INT2FIX(PGRES_TUPLES_OK));
515
- /* #result_status constant: Copy Out (from server) data transfer started. */
514
+ /* Result#result_status constant - Copy Out (from server) data transfer started. */
516
515
  rb_define_const(rb_mPGconstants, "PGRES_COPY_OUT", INT2FIX(PGRES_COPY_OUT));
517
- /* #result_status constant: Copy In (to server) data transfer started. */
516
+ /* Result#result_status constant - Copy In (to server) data transfer started. */
518
517
  rb_define_const(rb_mPGconstants, "PGRES_COPY_IN", INT2FIX(PGRES_COPY_IN));
519
- /* #result_status constant: The server’s response was not understood. */
518
+ /* Result#result_status constant - The server’s response was not understood. */
520
519
  rb_define_const(rb_mPGconstants, "PGRES_BAD_RESPONSE", INT2FIX(PGRES_BAD_RESPONSE));
521
- /* #result_status constant: A nonfatal error (a notice or warning) occurred. */
520
+ /* Result#result_status constant - A nonfatal error (a notice or warning) occurred. */
522
521
  rb_define_const(rb_mPGconstants, "PGRES_NONFATAL_ERROR",INT2FIX(PGRES_NONFATAL_ERROR));
523
- /* #result_status constant: A fatal error occurred. */
522
+ /* Result#result_status constant - A fatal error occurred. */
524
523
  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
524
+ /* Result#result_status constant - Copy In/Out data transfer in progress. */
527
525
  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
526
+ /* Result#result_status constant - Single tuple from larger resultset. */
531
527
  rb_define_const(rb_mPGconstants, "PGRES_SINGLE_TUPLE", INT2FIX(PGRES_SINGLE_TUPLE));
532
- #endif
533
528
 
534
529
  /****** Result CONSTANTS: result error field codes ******/
535
530
 
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.
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.
540
536
  */
541
537
  rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY", INT2FIX(PG_DIAG_SEVERITY));
542
538
 
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.
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.
549
555
  */
550
556
  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. */
557
+ /* Result#result_error_field argument constant
558
+ *
559
+ * The primary human-readable error message (typically one line).
560
+ * Always present. */
554
561
  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.
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.
559
566
  */
560
567
  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.
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.
566
573
  */
567
-
568
574
  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.
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.
573
580
  */
574
-
575
581
  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.
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.
581
586
  */
582
-
583
587
  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.
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.
587
592
  */
588
-
589
593
  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.
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.
594
599
  */
595
-
596
600
  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. */
601
+ /* Result#result_error_field argument constant
602
+ *
603
+ * The file name of the source-code location where the error was reported. */
599
604
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FILE", INT2FIX(PG_DIAG_SOURCE_FILE));
600
605
 
601
- /* #result_error_field argument constant: The line number of the
602
- * 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. */
603
609
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_LINE", INT2FIX(PG_DIAG_SOURCE_LINE));
604
610
 
605
- /* #result_error_field argument constant: The name of the source-code
606
- * function reporting the error. */
611
+ /* Result#result_error_field argument constant
612
+ *
613
+ * The name of the source-code function reporting the error. */
607
614
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FUNCTION", INT2FIX(PG_DIAG_SOURCE_FUNCTION));
608
615
 
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. */
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. */
612
620
  rb_define_const(rb_mPGconstants, "PG_DIAG_SCHEMA_NAME", INT2FIX(PG_DIAG_SCHEMA_NAME));
613
621
 
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.) */
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.) */
617
626
  rb_define_const(rb_mPGconstants, "PG_DIAG_TABLE_NAME", INT2FIX(PG_DIAG_TABLE_NAME));
618
627
 
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.) */
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.) */
622
632
  rb_define_const(rb_mPGconstants, "PG_DIAG_COLUMN_NAME", INT2FIX(PG_DIAG_COLUMN_NAME));
623
633
 
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.) */
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.) */
627
638
  rb_define_const(rb_mPGconstants, "PG_DIAG_DATATYPE_NAME", INT2FIX(PG_DIAG_DATATYPE_NAME));
628
639
 
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.) */
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.) */
634
645
  rb_define_const(rb_mPGconstants, "PG_DIAG_CONSTRAINT_NAME", INT2FIX(PG_DIAG_CONSTRAINT_NAME));
635
646
  #endif
636
647
 
@@ -641,9 +652,7 @@ Init_pg_ext()
641
652
  /* Add the constants to the toplevel namespace */
642
653
  rb_include_module( rb_mPG, rb_mPGconstants );
643
654
 
644
- #ifdef M17N_SUPPORTED
645
655
  enc_pg2ruby = st_init_numtable();
646
- #endif
647
656
 
648
657
  /* Initialize the main extension classes */
649
658
  init_pg_connection();
@@ -662,5 +671,7 @@ Init_pg_ext()
662
671
  init_pg_binary_encoder();
663
672
  init_pg_binary_decoder();
664
673
  init_pg_copycoder();
674
+ init_pg_recordcoder();
675
+ init_pg_tuple();
665
676
  }
666
677