pg 0.17.1 → 1.2.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.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/BSDL +2 -2
- data/ChangeLog +0 -3506
- data/History.rdoc +308 -0
- data/Manifest.txt +35 -19
- data/README-Windows.rdoc +17 -28
- data/README.ja.rdoc +1 -2
- data/README.rdoc +113 -14
- data/Rakefile +67 -30
- data/Rakefile.cross +109 -83
- data/ext/errorcodes.def +101 -0
- data/ext/errorcodes.rb +1 -1
- data/ext/errorcodes.txt +33 -2
- data/ext/extconf.rb +55 -58
- data/ext/gvl_wrappers.c +4 -0
- data/ext/gvl_wrappers.h +27 -39
- data/ext/pg.c +262 -130
- data/ext/pg.h +266 -54
- data/ext/pg_binary_decoder.c +229 -0
- data/ext/pg_binary_encoder.c +163 -0
- data/ext/pg_coder.c +561 -0
- data/ext/pg_connection.c +1689 -990
- data/ext/pg_copy_coder.c +599 -0
- data/ext/pg_errors.c +6 -0
- data/ext/pg_record_coder.c +491 -0
- data/ext/pg_result.c +897 -164
- data/ext/pg_text_decoder.c +987 -0
- data/ext/pg_text_encoder.c +814 -0
- data/ext/pg_tuple.c +549 -0
- data/ext/pg_type_map.c +166 -0
- data/ext/pg_type_map_all_strings.c +116 -0
- data/ext/pg_type_map_by_class.c +244 -0
- data/ext/pg_type_map_by_column.c +313 -0
- data/ext/pg_type_map_by_mri_type.c +284 -0
- data/ext/pg_type_map_by_oid.c +356 -0
- data/ext/pg_type_map_in_ruby.c +299 -0
- data/ext/pg_util.c +149 -0
- data/ext/pg_util.h +65 -0
- data/lib/pg/basic_type_mapping.rb +522 -0
- data/lib/pg/binary_decoder.rb +23 -0
- data/lib/pg/coder.rb +104 -0
- data/lib/pg/connection.rb +153 -41
- data/lib/pg/constants.rb +2 -1
- data/lib/pg/exceptions.rb +2 -1
- data/lib/pg/result.rb +33 -6
- data/lib/pg/text_decoder.rb +46 -0
- data/lib/pg/text_encoder.rb +59 -0
- data/lib/pg/tuple.rb +30 -0
- data/lib/pg/type_map_by_column.rb +16 -0
- data/lib/pg.rb +29 -9
- data/spec/{lib/helpers.rb → helpers.rb} +151 -64
- data/spec/pg/basic_type_mapping_spec.rb +630 -0
- data/spec/pg/connection_spec.rb +1180 -477
- data/spec/pg/connection_sync_spec.rb +41 -0
- data/spec/pg/result_spec.rb +456 -120
- data/spec/pg/tuple_spec.rb +333 -0
- data/spec/pg/type_map_by_class_spec.rb +138 -0
- data/spec/pg/type_map_by_column_spec.rb +226 -0
- data/spec/pg/type_map_by_mri_type_spec.rb +136 -0
- data/spec/pg/type_map_by_oid_spec.rb +149 -0
- data/spec/pg/type_map_in_ruby_spec.rb +164 -0
- data/spec/pg/type_map_spec.rb +22 -0
- data/spec/pg/type_spec.rb +1123 -0
- data/spec/pg_spec.rb +26 -20
- data.tar.gz.sig +0 -0
- metadata +148 -91
- metadata.gz.sig +0 -0
- data/sample/array_insert.rb +0 -20
- data/sample/async_api.rb +0 -106
- data/sample/async_copyto.rb +0 -39
- data/sample/async_mixed.rb +0 -56
- data/sample/check_conn.rb +0 -21
- data/sample/copyfrom.rb +0 -81
- data/sample/copyto.rb +0 -19
- data/sample/cursor.rb +0 -21
- data/sample/disk_usage_report.rb +0 -186
- data/sample/issue-119.rb +0 -94
- data/sample/losample.rb +0 -69
- data/sample/minimal-testcase.rb +0 -17
- data/sample/notify_wait.rb +0 -72
- data/sample/pg_statistics.rb +0 -294
- data/sample/replication_monitor.rb +0 -231
- data/sample/test_binary_values.rb +0 -33
- data/sample/wal_shipper.rb +0 -434
- data/sample/warehouse_partitions.rb +0 -320
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
|
*/
|
@@ -123,24 +124,6 @@ const char * const (pg_enc_pg2ruby_mapping[][2]) = {
|
|
123
124
|
* A cache of mapping from PostgreSQL's encoding indices to Ruby's rb_encoding*s.
|
124
125
|
*/
|
125
126
|
static struct st_table *enc_pg2ruby;
|
126
|
-
static ID s_id_index;
|
127
|
-
|
128
|
-
|
129
|
-
/*
|
130
|
-
* Get the index of encoding +val+.
|
131
|
-
* :FIXME: Look into replacing this with rb_enc_get_index() since 1.9.1 isn't really
|
132
|
-
* used anymore.
|
133
|
-
*/
|
134
|
-
int
|
135
|
-
pg_enc_get_index(VALUE val)
|
136
|
-
{
|
137
|
-
int i = ENCODING_GET_INLINED(val);
|
138
|
-
if (i == ENCODING_INLINE_MAX) {
|
139
|
-
VALUE iv = rb_ivar_get(val, s_id_index);
|
140
|
-
i = NUM2INT(iv);
|
141
|
-
}
|
142
|
-
return i;
|
143
|
-
}
|
144
127
|
|
145
128
|
|
146
129
|
/*
|
@@ -160,9 +143,6 @@ pg_find_or_create_johab(void)
|
|
160
143
|
}
|
161
144
|
|
162
145
|
enc_index = rb_define_dummy_encoding(aliases[0]);
|
163
|
-
for (i = 1; i < sizeof(aliases)/sizeof(aliases[0]); ++i) {
|
164
|
-
ENC_ALIAS(aliases[i], aliases[0]);
|
165
|
-
}
|
166
146
|
return rb_enc_from_index(enc_index);
|
167
147
|
}
|
168
148
|
|
@@ -246,14 +226,55 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
|
|
246
226
|
return encname;
|
247
227
|
}
|
248
228
|
|
249
|
-
|
229
|
+
|
230
|
+
/*
|
231
|
+
* Ensures that the given string has enough capacity to take expand_len
|
232
|
+
* more data bytes. The new data part of the String is not initialized.
|
233
|
+
*
|
234
|
+
* current_out must be a pointer within the data part of the String object.
|
235
|
+
* This pointer is returned and possibly adjusted, because the location of the data
|
236
|
+
* part of the String can change through this function.
|
237
|
+
*
|
238
|
+
* PG_RB_STR_ENSURE_CAPA can be used to do fast inline checks of the remaining capacity.
|
239
|
+
* end_capa it is then set to the first byte after the currently reserved memory,
|
240
|
+
* if not NULL.
|
241
|
+
*
|
242
|
+
* Before the String can be used with other string functions or returned to Ruby space,
|
243
|
+
* the string length has to be set with rb_str_set_len().
|
244
|
+
*
|
245
|
+
* Usage example:
|
246
|
+
*
|
247
|
+
* VALUE string;
|
248
|
+
* char *current_out, *end_capa;
|
249
|
+
* PG_RB_STR_NEW( string, current_out, end_capa );
|
250
|
+
* while( data_is_going_to_be_processed ){
|
251
|
+
* PG_RB_STR_ENSURE_CAPA( string, 2, current_out, end_capa );
|
252
|
+
* *current_out++ = databyte1;
|
253
|
+
* *current_out++ = databyte2;
|
254
|
+
* }
|
255
|
+
* rb_str_set_len( string, current_out - RSTRING_PTR(string) );
|
256
|
+
*
|
257
|
+
*/
|
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;
|
267
|
+
}
|
268
|
+
if( end_ptr )
|
269
|
+
*end_ptr = RSTRING_PTR(str) + rb_str_capacity( str );
|
270
|
+
return curr_ptr;
|
271
|
+
}
|
250
272
|
|
251
273
|
|
252
274
|
/**************************************************************************
|
253
275
|
* Module Methods
|
254
276
|
**************************************************************************/
|
255
277
|
|
256
|
-
#ifdef HAVE_PQLIBVERSION
|
257
278
|
/*
|
258
279
|
* call-seq:
|
259
280
|
* PG.library_version -> Integer
|
@@ -271,7 +292,6 @@ pg_s_library_version(VALUE self)
|
|
271
292
|
UNUSED( self );
|
272
293
|
return INT2NUM(PQlibVersion());
|
273
294
|
}
|
274
|
-
#endif
|
275
295
|
|
276
296
|
|
277
297
|
/*
|
@@ -289,6 +309,66 @@ pg_s_threadsafe_p(VALUE self)
|
|
289
309
|
return PQisthreadsafe() ? Qtrue : Qfalse;
|
290
310
|
}
|
291
311
|
|
312
|
+
static int
|
313
|
+
pg_to_bool_int(VALUE value)
|
314
|
+
{
|
315
|
+
switch( TYPE(value) ){
|
316
|
+
case T_FALSE:
|
317
|
+
return 0;
|
318
|
+
case T_TRUE:
|
319
|
+
return 1;
|
320
|
+
default:
|
321
|
+
return NUM2INT(value);
|
322
|
+
}
|
323
|
+
}
|
324
|
+
|
325
|
+
/*
|
326
|
+
* call-seq:
|
327
|
+
* PG.init_openssl(do_ssl, do_crypto) -> nil
|
328
|
+
*
|
329
|
+
* Allows applications to select which security libraries to initialize.
|
330
|
+
*
|
331
|
+
* If your application initializes libssl and/or libcrypto libraries and libpq is
|
332
|
+
* built with SSL support, you should call PG.init_openssl() to tell libpq that the
|
333
|
+
* libssl and/or libcrypto libraries have been initialized by your application,
|
334
|
+
* so that libpq will not also initialize those libraries.
|
335
|
+
*
|
336
|
+
* When do_ssl is +true+, libpq will initialize the OpenSSL library before first
|
337
|
+
* opening a database connection. When do_crypto is +true+, the libcrypto library
|
338
|
+
* will be initialized. By default (if PG.init_openssl() is not called), both libraries
|
339
|
+
* are initialized. When SSL support is not compiled in, this function is present but does nothing.
|
340
|
+
*
|
341
|
+
* If your application uses and initializes either OpenSSL or its underlying libcrypto library,
|
342
|
+
* you must call this function with +false+ for the appropriate parameter(s) before first opening
|
343
|
+
* a database connection. Also be sure that you have done that initialization before opening a
|
344
|
+
* database connection.
|
345
|
+
*
|
346
|
+
*/
|
347
|
+
static VALUE
|
348
|
+
pg_s_init_openssl(VALUE self, VALUE do_ssl, VALUE do_crypto)
|
349
|
+
{
|
350
|
+
UNUSED( self );
|
351
|
+
PQinitOpenSSL(pg_to_bool_int(do_ssl), pg_to_bool_int(do_crypto));
|
352
|
+
return Qnil;
|
353
|
+
}
|
354
|
+
|
355
|
+
|
356
|
+
/*
|
357
|
+
* call-seq:
|
358
|
+
* PG.init_ssl(do_ssl) -> nil
|
359
|
+
*
|
360
|
+
* Allows applications to select which security libraries to initialize.
|
361
|
+
*
|
362
|
+
* This function is equivalent to <tt>PG.init_openssl(do_ssl, do_ssl)</tt> . It is sufficient for
|
363
|
+
* applications that initialize both or neither of OpenSSL and libcrypto.
|
364
|
+
*/
|
365
|
+
static VALUE
|
366
|
+
pg_s_init_ssl(VALUE self, VALUE do_ssl)
|
367
|
+
{
|
368
|
+
UNUSED( self );
|
369
|
+
PQinitSSL(pg_to_bool_int(do_ssl));
|
370
|
+
return Qnil;
|
371
|
+
}
|
292
372
|
|
293
373
|
|
294
374
|
/**************************************************************************
|
@@ -298,19 +378,28 @@ pg_s_threadsafe_p(VALUE self)
|
|
298
378
|
void
|
299
379
|
Init_pg_ext()
|
300
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
|
+
|
301
388
|
rb_mPG = rb_define_module( "PG" );
|
302
389
|
rb_mPGconstants = rb_define_module_under( rb_mPG, "Constants" );
|
303
390
|
|
304
391
|
/*************************
|
305
392
|
* PG module methods
|
306
393
|
*************************/
|
307
|
-
#ifdef HAVE_PQLIBVERSION
|
308
394
|
rb_define_singleton_method( rb_mPG, "library_version", pg_s_library_version, 0 );
|
309
|
-
#endif
|
310
395
|
rb_define_singleton_method( rb_mPG, "isthreadsafe", pg_s_threadsafe_p, 0 );
|
311
396
|
SINGLETON_ALIAS( rb_mPG, "is_threadsafe?", "isthreadsafe" );
|
312
397
|
SINGLETON_ALIAS( rb_mPG, "threadsafe?", "isthreadsafe" );
|
313
398
|
|
399
|
+
rb_define_singleton_method( rb_mPG, "init_openssl", pg_s_init_openssl, 2 );
|
400
|
+
rb_define_singleton_method( rb_mPG, "init_ssl", pg_s_init_ssl, 1 );
|
401
|
+
|
402
|
+
|
314
403
|
/****** PG::Connection CLASS CONSTANTS: Connection Status ******/
|
315
404
|
|
316
405
|
/* Connection succeeded */
|
@@ -332,7 +421,7 @@ Init_pg_ext()
|
|
332
421
|
rb_define_const(rb_mPGconstants, "CONNECTION_SSL_STARTUP", INT2FIX(CONNECTION_SSL_STARTUP));
|
333
422
|
/* Negotiating environment-driven parameter settings. */
|
334
423
|
rb_define_const(rb_mPGconstants, "CONNECTION_SETENV", INT2FIX(CONNECTION_SETENV));
|
335
|
-
/* Internal state
|
424
|
+
/* Internal state - PG.connect() needed. */
|
336
425
|
rb_define_const(rb_mPGconstants, "CONNECTION_NEEDED", INT2FIX(CONNECTION_NEEDED));
|
337
426
|
|
338
427
|
/****** PG::Connection CLASS CONSTANTS: Nonblocking connection polling status ******/
|
@@ -348,27 +437,48 @@ Init_pg_ext()
|
|
348
437
|
|
349
438
|
/****** PG::Connection CLASS CONSTANTS: Transaction Status ******/
|
350
439
|
|
351
|
-
/* Transaction is currently idle (#transaction_status) */
|
440
|
+
/* Transaction is currently idle ( Connection#transaction_status ) */
|
352
441
|
rb_define_const(rb_mPGconstants, "PQTRANS_IDLE", INT2FIX(PQTRANS_IDLE));
|
353
|
-
/* 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 ) */
|
354
443
|
rb_define_const(rb_mPGconstants, "PQTRANS_ACTIVE", INT2FIX(PQTRANS_ACTIVE));
|
355
|
-
/* Transaction is currently idle, in a valid transaction block (#transaction_status) */
|
444
|
+
/* Transaction is currently idle, in a valid transaction block ( Connection#transaction_status ) */
|
356
445
|
rb_define_const(rb_mPGconstants, "PQTRANS_INTRANS", INT2FIX(PQTRANS_INTRANS));
|
357
|
-
/* Transaction is currently idle, in a failed transaction block (#transaction_status) */
|
446
|
+
/* Transaction is currently idle, in a failed transaction block ( Connection#transaction_status ) */
|
358
447
|
rb_define_const(rb_mPGconstants, "PQTRANS_INERROR", INT2FIX(PQTRANS_INERROR));
|
359
|
-
/* Transaction's connection is bad (#transaction_status) */
|
448
|
+
/* Transaction's connection is bad ( Connection#transaction_status ) */
|
360
449
|
rb_define_const(rb_mPGconstants, "PQTRANS_UNKNOWN", INT2FIX(PQTRANS_UNKNOWN));
|
361
450
|
|
362
451
|
/****** PG::Connection CLASS CONSTANTS: Error Verbosity ******/
|
363
452
|
|
364
|
-
/*
|
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. */
|
365
455
|
rb_define_const(rb_mPGconstants, "PQERRORS_TERSE", INT2FIX(PQERRORS_TERSE));
|
366
|
-
/*
|
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). */
|
367
458
|
rb_define_const(rb_mPGconstants, "PQERRORS_DEFAULT", INT2FIX(PQERRORS_DEFAULT));
|
368
|
-
/*
|
459
|
+
/* Error verbosity level ( Connection#set_error_verbosity ).
|
460
|
+
* The VERBOSE mode includes all available fields. */
|
369
461
|
rb_define_const(rb_mPGconstants, "PQERRORS_VERBOSE", INT2FIX(PQERRORS_VERBOSE));
|
370
462
|
|
371
|
-
|
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
|
+
|
372
482
|
/****** PG::Connection CLASS CONSTANTS: Check Server Status ******/
|
373
483
|
|
374
484
|
/* Server is accepting connections. */
|
@@ -379,149 +489,159 @@ Init_pg_ext()
|
|
379
489
|
rb_define_const(rb_mPGconstants, "PQPING_NO_RESPONSE", INT2FIX(PQPING_NO_RESPONSE));
|
380
490
|
/* Connection not attempted (bad params). */
|
381
491
|
rb_define_const(rb_mPGconstants, "PQPING_NO_ATTEMPT", INT2FIX(PQPING_NO_ATTEMPT));
|
382
|
-
#endif
|
383
492
|
|
384
493
|
/****** PG::Connection CLASS CONSTANTS: Large Objects ******/
|
385
494
|
|
386
|
-
/* Flag for #lo_creat, #lo_open -- open for writing */
|
495
|
+
/* Flag for Connection#lo_creat, Connection#lo_open -- open for writing */
|
387
496
|
rb_define_const(rb_mPGconstants, "INV_WRITE", INT2FIX(INV_WRITE));
|
388
|
-
/* Flag for #lo_creat, #lo_open -- open for reading */
|
497
|
+
/* Flag for Connection#lo_creat, Connection#lo_open -- open for reading */
|
389
498
|
rb_define_const(rb_mPGconstants, "INV_READ", INT2FIX(INV_READ));
|
390
|
-
/* Flag for #lo_lseek -- seek from object start */
|
499
|
+
/* Flag for Connection#lo_lseek -- seek from object start */
|
391
500
|
rb_define_const(rb_mPGconstants, "SEEK_SET", INT2FIX(SEEK_SET));
|
392
|
-
/* Flag for #lo_lseek -- seek from current position */
|
501
|
+
/* Flag for Connection#lo_lseek -- seek from current position */
|
393
502
|
rb_define_const(rb_mPGconstants, "SEEK_CUR", INT2FIX(SEEK_CUR));
|
394
|
-
/* Flag for #lo_lseek -- seek from object end */
|
503
|
+
/* Flag for Connection#lo_lseek -- seek from object end */
|
395
504
|
rb_define_const(rb_mPGconstants, "SEEK_END", INT2FIX(SEEK_END));
|
396
505
|
|
397
506
|
/****** PG::Result CONSTANTS: result status ******/
|
398
507
|
|
399
|
-
/* #result_status constant
|
508
|
+
/* Result#result_status constant - The string sent to the server was empty. */
|
400
509
|
rb_define_const(rb_mPGconstants, "PGRES_EMPTY_QUERY", INT2FIX(PGRES_EMPTY_QUERY));
|
401
|
-
/* #result_status constant
|
510
|
+
/* Result#result_status constant - Successful completion of a command returning no data. */
|
402
511
|
rb_define_const(rb_mPGconstants, "PGRES_COMMAND_OK", INT2FIX(PGRES_COMMAND_OK));
|
403
|
-
|
404
|
-
(such as a SELECT or SHOW). */
|
512
|
+
/* Result#result_status constant - Successful completion of a command returning data (such as a SELECT or SHOW). */
|
405
513
|
rb_define_const(rb_mPGconstants, "PGRES_TUPLES_OK", INT2FIX(PGRES_TUPLES_OK));
|
406
|
-
/* #result_status constant
|
514
|
+
/* Result#result_status constant - Copy Out (from server) data transfer started. */
|
407
515
|
rb_define_const(rb_mPGconstants, "PGRES_COPY_OUT", INT2FIX(PGRES_COPY_OUT));
|
408
|
-
/* #result_status constant
|
516
|
+
/* Result#result_status constant - Copy In (to server) data transfer started. */
|
409
517
|
rb_define_const(rb_mPGconstants, "PGRES_COPY_IN", INT2FIX(PGRES_COPY_IN));
|
410
|
-
/* #result_status constant
|
518
|
+
/* Result#result_status constant - The server’s response was not understood. */
|
411
519
|
rb_define_const(rb_mPGconstants, "PGRES_BAD_RESPONSE", INT2FIX(PGRES_BAD_RESPONSE));
|
412
|
-
/* #result_status constant
|
520
|
+
/* Result#result_status constant - A nonfatal error (a notice or warning) occurred. */
|
413
521
|
rb_define_const(rb_mPGconstants, "PGRES_NONFATAL_ERROR",INT2FIX(PGRES_NONFATAL_ERROR));
|
414
|
-
/* #result_status constant
|
522
|
+
/* Result#result_status constant - A fatal error occurred. */
|
415
523
|
rb_define_const(rb_mPGconstants, "PGRES_FATAL_ERROR", INT2FIX(PGRES_FATAL_ERROR));
|
416
|
-
/* #result_status constant
|
417
|
-
#ifdef HAVE_CONST_PGRES_COPY_BOTH
|
524
|
+
/* Result#result_status constant - Copy In/Out data transfer in progress. */
|
418
525
|
rb_define_const(rb_mPGconstants, "PGRES_COPY_BOTH", INT2FIX(PGRES_COPY_BOTH));
|
419
|
-
#
|
420
|
-
/* #result_status constant: Single tuple from larger resultset. */
|
421
|
-
#ifdef HAVE_CONST_PGRES_SINGLE_TUPLE
|
526
|
+
/* Result#result_status constant - Single tuple from larger resultset. */
|
422
527
|
rb_define_const(rb_mPGconstants, "PGRES_SINGLE_TUPLE", INT2FIX(PGRES_SINGLE_TUPLE));
|
423
|
-
#endif
|
424
528
|
|
425
529
|
/****** Result CONSTANTS: result error field codes ******/
|
426
530
|
|
427
|
-
/* #result_error_field argument constant
|
428
|
-
*
|
429
|
-
* DEBUG, INFO, or LOG (in a notice message), or a localized translation
|
430
|
-
* of one of these.
|
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.
|
431
536
|
*/
|
432
537
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY", INT2FIX(PG_DIAG_SEVERITY));
|
433
538
|
|
434
|
-
|
435
|
-
|
436
|
-
*
|
437
|
-
*
|
438
|
-
*
|
439
|
-
*
|
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.
|
440
555
|
*/
|
441
556
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SQLSTATE", INT2FIX(PG_DIAG_SQLSTATE));
|
442
|
-
|
443
|
-
|
444
|
-
* error message (typically one line).
|
557
|
+
/* Result#result_error_field argument constant
|
558
|
+
*
|
559
|
+
* The primary human-readable error message (typically one line).
|
560
|
+
* Always present. */
|
445
561
|
rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_PRIMARY", INT2FIX(PG_DIAG_MESSAGE_PRIMARY));
|
446
|
-
|
447
|
-
|
448
|
-
* error message carrying more detail about the problem.
|
449
|
-
* 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.
|
450
566
|
*/
|
451
567
|
rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_DETAIL", INT2FIX(PG_DIAG_MESSAGE_DETAIL));
|
452
|
-
|
453
|
-
|
454
|
-
* what to do about the problem.
|
455
|
-
* in that it offers advice (potentially inappropriate) rather than
|
456
|
-
*
|
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.
|
457
573
|
*/
|
458
|
-
|
459
574
|
rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_HINT", INT2FIX(PG_DIAG_MESSAGE_HINT));
|
460
|
-
/* #result_error_field argument constant
|
461
|
-
*
|
462
|
-
*
|
463
|
-
*
|
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.
|
464
580
|
*/
|
465
|
-
|
466
581
|
rb_define_const(rb_mPGconstants, "PG_DIAG_STATEMENT_POSITION", INT2FIX(PG_DIAG_STATEMENT_POSITION));
|
467
|
-
/* #result_error_field argument constant
|
468
|
-
*
|
469
|
-
* position refers to an internally generated command rather than the
|
470
|
-
*
|
471
|
-
* 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.
|
472
586
|
*/
|
473
|
-
|
474
587
|
rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_POSITION", INT2FIX(PG_DIAG_INTERNAL_POSITION));
|
475
|
-
/* #result_error_field argument constant
|
476
|
-
*
|
477
|
-
*
|
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.
|
478
592
|
*/
|
479
|
-
|
480
593
|
rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_QUERY", INT2FIX(PG_DIAG_INTERNAL_QUERY));
|
481
|
-
/* #result_error_field argument constant
|
482
|
-
*
|
483
|
-
*
|
484
|
-
*
|
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.
|
485
599
|
*/
|
486
|
-
|
487
600
|
rb_define_const(rb_mPGconstants, "PG_DIAG_CONTEXT", INT2FIX(PG_DIAG_CONTEXT));
|
488
|
-
/* #result_error_field argument constant
|
489
|
-
*
|
601
|
+
/* Result#result_error_field argument constant
|
602
|
+
*
|
603
|
+
* The file name of the source-code location where the error was reported. */
|
490
604
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FILE", INT2FIX(PG_DIAG_SOURCE_FILE));
|
491
605
|
|
492
|
-
/* #result_error_field argument constant
|
493
|
-
*
|
606
|
+
/* Result#result_error_field argument constant
|
607
|
+
*
|
608
|
+
* The line number of the source-code location where the error was reported. */
|
494
609
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_LINE", INT2FIX(PG_DIAG_SOURCE_LINE));
|
495
610
|
|
496
|
-
/* #result_error_field argument constant
|
497
|
-
*
|
611
|
+
/* Result#result_error_field argument constant
|
612
|
+
*
|
613
|
+
* The name of the source-code function reporting the error. */
|
498
614
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FUNCTION", INT2FIX(PG_DIAG_SOURCE_FUNCTION));
|
499
615
|
|
500
|
-
#ifdef
|
501
|
-
/* #result_error_field argument constant
|
502
|
-
*
|
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. */
|
503
620
|
rb_define_const(rb_mPGconstants, "PG_DIAG_SCHEMA_NAME", INT2FIX(PG_DIAG_SCHEMA_NAME));
|
504
621
|
|
505
|
-
/* #result_error_field argument constant
|
506
|
-
*
|
507
|
-
*
|
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.) */
|
508
626
|
rb_define_const(rb_mPGconstants, "PG_DIAG_TABLE_NAME", INT2FIX(PG_DIAG_TABLE_NAME));
|
509
627
|
|
510
|
-
/* #result_error_field argument constant
|
511
|
-
*
|
512
|
-
*
|
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.) */
|
513
632
|
rb_define_const(rb_mPGconstants, "PG_DIAG_COLUMN_NAME", INT2FIX(PG_DIAG_COLUMN_NAME));
|
514
633
|
|
515
|
-
/* #result_error_field argument constant
|
516
|
-
*
|
517
|
-
*
|
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.) */
|
518
638
|
rb_define_const(rb_mPGconstants, "PG_DIAG_DATATYPE_NAME", INT2FIX(PG_DIAG_DATATYPE_NAME));
|
519
639
|
|
520
|
-
/* #result_error_field argument constant
|
521
|
-
*
|
522
|
-
*
|
523
|
-
*
|
524
|
-
* 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.) */
|
525
645
|
rb_define_const(rb_mPGconstants, "PG_DIAG_CONSTRAINT_NAME", INT2FIX(PG_DIAG_CONSTRAINT_NAME));
|
526
646
|
#endif
|
527
647
|
|
@@ -532,14 +652,26 @@ Init_pg_ext()
|
|
532
652
|
/* Add the constants to the toplevel namespace */
|
533
653
|
rb_include_module( rb_mPG, rb_mPGconstants );
|
534
654
|
|
535
|
-
#ifdef M17N_SUPPORTED
|
536
655
|
enc_pg2ruby = st_init_numtable();
|
537
|
-
s_id_index = rb_intern("@encoding");
|
538
|
-
#endif
|
539
656
|
|
540
657
|
/* Initialize the main extension classes */
|
541
658
|
init_pg_connection();
|
542
659
|
init_pg_result();
|
543
660
|
init_pg_errors();
|
661
|
+
init_pg_type_map();
|
662
|
+
init_pg_type_map_all_strings();
|
663
|
+
init_pg_type_map_by_class();
|
664
|
+
init_pg_type_map_by_column();
|
665
|
+
init_pg_type_map_by_mri_type();
|
666
|
+
init_pg_type_map_by_oid();
|
667
|
+
init_pg_type_map_in_ruby();
|
668
|
+
init_pg_coder();
|
669
|
+
init_pg_text_encoder();
|
670
|
+
init_pg_text_decoder();
|
671
|
+
init_pg_binary_encoder();
|
672
|
+
init_pg_binary_decoder();
|
673
|
+
init_pg_copycoder();
|
674
|
+
init_pg_recordcoder();
|
675
|
+
init_pg_tuple();
|
544
676
|
}
|
545
677
|
|