pg 0.18.2 → 1.4.5
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.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.appveyor.yml +36 -0
- data/.gems +6 -0
- data/.github/workflows/binary-gems.yml +86 -0
- data/.github/workflows/source-gem.yml +131 -0
- data/.gitignore +13 -0
- data/.hgsigs +34 -0
- data/.hgtags +41 -0
- data/.irbrc +23 -0
- data/.pryrc +23 -0
- data/.tm_properties +21 -0
- data/.travis.yml +49 -0
- data/BSDL +2 -2
- data/Gemfile +14 -0
- data/History.rdoc +480 -4
- data/Manifest.txt +8 -21
- data/README-Windows.rdoc +17 -28
- data/README.ja.rdoc +1 -2
- data/README.rdoc +92 -20
- data/Rakefile +33 -133
- data/Rakefile.cross +89 -67
- data/certs/ged.pem +24 -0
- data/certs/larskanis-2022.pem +26 -0
- data/ext/errorcodes.def +113 -0
- data/ext/errorcodes.rb +1 -1
- data/ext/errorcodes.txt +36 -2
- data/ext/extconf.rb +120 -54
- data/ext/gvl_wrappers.c +8 -0
- data/ext/gvl_wrappers.h +44 -33
- data/ext/pg.c +216 -172
- data/ext/pg.h +93 -98
- data/ext/pg_binary_decoder.c +85 -16
- data/ext/pg_binary_encoder.c +25 -22
- data/ext/pg_coder.c +176 -40
- data/ext/pg_connection.c +1735 -1138
- data/ext/pg_copy_coder.c +95 -28
- data/ext/pg_errors.c +1 -1
- data/ext/pg_record_coder.c +521 -0
- data/ext/pg_result.c +642 -221
- data/ext/pg_text_decoder.c +609 -41
- data/ext/pg_text_encoder.c +254 -100
- data/ext/pg_tuple.c +569 -0
- data/ext/pg_type_map.c +62 -22
- data/ext/pg_type_map_all_strings.c +20 -6
- data/ext/pg_type_map_by_class.c +55 -25
- data/ext/pg_type_map_by_column.c +81 -42
- data/ext/pg_type_map_by_mri_type.c +49 -20
- data/ext/pg_type_map_by_oid.c +56 -26
- data/ext/pg_type_map_in_ruby.c +52 -21
- data/ext/{util.c → pg_util.c} +12 -12
- data/ext/{util.h → pg_util.h} +2 -2
- data/lib/pg/basic_type_map_based_on_result.rb +47 -0
- data/lib/pg/basic_type_map_for_queries.rb +193 -0
- data/lib/pg/basic_type_map_for_results.rb +81 -0
- data/lib/pg/basic_type_registry.rb +301 -0
- data/lib/pg/binary_decoder.rb +23 -0
- data/lib/pg/coder.rb +24 -3
- data/lib/pg/connection.rb +711 -64
- data/lib/pg/constants.rb +2 -1
- data/lib/pg/exceptions.rb +9 -2
- data/lib/pg/result.rb +24 -7
- data/lib/pg/text_decoder.rb +27 -23
- data/lib/pg/text_encoder.rb +40 -8
- data/lib/pg/tuple.rb +30 -0
- data/lib/pg/type_map_by_column.rb +3 -2
- data/lib/pg/version.rb +4 -0
- data/lib/pg.rb +61 -36
- data/misc/openssl-pg-segfault.rb +31 -0
- data/misc/postgres/History.txt +9 -0
- data/misc/postgres/Manifest.txt +5 -0
- data/misc/postgres/README.txt +21 -0
- data/misc/postgres/Rakefile +21 -0
- data/misc/postgres/lib/postgres.rb +16 -0
- data/misc/ruby-pg/History.txt +9 -0
- data/misc/ruby-pg/Manifest.txt +5 -0
- data/misc/ruby-pg/README.txt +21 -0
- data/misc/ruby-pg/Rakefile +21 -0
- data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
- data/pg.gemspec +32 -0
- data/rakelib/task_extension.rb +46 -0
- data/sample/array_insert.rb +1 -1
- data/sample/async_api.rb +4 -8
- data/sample/async_copyto.rb +1 -1
- data/sample/async_mixed.rb +1 -1
- data/sample/check_conn.rb +1 -1
- data/sample/copydata.rb +71 -0
- data/sample/copyfrom.rb +1 -1
- data/sample/copyto.rb +1 -1
- data/sample/cursor.rb +1 -1
- data/sample/disk_usage_report.rb +6 -15
- data/sample/issue-119.rb +2 -2
- data/sample/losample.rb +1 -1
- data/sample/minimal-testcase.rb +2 -2
- data/sample/notify_wait.rb +1 -1
- data/sample/pg_statistics.rb +6 -15
- data/sample/replication_monitor.rb +9 -18
- data/sample/test_binary_values.rb +1 -1
- data/sample/wal_shipper.rb +2 -2
- data/sample/warehouse_partitions.rb +8 -17
- data.tar.gz.sig +0 -0
- metadata +74 -216
- metadata.gz.sig +0 -0
- data/ChangeLog +0 -5545
- data/lib/pg/basic_type_mapping.rb +0 -399
- data/spec/data/expected_trace.out +0 -26
- data/spec/data/random_binary_data +0 -0
- data/spec/helpers.rb +0 -355
- data/spec/pg/basic_type_mapping_spec.rb +0 -251
- data/spec/pg/connection_spec.rb +0 -1535
- data/spec/pg/result_spec.rb +0 -449
- data/spec/pg/type_map_by_class_spec.rb +0 -138
- data/spec/pg/type_map_by_column_spec.rb +0 -222
- data/spec/pg/type_map_by_mri_type_spec.rb +0 -136
- data/spec/pg/type_map_by_oid_spec.rb +0 -149
- data/spec/pg/type_map_in_ruby_spec.rb +0 -164
- data/spec/pg/type_map_spec.rb +0 -22
- data/spec/pg/type_spec.rb +0 -688
- data/spec/pg_spec.rb +0 -50
data/ext/pg.c
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* pg.c - Toplevel extension
|
|
3
|
-
* $Id
|
|
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-
|
|
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
|
-
*
|
|
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
|
*/
|
|
@@ -125,29 +126,6 @@ const char * const (pg_enc_pg2ruby_mapping[][2]) = {
|
|
|
125
126
|
static struct st_table *enc_pg2ruby;
|
|
126
127
|
|
|
127
128
|
|
|
128
|
-
/*
|
|
129
|
-
* Look up the JOHAB encoding, creating it as a dummy encoding if it's not
|
|
130
|
-
* already defined.
|
|
131
|
-
*/
|
|
132
|
-
static rb_encoding *
|
|
133
|
-
pg_find_or_create_johab(void)
|
|
134
|
-
{
|
|
135
|
-
static const char * const aliases[] = { "JOHAB", "Windows-1361", "CP1361" };
|
|
136
|
-
int enc_index;
|
|
137
|
-
size_t i;
|
|
138
|
-
|
|
139
|
-
for (i = 0; i < sizeof(aliases)/sizeof(aliases[0]); ++i) {
|
|
140
|
-
enc_index = rb_enc_find_index(aliases[i]);
|
|
141
|
-
if (enc_index > 0) return rb_enc_from_index(enc_index);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
enc_index = rb_define_dummy_encoding(aliases[0]);
|
|
145
|
-
for (i = 1; i < sizeof(aliases)/sizeof(aliases[0]); ++i) {
|
|
146
|
-
ENC_ALIAS(aliases[i], aliases[0]);
|
|
147
|
-
}
|
|
148
|
-
return rb_enc_from_index(enc_index);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
129
|
/*
|
|
152
130
|
* Return the given PostgreSQL encoding ID as an rb_encoding.
|
|
153
131
|
*
|
|
@@ -188,10 +166,6 @@ pg_get_pg_encname_as_rb_encoding( const char *pg_encname )
|
|
|
188
166
|
return rb_enc_find( pg_enc_pg2ruby_mapping[i][1] );
|
|
189
167
|
}
|
|
190
168
|
|
|
191
|
-
/* JOHAB isn't a builtin encoding, so make up a dummy encoding if it's seen */
|
|
192
|
-
if ( strncmp(pg_encname, "JOHAB", 5) == 0 )
|
|
193
|
-
return pg_find_or_create_johab();
|
|
194
|
-
|
|
195
169
|
/* Fallthrough to ASCII-8BIT */
|
|
196
170
|
return rb_ascii8bit_encoding();
|
|
197
171
|
}
|
|
@@ -228,8 +202,6 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
|
|
|
228
202
|
return encname;
|
|
229
203
|
}
|
|
230
204
|
|
|
231
|
-
#endif /* M17N_SUPPORTED */
|
|
232
|
-
|
|
233
205
|
|
|
234
206
|
/*
|
|
235
207
|
* Ensures that the given string has enough capacity to take expand_len
|
|
@@ -259,45 +231,26 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
|
|
|
259
231
|
* rb_str_set_len( string, current_out - RSTRING_PTR(string) );
|
|
260
232
|
*
|
|
261
233
|
*/
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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;
|
|
234
|
+
char *
|
|
235
|
+
pg_rb_str_ensure_capa( VALUE str, long expand_len, char *curr_ptr, char **end_ptr )
|
|
236
|
+
{
|
|
237
|
+
long curr_len = curr_ptr - RSTRING_PTR(str);
|
|
238
|
+
long curr_capa = rb_str_capacity( str );
|
|
239
|
+
if( curr_capa < curr_len + expand_len ){
|
|
240
|
+
rb_str_set_len( str, curr_len );
|
|
241
|
+
rb_str_modify_expand( str, (curr_len + expand_len) * 2 - curr_capa );
|
|
242
|
+
curr_ptr = RSTRING_PTR(str) + curr_len;
|
|
292
243
|
}
|
|
293
|
-
|
|
244
|
+
if( end_ptr )
|
|
245
|
+
*end_ptr = RSTRING_PTR(str) + rb_str_capacity( str );
|
|
246
|
+
return curr_ptr;
|
|
247
|
+
}
|
|
294
248
|
|
|
295
249
|
|
|
296
250
|
/**************************************************************************
|
|
297
251
|
* Module Methods
|
|
298
252
|
**************************************************************************/
|
|
299
253
|
|
|
300
|
-
#ifdef HAVE_PQLIBVERSION
|
|
301
254
|
/*
|
|
302
255
|
* call-seq:
|
|
303
256
|
* PG.library_version -> Integer
|
|
@@ -315,7 +268,6 @@ pg_s_library_version(VALUE self)
|
|
|
315
268
|
UNUSED( self );
|
|
316
269
|
return INT2NUM(PQlibVersion());
|
|
317
270
|
}
|
|
318
|
-
#endif
|
|
319
271
|
|
|
320
272
|
|
|
321
273
|
/*
|
|
@@ -355,8 +307,7 @@ pg_to_bool_int(VALUE value)
|
|
|
355
307
|
* If your application initializes libssl and/or libcrypto libraries and libpq is
|
|
356
308
|
* built with SSL support, you should call PG.init_openssl() to tell libpq that the
|
|
357
309
|
* libssl and/or libcrypto libraries have been initialized by your application,
|
|
358
|
-
* so that libpq will not also initialize those libraries.
|
|
359
|
-
* http://h71000.www7.hp.com/doc/83final/BA554_90007/ch04.html for details on the SSL API.
|
|
310
|
+
* so that libpq will not also initialize those libraries.
|
|
360
311
|
*
|
|
361
312
|
* When do_ssl is +true+, libpq will initialize the OpenSSL library before first
|
|
362
313
|
* opening a database connection. When do_crypto is +true+, the libcrypto library
|
|
@@ -401,17 +352,22 @@ pg_s_init_ssl(VALUE self, VALUE do_ssl)
|
|
|
401
352
|
**************************************************************************/
|
|
402
353
|
|
|
403
354
|
void
|
|
404
|
-
Init_pg_ext()
|
|
355
|
+
Init_pg_ext(void)
|
|
405
356
|
{
|
|
357
|
+
if( RTEST(rb_eval_string("ENV['PG_SKIP_DEPRECATION_WARNING']")) ){
|
|
358
|
+
/* Set all bits to disable all deprecation warnings. */
|
|
359
|
+
pg_skip_deprecation_warning = 0xFFFF;
|
|
360
|
+
} else {
|
|
361
|
+
pg_skip_deprecation_warning = 0;
|
|
362
|
+
}
|
|
363
|
+
|
|
406
364
|
rb_mPG = rb_define_module( "PG" );
|
|
407
365
|
rb_mPGconstants = rb_define_module_under( rb_mPG, "Constants" );
|
|
408
366
|
|
|
409
367
|
/*************************
|
|
410
368
|
* PG module methods
|
|
411
369
|
*************************/
|
|
412
|
-
#ifdef HAVE_PQLIBVERSION
|
|
413
370
|
rb_define_singleton_method( rb_mPG, "library_version", pg_s_library_version, 0 );
|
|
414
|
-
#endif
|
|
415
371
|
rb_define_singleton_method( rb_mPG, "isthreadsafe", pg_s_threadsafe_p, 0 );
|
|
416
372
|
SINGLETON_ALIAS( rb_mPG, "is_threadsafe?", "isthreadsafe" );
|
|
417
373
|
SINGLETON_ALIAS( rb_mPG, "threadsafe?", "isthreadsafe" );
|
|
@@ -435,14 +391,34 @@ Init_pg_ext()
|
|
|
435
391
|
rb_define_const(rb_mPGconstants, "CONNECTION_MADE", INT2FIX(CONNECTION_MADE));
|
|
436
392
|
/* Waiting for a response from the server. */
|
|
437
393
|
rb_define_const(rb_mPGconstants, "CONNECTION_AWAITING_RESPONSE", INT2FIX(CONNECTION_AWAITING_RESPONSE));
|
|
438
|
-
/* Received authentication; waiting for backend
|
|
394
|
+
/* Received authentication; waiting for backend startup. */
|
|
439
395
|
rb_define_const(rb_mPGconstants, "CONNECTION_AUTH_OK", INT2FIX(CONNECTION_AUTH_OK));
|
|
396
|
+
/* This state is no longer used. */
|
|
397
|
+
rb_define_const(rb_mPGconstants, "CONNECTION_SETENV", INT2FIX(CONNECTION_SETENV));
|
|
440
398
|
/* Negotiating SSL encryption. */
|
|
441
399
|
rb_define_const(rb_mPGconstants, "CONNECTION_SSL_STARTUP", INT2FIX(CONNECTION_SSL_STARTUP));
|
|
442
|
-
/*
|
|
443
|
-
rb_define_const(rb_mPGconstants, "CONNECTION_SETENV", INT2FIX(CONNECTION_SETENV));
|
|
444
|
-
/* Internal state: connect() needed. */
|
|
400
|
+
/* Internal state - PG.connect() needed. */
|
|
445
401
|
rb_define_const(rb_mPGconstants, "CONNECTION_NEEDED", INT2FIX(CONNECTION_NEEDED));
|
|
402
|
+
#if PG_MAJORVERSION_NUM >= 10
|
|
403
|
+
/* Checking if session is read-write. Available since PostgreSQL-10. */
|
|
404
|
+
rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_WRITABLE", INT2FIX(CONNECTION_CHECK_WRITABLE));
|
|
405
|
+
#endif
|
|
406
|
+
#if PG_MAJORVERSION_NUM >= 10
|
|
407
|
+
/* Consuming any extra messages. Available since PostgreSQL-10. */
|
|
408
|
+
rb_define_const(rb_mPGconstants, "CONNECTION_CONSUME", INT2FIX(CONNECTION_CONSUME));
|
|
409
|
+
#endif
|
|
410
|
+
#if PG_MAJORVERSION_NUM >= 12
|
|
411
|
+
/* Negotiating GSSAPI. Available since PostgreSQL-12. */
|
|
412
|
+
rb_define_const(rb_mPGconstants, "CONNECTION_GSS_STARTUP", INT2FIX(CONNECTION_GSS_STARTUP));
|
|
413
|
+
#endif
|
|
414
|
+
#if PG_MAJORVERSION_NUM >= 13
|
|
415
|
+
/* Checking target server properties. Available since PostgreSQL-13. */
|
|
416
|
+
rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_TARGET", INT2FIX(CONNECTION_CHECK_TARGET));
|
|
417
|
+
#endif
|
|
418
|
+
#if PG_MAJORVERSION_NUM >= 14
|
|
419
|
+
/* Checking if server is in standby mode. Available since PostgreSQL-14. */
|
|
420
|
+
rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_STANDBY", INT2FIX(CONNECTION_CHECK_STANDBY));
|
|
421
|
+
#endif
|
|
446
422
|
|
|
447
423
|
/****** PG::Connection CLASS CONSTANTS: Nonblocking connection polling status ******/
|
|
448
424
|
|
|
@@ -457,27 +433,48 @@ Init_pg_ext()
|
|
|
457
433
|
|
|
458
434
|
/****** PG::Connection CLASS CONSTANTS: Transaction Status ******/
|
|
459
435
|
|
|
460
|
-
/* Transaction is currently idle (#transaction_status) */
|
|
436
|
+
/* Transaction is currently idle ( Connection#transaction_status ) */
|
|
461
437
|
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) */
|
|
438
|
+
/* Transaction is currently active; query has been sent to the server, but not yet completed. ( Connection#transaction_status ) */
|
|
463
439
|
rb_define_const(rb_mPGconstants, "PQTRANS_ACTIVE", INT2FIX(PQTRANS_ACTIVE));
|
|
464
|
-
/* Transaction is currently idle, in a valid transaction block (#transaction_status) */
|
|
440
|
+
/* Transaction is currently idle, in a valid transaction block ( Connection#transaction_status ) */
|
|
465
441
|
rb_define_const(rb_mPGconstants, "PQTRANS_INTRANS", INT2FIX(PQTRANS_INTRANS));
|
|
466
|
-
/* Transaction is currently idle, in a failed transaction block (#transaction_status) */
|
|
442
|
+
/* Transaction is currently idle, in a failed transaction block ( Connection#transaction_status ) */
|
|
467
443
|
rb_define_const(rb_mPGconstants, "PQTRANS_INERROR", INT2FIX(PQTRANS_INERROR));
|
|
468
|
-
/* Transaction's connection is bad (#transaction_status) */
|
|
444
|
+
/* Transaction's connection is bad ( Connection#transaction_status ) */
|
|
469
445
|
rb_define_const(rb_mPGconstants, "PQTRANS_UNKNOWN", INT2FIX(PQTRANS_UNKNOWN));
|
|
470
446
|
|
|
471
447
|
/****** PG::Connection CLASS CONSTANTS: Error Verbosity ******/
|
|
472
448
|
|
|
473
|
-
/*
|
|
449
|
+
/* Error verbosity level ( Connection#set_error_verbosity ).
|
|
450
|
+
* In TERSE mode, returned messages include severity, primary text, and position only; this will normally fit on a single line. */
|
|
474
451
|
rb_define_const(rb_mPGconstants, "PQERRORS_TERSE", INT2FIX(PQERRORS_TERSE));
|
|
475
|
-
/*
|
|
452
|
+
/* Error verbosity level ( Connection#set_error_verbosity ).
|
|
453
|
+
* The DEFAULT mode produces messages that include the above plus any detail, hint, or context fields (these might span multiple lines). */
|
|
476
454
|
rb_define_const(rb_mPGconstants, "PQERRORS_DEFAULT", INT2FIX(PQERRORS_DEFAULT));
|
|
477
|
-
/*
|
|
455
|
+
/* Error verbosity level ( Connection#set_error_verbosity ).
|
|
456
|
+
* The VERBOSE mode includes all available fields. */
|
|
478
457
|
rb_define_const(rb_mPGconstants, "PQERRORS_VERBOSE", INT2FIX(PQERRORS_VERBOSE));
|
|
479
458
|
|
|
480
|
-
|
|
459
|
+
/* PQERRORS_SQLSTATE was introduced in PG-12 together with PQresultMemorySize() */
|
|
460
|
+
#ifdef HAVE_PQRESULTMEMORYSIZE
|
|
461
|
+
/* Error verbosity level ( Connection#set_error_verbosity ).
|
|
462
|
+
* 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).
|
|
463
|
+
*
|
|
464
|
+
* Available since PostgreSQL-12.
|
|
465
|
+
*/
|
|
466
|
+
rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
|
|
467
|
+
#endif
|
|
468
|
+
|
|
469
|
+
#ifdef HAVE_PQRESULTVERBOSEERRORMESSAGE
|
|
470
|
+
/* See Connection#set_error_context_visibility */
|
|
471
|
+
rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_NEVER", INT2FIX(PQSHOW_CONTEXT_NEVER));
|
|
472
|
+
/* See Connection#set_error_context_visibility */
|
|
473
|
+
rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_ERRORS", INT2FIX(PQSHOW_CONTEXT_ERRORS));
|
|
474
|
+
/* See Connection#set_error_context_visibility */
|
|
475
|
+
rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_ALWAYS", INT2FIX(PQSHOW_CONTEXT_ALWAYS));
|
|
476
|
+
#endif
|
|
477
|
+
|
|
481
478
|
/****** PG::Connection CLASS CONSTANTS: Check Server Status ******/
|
|
482
479
|
|
|
483
480
|
/* Server is accepting connections. */
|
|
@@ -488,162 +485,207 @@ Init_pg_ext()
|
|
|
488
485
|
rb_define_const(rb_mPGconstants, "PQPING_NO_RESPONSE", INT2FIX(PQPING_NO_RESPONSE));
|
|
489
486
|
/* Connection not attempted (bad params). */
|
|
490
487
|
rb_define_const(rb_mPGconstants, "PQPING_NO_ATTEMPT", INT2FIX(PQPING_NO_ATTEMPT));
|
|
491
|
-
#endif
|
|
492
488
|
|
|
493
489
|
/****** PG::Connection CLASS CONSTANTS: Large Objects ******/
|
|
494
490
|
|
|
495
|
-
/* Flag for #lo_creat, #lo_open -- open for writing */
|
|
491
|
+
/* Flag for Connection#lo_creat, Connection#lo_open -- open for writing */
|
|
496
492
|
rb_define_const(rb_mPGconstants, "INV_WRITE", INT2FIX(INV_WRITE));
|
|
497
|
-
/* Flag for #lo_creat, #lo_open -- open for reading */
|
|
493
|
+
/* Flag for Connection#lo_creat, Connection#lo_open -- open for reading */
|
|
498
494
|
rb_define_const(rb_mPGconstants, "INV_READ", INT2FIX(INV_READ));
|
|
499
|
-
/* Flag for #lo_lseek -- seek from object start */
|
|
495
|
+
/* Flag for Connection#lo_lseek -- seek from object start */
|
|
500
496
|
rb_define_const(rb_mPGconstants, "SEEK_SET", INT2FIX(SEEK_SET));
|
|
501
|
-
/* Flag for #lo_lseek -- seek from current position */
|
|
497
|
+
/* Flag for Connection#lo_lseek -- seek from current position */
|
|
502
498
|
rb_define_const(rb_mPGconstants, "SEEK_CUR", INT2FIX(SEEK_CUR));
|
|
503
|
-
/* Flag for #lo_lseek -- seek from object end */
|
|
499
|
+
/* Flag for Connection#lo_lseek -- seek from object end */
|
|
504
500
|
rb_define_const(rb_mPGconstants, "SEEK_END", INT2FIX(SEEK_END));
|
|
505
501
|
|
|
506
502
|
/****** PG::Result CONSTANTS: result status ******/
|
|
507
503
|
|
|
508
|
-
/* #result_status constant
|
|
504
|
+
/* Result#result_status constant - The string sent to the server was empty. */
|
|
509
505
|
rb_define_const(rb_mPGconstants, "PGRES_EMPTY_QUERY", INT2FIX(PGRES_EMPTY_QUERY));
|
|
510
|
-
/* #result_status constant
|
|
506
|
+
/* Result#result_status constant - Successful completion of a command returning no data. */
|
|
511
507
|
rb_define_const(rb_mPGconstants, "PGRES_COMMAND_OK", INT2FIX(PGRES_COMMAND_OK));
|
|
512
|
-
|
|
513
|
-
(such as a SELECT or SHOW). */
|
|
508
|
+
/* Result#result_status constant - Successful completion of a command returning data (such as a SELECT or SHOW). */
|
|
514
509
|
rb_define_const(rb_mPGconstants, "PGRES_TUPLES_OK", INT2FIX(PGRES_TUPLES_OK));
|
|
515
|
-
/* #result_status constant
|
|
510
|
+
/* Result#result_status constant - Copy Out (from server) data transfer started. */
|
|
516
511
|
rb_define_const(rb_mPGconstants, "PGRES_COPY_OUT", INT2FIX(PGRES_COPY_OUT));
|
|
517
|
-
/* #result_status constant
|
|
512
|
+
/* Result#result_status constant - Copy In (to server) data transfer started. */
|
|
518
513
|
rb_define_const(rb_mPGconstants, "PGRES_COPY_IN", INT2FIX(PGRES_COPY_IN));
|
|
519
|
-
/* #result_status constant
|
|
514
|
+
/* Result#result_status constant - The server’s response was not understood. */
|
|
520
515
|
rb_define_const(rb_mPGconstants, "PGRES_BAD_RESPONSE", INT2FIX(PGRES_BAD_RESPONSE));
|
|
521
|
-
/* #result_status constant
|
|
516
|
+
/* Result#result_status constant - A nonfatal error (a notice or warning) occurred. */
|
|
522
517
|
rb_define_const(rb_mPGconstants, "PGRES_NONFATAL_ERROR",INT2FIX(PGRES_NONFATAL_ERROR));
|
|
523
|
-
/* #result_status constant
|
|
518
|
+
/* Result#result_status constant - A fatal error occurred. */
|
|
524
519
|
rb_define_const(rb_mPGconstants, "PGRES_FATAL_ERROR", INT2FIX(PGRES_FATAL_ERROR));
|
|
525
|
-
/* #result_status constant
|
|
526
|
-
#ifdef HAVE_CONST_PGRES_COPY_BOTH
|
|
520
|
+
/* Result#result_status constant - Copy In/Out data transfer in progress. */
|
|
527
521
|
rb_define_const(rb_mPGconstants, "PGRES_COPY_BOTH", INT2FIX(PGRES_COPY_BOTH));
|
|
528
|
-
#
|
|
529
|
-
/* #result_status constant: Single tuple from larger resultset. */
|
|
530
|
-
#ifdef HAVE_CONST_PGRES_SINGLE_TUPLE
|
|
522
|
+
/* Result#result_status constant - Single tuple from larger resultset. */
|
|
531
523
|
rb_define_const(rb_mPGconstants, "PGRES_SINGLE_TUPLE", INT2FIX(PGRES_SINGLE_TUPLE));
|
|
524
|
+
|
|
525
|
+
#ifdef HAVE_PQENTERPIPELINEMODE
|
|
526
|
+
/* Result#result_status constant - The PG::Result represents a synchronization point in pipeline mode, requested by Connection#pipeline_sync.
|
|
527
|
+
*
|
|
528
|
+
* This status occurs only when pipeline mode has been selected. */
|
|
529
|
+
rb_define_const(rb_mPGconstants, "PGRES_PIPELINE_SYNC", INT2FIX(PGRES_PIPELINE_SYNC));
|
|
530
|
+
|
|
531
|
+
/* Result#result_status constant - The PG::Result represents a pipeline that has received an error from the server.
|
|
532
|
+
*
|
|
533
|
+
* 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.
|
|
534
|
+
*/
|
|
535
|
+
rb_define_const(rb_mPGconstants, "PGRES_PIPELINE_ABORTED", INT2FIX(PGRES_PIPELINE_ABORTED));
|
|
532
536
|
#endif
|
|
533
537
|
|
|
534
538
|
/****** Result CONSTANTS: result error field codes ******/
|
|
535
539
|
|
|
536
|
-
/* #result_error_field argument constant
|
|
537
|
-
*
|
|
538
|
-
* DEBUG, INFO, or LOG (in a notice message), or a localized translation
|
|
539
|
-
* of one of these.
|
|
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), or a localized translation
|
|
543
|
+
* of one of these.
|
|
544
|
+
* Always present.
|
|
540
545
|
*/
|
|
541
546
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY", INT2FIX(PG_DIAG_SEVERITY));
|
|
542
547
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
548
|
+
#ifdef PG_DIAG_SEVERITY_NONLOCALIZED
|
|
549
|
+
/* Result#result_error_field argument constant
|
|
550
|
+
*
|
|
551
|
+
* 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).
|
|
552
|
+
* This is identical to the PG_DIAG_SEVERITY field except that the contents are never localized.
|
|
553
|
+
*
|
|
554
|
+
* Available since PostgreSQL-9.6
|
|
555
|
+
*/
|
|
556
|
+
rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY_NONLOCALIZED", INT2FIX(PG_DIAG_SEVERITY_NONLOCALIZED));
|
|
557
|
+
#endif
|
|
558
|
+
/* Result#result_error_field argument constant
|
|
559
|
+
*
|
|
560
|
+
* The SQLSTATE code for the error.
|
|
561
|
+
* 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.
|
|
562
|
+
* For a list of the possible SQLSTATE codes, see Appendix A.
|
|
563
|
+
* This field is not localizable, and is always present.
|
|
549
564
|
*/
|
|
550
565
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SQLSTATE", INT2FIX(PG_DIAG_SQLSTATE));
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
* error message (typically one line).
|
|
566
|
+
/* Result#result_error_field argument constant
|
|
567
|
+
*
|
|
568
|
+
* The primary human-readable error message (typically one line).
|
|
569
|
+
* Always present. */
|
|
554
570
|
rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_PRIMARY", INT2FIX(PG_DIAG_MESSAGE_PRIMARY));
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
* error message carrying more detail about the problem.
|
|
558
|
-
* multiple lines.
|
|
571
|
+
/* Result#result_error_field argument constant
|
|
572
|
+
*
|
|
573
|
+
* Detail: an optional secondary error message carrying more detail about the problem.
|
|
574
|
+
* Might run to multiple lines.
|
|
559
575
|
*/
|
|
560
576
|
rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_DETAIL", INT2FIX(PG_DIAG_MESSAGE_DETAIL));
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
* what to do about the problem.
|
|
564
|
-
* in that it offers advice (potentially inappropriate) rather than
|
|
565
|
-
*
|
|
577
|
+
/* Result#result_error_field argument constant
|
|
578
|
+
*
|
|
579
|
+
* Hint: an optional suggestion what to do about the problem.
|
|
580
|
+
* This is intended to differ from detail in that it offers advice (potentially inappropriate) rather than hard facts.
|
|
581
|
+
* Might run to multiple lines.
|
|
566
582
|
*/
|
|
567
|
-
|
|
568
583
|
rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_HINT", INT2FIX(PG_DIAG_MESSAGE_HINT));
|
|
569
|
-
/* #result_error_field argument constant
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
584
|
+
/* Result#result_error_field argument constant
|
|
585
|
+
*
|
|
586
|
+
* A string containing a decimal integer indicating an error cursor position as an index into the original statement string.
|
|
587
|
+
*
|
|
588
|
+
* The first character has index 1, and positions are measured in characters not bytes.
|
|
573
589
|
*/
|
|
574
|
-
|
|
575
590
|
rb_define_const(rb_mPGconstants, "PG_DIAG_STATEMENT_POSITION", INT2FIX(PG_DIAG_STATEMENT_POSITION));
|
|
576
|
-
/* #result_error_field argument constant
|
|
577
|
-
*
|
|
578
|
-
* position refers to an internally generated command rather than the
|
|
579
|
-
*
|
|
580
|
-
* always appear when this eld appears.
|
|
591
|
+
/* Result#result_error_field argument constant
|
|
592
|
+
*
|
|
593
|
+
* 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.
|
|
594
|
+
* The PG_DIAG_INTERNAL_QUERY field will always appear when this field appears.
|
|
581
595
|
*/
|
|
582
|
-
|
|
583
596
|
rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_POSITION", INT2FIX(PG_DIAG_INTERNAL_POSITION));
|
|
584
|
-
/* #result_error_field argument constant
|
|
585
|
-
*
|
|
586
|
-
*
|
|
597
|
+
/* Result#result_error_field argument constant
|
|
598
|
+
*
|
|
599
|
+
* The text of a failed internally-generated command.
|
|
600
|
+
* This could be, for example, a SQL query issued by a PL/pgSQL function.
|
|
587
601
|
*/
|
|
588
|
-
|
|
589
602
|
rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_QUERY", INT2FIX(PG_DIAG_INTERNAL_QUERY));
|
|
590
|
-
/* #result_error_field argument constant
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
603
|
+
/* Result#result_error_field argument constant
|
|
604
|
+
*
|
|
605
|
+
* An indication of the context in which the error occurred.
|
|
606
|
+
* Presently this includes a call stack traceback of active procedural language functions and internally-generated queries.
|
|
607
|
+
* The trace is one entry per line, most recent first.
|
|
594
608
|
*/
|
|
595
|
-
|
|
596
609
|
rb_define_const(rb_mPGconstants, "PG_DIAG_CONTEXT", INT2FIX(PG_DIAG_CONTEXT));
|
|
597
|
-
/* #result_error_field argument constant
|
|
598
|
-
*
|
|
610
|
+
/* Result#result_error_field argument constant
|
|
611
|
+
*
|
|
612
|
+
* The file name of the source-code location where the error was reported. */
|
|
599
613
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FILE", INT2FIX(PG_DIAG_SOURCE_FILE));
|
|
600
614
|
|
|
601
|
-
/* #result_error_field argument constant
|
|
602
|
-
*
|
|
615
|
+
/* Result#result_error_field argument constant
|
|
616
|
+
*
|
|
617
|
+
* The line number of the source-code location where the error was reported. */
|
|
603
618
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_LINE", INT2FIX(PG_DIAG_SOURCE_LINE));
|
|
604
619
|
|
|
605
|
-
/* #result_error_field argument constant
|
|
606
|
-
*
|
|
620
|
+
/* Result#result_error_field argument constant
|
|
621
|
+
*
|
|
622
|
+
* The name of the source-code function reporting the error. */
|
|
607
623
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FUNCTION", INT2FIX(PG_DIAG_SOURCE_FUNCTION));
|
|
608
624
|
|
|
609
|
-
#ifdef
|
|
610
|
-
/* #result_error_field argument constant
|
|
611
|
-
*
|
|
625
|
+
#ifdef PG_DIAG_TABLE_NAME
|
|
626
|
+
/* Result#result_error_field argument constant
|
|
627
|
+
*
|
|
628
|
+
* If the error was associated with a specific database object, the name of the schema containing that object, if any. */
|
|
612
629
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SCHEMA_NAME", INT2FIX(PG_DIAG_SCHEMA_NAME));
|
|
613
630
|
|
|
614
|
-
/* #result_error_field argument constant
|
|
615
|
-
*
|
|
616
|
-
*
|
|
631
|
+
/* Result#result_error_field argument constant
|
|
632
|
+
*
|
|
633
|
+
* If the error was associated with a specific table, the name of the table.
|
|
634
|
+
* (When this field is present, the schema name field provides the name of the table's schema.) */
|
|
617
635
|
rb_define_const(rb_mPGconstants, "PG_DIAG_TABLE_NAME", INT2FIX(PG_DIAG_TABLE_NAME));
|
|
618
636
|
|
|
619
|
-
/* #result_error_field argument constant
|
|
620
|
-
*
|
|
621
|
-
*
|
|
637
|
+
/* Result#result_error_field argument constant
|
|
638
|
+
*
|
|
639
|
+
* If the error was associated with a specific table column, the name of the column.
|
|
640
|
+
* (When this field is present, the schema and table name fields identify the table.) */
|
|
622
641
|
rb_define_const(rb_mPGconstants, "PG_DIAG_COLUMN_NAME", INT2FIX(PG_DIAG_COLUMN_NAME));
|
|
623
642
|
|
|
624
|
-
/* #result_error_field argument constant
|
|
625
|
-
*
|
|
626
|
-
*
|
|
643
|
+
/* Result#result_error_field argument constant
|
|
644
|
+
*
|
|
645
|
+
* If the error was associated with a specific datatype, the name of the datatype.
|
|
646
|
+
* (When this field is present, the schema name field provides the name of the datatype's schema.) */
|
|
627
647
|
rb_define_const(rb_mPGconstants, "PG_DIAG_DATATYPE_NAME", INT2FIX(PG_DIAG_DATATYPE_NAME));
|
|
628
648
|
|
|
629
|
-
/* #result_error_field argument constant
|
|
630
|
-
*
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
* constraint syntax.) */
|
|
649
|
+
/* Result#result_error_field argument constant
|
|
650
|
+
*
|
|
651
|
+
* If the error was associated with a specific constraint, the name of the constraint.
|
|
652
|
+
* The table or domain that the constraint belongs to is reported using the fields listed above.
|
|
653
|
+
* (For this purpose, indexes are treated as constraints, even if they weren't created with constraint syntax.) */
|
|
634
654
|
rb_define_const(rb_mPGconstants, "PG_DIAG_CONSTRAINT_NAME", INT2FIX(PG_DIAG_CONSTRAINT_NAME));
|
|
635
655
|
#endif
|
|
636
656
|
|
|
657
|
+
#ifdef HAVE_PQENTERPIPELINEMODE
|
|
658
|
+
/* Connection#pipeline_status constant
|
|
659
|
+
*
|
|
660
|
+
* The libpq connection is in pipeline mode.
|
|
661
|
+
*/
|
|
662
|
+
rb_define_const(rb_mPGconstants, "PQ_PIPELINE_ON", INT2FIX(PQ_PIPELINE_ON));
|
|
663
|
+
|
|
664
|
+
/* Connection#pipeline_status constant
|
|
665
|
+
*
|
|
666
|
+
* The libpq connection is not in pipeline mode.
|
|
667
|
+
*/
|
|
668
|
+
rb_define_const(rb_mPGconstants, "PQ_PIPELINE_OFF", INT2FIX(PQ_PIPELINE_OFF));
|
|
669
|
+
|
|
670
|
+
/* Connection#pipeline_status constant
|
|
671
|
+
*
|
|
672
|
+
* The libpq connection is in pipeline mode and an error occurred while processing the current pipeline.
|
|
673
|
+
* The aborted flag is cleared when PQgetResult returns a result of type PGRES_PIPELINE_SYNC.
|
|
674
|
+
*/
|
|
675
|
+
rb_define_const(rb_mPGconstants, "PQ_PIPELINE_ABORTED", INT2FIX(PQ_PIPELINE_ABORTED));
|
|
676
|
+
#endif
|
|
677
|
+
|
|
637
678
|
/* Invalid OID constant */
|
|
638
679
|
rb_define_const(rb_mPGconstants, "INVALID_OID", INT2FIX(InvalidOid));
|
|
639
680
|
rb_define_const(rb_mPGconstants, "InvalidOid", INT2FIX(InvalidOid));
|
|
640
681
|
|
|
682
|
+
/* PostgreSQL compiled in default port */
|
|
683
|
+
rb_define_const(rb_mPGconstants, "DEF_PGPORT", INT2FIX(DEF_PGPORT));
|
|
684
|
+
|
|
641
685
|
/* Add the constants to the toplevel namespace */
|
|
642
686
|
rb_include_module( rb_mPG, rb_mPGconstants );
|
|
643
687
|
|
|
644
|
-
#ifdef M17N_SUPPORTED
|
|
645
688
|
enc_pg2ruby = st_init_numtable();
|
|
646
|
-
#endif
|
|
647
689
|
|
|
648
690
|
/* Initialize the main extension classes */
|
|
649
691
|
init_pg_connection();
|
|
@@ -662,5 +704,7 @@ Init_pg_ext()
|
|
|
662
704
|
init_pg_binary_encoder();
|
|
663
705
|
init_pg_binary_decoder();
|
|
664
706
|
init_pg_copycoder();
|
|
707
|
+
init_pg_recordcoder();
|
|
708
|
+
init_pg_tuple();
|
|
665
709
|
}
|
|
666
710
|
|