pg 0.18.0 → 1.0.0
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 +1221 -4
- data/History.rdoc +130 -0
- data/Manifest.txt +0 -18
- data/README-Windows.rdoc +15 -26
- data/README.rdoc +16 -10
- data/Rakefile +32 -23
- data/Rakefile.cross +56 -38
- data/ext/errorcodes.def +33 -0
- data/ext/errorcodes.txt +15 -1
- data/ext/extconf.rb +27 -35
- data/ext/gvl_wrappers.c +4 -0
- data/ext/gvl_wrappers.h +27 -39
- data/ext/pg.c +19 -51
- data/ext/pg.h +22 -79
- data/ext/pg_binary_decoder.c +3 -1
- data/ext/pg_binary_encoder.c +14 -12
- data/ext/pg_coder.c +31 -10
- data/ext/pg_connection.c +350 -263
- data/ext/pg_copy_coder.c +34 -4
- data/ext/pg_result.c +27 -25
- data/ext/pg_text_decoder.c +9 -10
- data/ext/pg_text_encoder.c +93 -73
- data/ext/pg_type_map.c +20 -13
- data/ext/pg_type_map_by_column.c +7 -7
- data/ext/pg_type_map_by_mri_type.c +2 -2
- data/ext/pg_type_map_in_ruby.c +4 -7
- data/ext/util.c +3 -3
- data/ext/util.h +1 -1
- data/lib/pg/basic_type_mapping.rb +69 -42
- data/lib/pg/connection.rb +89 -38
- data/lib/pg/result.rb +10 -5
- data/lib/pg/text_decoder.rb +12 -3
- data/lib/pg/text_encoder.rb +8 -0
- data/lib/pg.rb +18 -10
- data/spec/helpers.rb +9 -16
- data/spec/pg/basic_type_mapping_spec.rb +58 -4
- data/spec/pg/connection_spec.rb +477 -217
- data/spec/pg/result_spec.rb +14 -7
- data/spec/pg/type_map_by_class_spec.rb +2 -2
- data/spec/pg/type_map_by_mri_type_spec.rb +1 -1
- data/spec/pg/type_spec.rb +145 -33
- data/spec/pg_spec.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +67 -66
- 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/errorcodes.def
CHANGED
@@ -198,6 +198,14 @@
|
|
198
198
|
VALUE klass = define_error_class( "InvalidRowCountInResultOffsetClause", "22" );
|
199
199
|
register_error_class( "2201X", klass );
|
200
200
|
}
|
201
|
+
{
|
202
|
+
VALUE klass = define_error_class( "InvalidTablesampleArgument", "22" );
|
203
|
+
register_error_class( "2202H", klass );
|
204
|
+
}
|
205
|
+
{
|
206
|
+
VALUE klass = define_error_class( "InvalidTablesampleRepeat", "22" );
|
207
|
+
register_error_class( "2202G", klass );
|
208
|
+
}
|
201
209
|
{
|
202
210
|
VALUE klass = define_error_class( "InvalidTimeZoneDisplacementValue", "22" );
|
203
211
|
register_error_class( "22009", klass );
|
@@ -222,6 +230,10 @@
|
|
222
230
|
VALUE klass = define_error_class( "NumericValueOutOfRange", "22" );
|
223
231
|
register_error_class( "22003", klass );
|
224
232
|
}
|
233
|
+
{
|
234
|
+
VALUE klass = define_error_class( "SequenceGeneratorLimitExceeded", "22" );
|
235
|
+
register_error_class( "2200H", klass );
|
236
|
+
}
|
225
237
|
{
|
226
238
|
VALUE klass = define_error_class( "StringDataLengthMismatch", "22" );
|
227
239
|
register_error_class( "22026", klass );
|
@@ -365,6 +377,10 @@
|
|
365
377
|
VALUE klass = define_error_class( "InFailedSqlTransaction", "25" );
|
366
378
|
register_error_class( "25P02", klass );
|
367
379
|
}
|
380
|
+
{
|
381
|
+
VALUE klass = define_error_class( "IdleInTransactionSessionTimeout", "25" );
|
382
|
+
register_error_class( "25P03", klass );
|
383
|
+
}
|
368
384
|
{
|
369
385
|
VALUE klass = define_error_class( "InvalidSqlStatementName", NULL );
|
370
386
|
register_error_class( "26000", klass );
|
@@ -466,6 +482,10 @@
|
|
466
482
|
VALUE klass = define_error_class( "ERIESrfProtocolViolated", "39" );
|
467
483
|
register_error_class( "39P02", klass );
|
468
484
|
}
|
485
|
+
{
|
486
|
+
VALUE klass = define_error_class( "ERIEEventTriggerProtocolViolated", "39" );
|
487
|
+
register_error_class( "39P03", klass );
|
488
|
+
}
|
469
489
|
{
|
470
490
|
VALUE klass = define_error_class( "SavepointException", NULL );
|
471
491
|
register_error_class( "3B000", klass );
|
@@ -571,6 +591,10 @@
|
|
571
591
|
VALUE klass = define_error_class( "WrongObjectType", "42" );
|
572
592
|
register_error_class( "42809", klass );
|
573
593
|
}
|
594
|
+
{
|
595
|
+
VALUE klass = define_error_class( "GeneratedAlways", "42" );
|
596
|
+
register_error_class( "428C9", klass );
|
597
|
+
}
|
574
598
|
{
|
575
599
|
VALUE klass = define_error_class( "UndefinedColumn", "42" );
|
576
600
|
register_error_class( "42703", klass );
|
@@ -781,6 +805,11 @@
|
|
781
805
|
VALUE klass = define_error_class( "DuplicateFile", "58" );
|
782
806
|
register_error_class( "58P02", klass );
|
783
807
|
}
|
808
|
+
{
|
809
|
+
VALUE klass = define_error_class( "SnapshotTooOld", NULL );
|
810
|
+
register_error_class( "72000", klass );
|
811
|
+
register_error_class( "72", klass );
|
812
|
+
}
|
784
813
|
{
|
785
814
|
VALUE klass = define_error_class( "ConfigFileError", NULL );
|
786
815
|
register_error_class( "F0000", klass );
|
@@ -916,6 +945,10 @@
|
|
916
945
|
VALUE klass = define_error_class( "TooManyRows", "P0" );
|
917
946
|
register_error_class( "P0003", klass );
|
918
947
|
}
|
948
|
+
{
|
949
|
+
VALUE klass = define_error_class( "AssertFailure", "P0" );
|
950
|
+
register_error_class( "P0004", klass );
|
951
|
+
}
|
919
952
|
{
|
920
953
|
VALUE klass = define_error_class( "InternalError", NULL );
|
921
954
|
register_error_class( "XX000", klass );
|
data/ext/errorcodes.txt
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# errcodes.txt
|
3
3
|
# PostgreSQL error codes
|
4
4
|
#
|
5
|
-
# Copyright (c) 2003-
|
5
|
+
# Copyright (c) 2003-2017, 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,6 +15,9 @@
|
|
15
15
|
# src/pl/plpgsql/src/plerrcodes.h
|
16
16
|
# a list of PL/pgSQL condition names and their SQLSTATE codes
|
17
17
|
#
|
18
|
+
# src/pl/tcl/pltclerrcodes.h
|
19
|
+
# the same, for PL/Tcl
|
20
|
+
#
|
18
21
|
# doc/src/sgml/errcodes-list.sgml
|
19
22
|
# a SGML table of error codes for inclusion in the documentation
|
20
23
|
#
|
@@ -177,12 +180,15 @@ Section: Class 22 - Data Exception
|
|
177
180
|
2201B E ERRCODE_INVALID_REGULAR_EXPRESSION invalid_regular_expression
|
178
181
|
2201W E ERRCODE_INVALID_ROW_COUNT_IN_LIMIT_CLAUSE invalid_row_count_in_limit_clause
|
179
182
|
2201X E ERRCODE_INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE invalid_row_count_in_result_offset_clause
|
183
|
+
2202H E ERRCODE_INVALID_TABLESAMPLE_ARGUMENT invalid_tablesample_argument
|
184
|
+
2202G E ERRCODE_INVALID_TABLESAMPLE_REPEAT invalid_tablesample_repeat
|
180
185
|
22009 E ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE invalid_time_zone_displacement_value
|
181
186
|
2200C E ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER invalid_use_of_escape_character
|
182
187
|
2200G E ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH most_specific_type_mismatch
|
183
188
|
22004 E ERRCODE_NULL_VALUE_NOT_ALLOWED null_value_not_allowed
|
184
189
|
22002 E ERRCODE_NULL_VALUE_NO_INDICATOR_PARAMETER null_value_no_indicator_parameter
|
185
190
|
22003 E ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE numeric_value_out_of_range
|
191
|
+
2200H E ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED sequence_generator_limit_exceeded
|
186
192
|
22026 E ERRCODE_STRING_DATA_LENGTH_MISMATCH string_data_length_mismatch
|
187
193
|
22001 E ERRCODE_STRING_DATA_RIGHT_TRUNCATION string_data_right_truncation
|
188
194
|
22011 E ERRCODE_SUBSTRING_ERROR substring_error
|
@@ -227,6 +233,7 @@ Section: Class 25 - Invalid Transaction State
|
|
227
233
|
25007 E ERRCODE_SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED schema_and_data_statement_mixing_not_supported
|
228
234
|
25P01 E ERRCODE_NO_ACTIVE_SQL_TRANSACTION no_active_sql_transaction
|
229
235
|
25P02 E ERRCODE_IN_FAILED_SQL_TRANSACTION in_failed_sql_transaction
|
236
|
+
25P03 E ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT idle_in_transaction_session_timeout
|
230
237
|
|
231
238
|
Section: Class 26 - Invalid SQL Statement Name
|
232
239
|
|
@@ -278,6 +285,7 @@ Section: Class 39 - External Routine Invocation Exception
|
|
278
285
|
39004 E ERRCODE_E_R_I_E_NULL_VALUE_NOT_ALLOWED null_value_not_allowed
|
279
286
|
39P01 E ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED trigger_protocol_violated
|
280
287
|
39P02 E ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED srf_protocol_violated
|
288
|
+
39P03 E ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED event_trigger_protocol_violated
|
281
289
|
|
282
290
|
Section: Class 3B - Savepoint Exception
|
283
291
|
|
@@ -319,6 +327,7 @@ Section: Class 42 - Syntax Error or Access Rule Violation
|
|
319
327
|
42P21 E ERRCODE_COLLATION_MISMATCH collation_mismatch
|
320
328
|
42P22 E ERRCODE_INDETERMINATE_COLLATION indeterminate_collation
|
321
329
|
42809 E ERRCODE_WRONG_OBJECT_TYPE wrong_object_type
|
330
|
+
428C9 E ERRCODE_GENERATED_ALWAYS generated_always
|
322
331
|
|
323
332
|
# Note: for ERRCODE purposes, we divide namable objects into these categories:
|
324
333
|
# databases, schemas, prepared statements, cursors, tables, columns,
|
@@ -410,6 +419,10 @@ Section: Class 58 - System Error (errors external to PostgreSQL itself)
|
|
410
419
|
58P01 E ERRCODE_UNDEFINED_FILE undefined_file
|
411
420
|
58P02 E ERRCODE_DUPLICATE_FILE duplicate_file
|
412
421
|
|
422
|
+
Section: Class 72 - Snapshot Failure
|
423
|
+
# (class borrowed from Oracle)
|
424
|
+
72000 E ERRCODE_SNAPSHOT_TOO_OLD snapshot_too_old
|
425
|
+
|
413
426
|
Section: Class F0 - Configuration File Error
|
414
427
|
|
415
428
|
# (PostgreSQL-specific error class)
|
@@ -454,6 +467,7 @@ P0000 E ERRCODE_PLPGSQL_ERROR plp
|
|
454
467
|
P0001 E ERRCODE_RAISE_EXCEPTION raise_exception
|
455
468
|
P0002 E ERRCODE_NO_DATA_FOUND no_data_found
|
456
469
|
P0003 E ERRCODE_TOO_MANY_ROWS too_many_rows
|
470
|
+
P0004 E ERRCODE_ASSERT_FAILURE assert_failure
|
457
471
|
|
458
472
|
Section: Class XX - Internal Error
|
459
473
|
|
data/ext/extconf.rb
CHANGED
@@ -24,7 +24,11 @@ if enable_config("windows-cross")
|
|
24
24
|
else
|
25
25
|
# Native build
|
26
26
|
|
27
|
-
|
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,32 @@ 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 '
|
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
|
+
"of this gem or upgrade your database to at least PostgreSQL-9.2."
|
75
76
|
have_func 'PQconninfo'
|
76
|
-
have_func '
|
77
|
-
|
78
|
-
have_func 'rb_encdb_alias'
|
79
|
-
have_func 'rb_enc_alias'
|
80
|
-
have_func 'rb_thread_call_without_gvl'
|
81
|
-
have_func 'rb_thread_call_with_gvl'
|
82
|
-
have_func 'rb_thread_fd_select'
|
83
|
-
have_func 'rb_w32_wrap_io_handle'
|
84
|
-
have_func 'rb_str_modify_expand'
|
85
|
-
have_func 'rb_hash_dup'
|
86
|
-
|
87
|
-
have_const 'PGRES_COPY_BOTH', 'libpq-fe.h'
|
88
|
-
have_const 'PGRES_SINGLE_TUPLE', 'libpq-fe.h'
|
89
|
-
have_const 'PG_DIAG_TABLE_NAME', 'libpq-fe.h'
|
77
|
+
have_func 'PQsslAttribute'
|
78
|
+
have_func 'PQencryptPasswordConn'
|
90
79
|
|
91
|
-
|
92
|
-
have_struct_member 'struct pgNotify', 'extra', 'libpq-fe.h'
|
80
|
+
have_const 'PG_DIAG_TABLE_NAME', 'libpq-fe.h'
|
93
81
|
|
94
82
|
# unistd.h confilicts with ruby/win32.h when cross compiling for win32 and ruby 1.9.1
|
95
83
|
have_header 'unistd.h'
|
96
|
-
have_header '
|
84
|
+
have_header 'inttypes.h'
|
85
|
+
|
86
|
+
checking_for "C99 variable length arrays" do
|
87
|
+
$defs.push( "-DHAVE_VARIABLE_LENGTH_ARRAYS" ) if try_compile('void test_vla(int l){ int vla[l]; }')
|
88
|
+
end
|
97
89
|
|
98
90
|
create_header()
|
99
91
|
create_makefile( "pg_ext" )
|
data/ext/gvl_wrappers.c
CHANGED
@@ -5,6 +5,10 @@
|
|
5
5
|
|
6
6
|
#include "pg.h"
|
7
7
|
|
8
|
+
#ifndef HAVE_PQENCRYPTPASSWORDCONN
|
9
|
+
char *PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm){return NULL;}
|
10
|
+
#endif
|
11
|
+
|
8
12
|
FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_WRAPPER_STRUCT );
|
9
13
|
FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_SKELETON );
|
10
14
|
FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_STUB );
|
data/ext/gvl_wrappers.h
CHANGED
@@ -15,14 +15,7 @@
|
|
15
15
|
#ifndef __gvl_wrappers_h
|
16
16
|
#define __gvl_wrappers_h
|
17
17
|
|
18
|
-
#
|
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
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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, ¶ms, 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
|
-
#
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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, ¶ms); \
|
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
|
3
|
+
* $Id: pg.c,v 1f0926bfa9a5 2018/01/04 18:14:32 lars $
|
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-2016 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
|
@@ -68,7 +69,6 @@ VALUE rb_mPGconstants;
|
|
68
69
|
* M17n functions
|
69
70
|
*/
|
70
71
|
|
71
|
-
#ifdef M17N_SUPPORTED
|
72
72
|
/**
|
73
73
|
* The mapping from canonical encoding names in PostgreSQL to ones in Ruby.
|
74
74
|
*/
|
@@ -143,7 +143,7 @@ pg_find_or_create_johab(void)
|
|
143
143
|
|
144
144
|
enc_index = rb_define_dummy_encoding(aliases[0]);
|
145
145
|
for (i = 1; i < sizeof(aliases)/sizeof(aliases[0]); ++i) {
|
146
|
-
|
146
|
+
rb_encdb_alias(aliases[i], aliases[0]);
|
147
147
|
}
|
148
148
|
return rb_enc_from_index(enc_index);
|
149
149
|
}
|
@@ -228,8 +228,6 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
|
|
228
228
|
return encname;
|
229
229
|
}
|
230
230
|
|
231
|
-
#endif /* M17N_SUPPORTED */
|
232
|
-
|
233
231
|
|
234
232
|
/*
|
235
233
|
* Ensures that the given string has enough capacity to take expand_len
|
@@ -252,52 +250,33 @@ pg_get_rb_encoding_as_pg_encoding( rb_encoding *enc )
|
|
252
250
|
* char *current_out, *end_capa;
|
253
251
|
* PG_RB_STR_NEW( string, current_out, end_capa );
|
254
252
|
* while( data_is_going_to_be_processed ){
|
255
|
-
* PG_RB_STR_ENSURE_CAPA( string, 2 current_out, end_capa );
|
253
|
+
* PG_RB_STR_ENSURE_CAPA( string, 2, current_out, end_capa );
|
256
254
|
* *current_out++ = databyte1;
|
257
255
|
* *current_out++ = databyte2;
|
258
256
|
* }
|
259
257
|
* rb_str_set_len( string, current_out - RSTRING_PTR(string) );
|
260
258
|
*
|
261
259
|
*/
|
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;
|
260
|
+
char *
|
261
|
+
pg_rb_str_ensure_capa( VALUE str, long expand_len, char *curr_ptr, char **end_ptr )
|
262
|
+
{
|
263
|
+
long curr_len = curr_ptr - RSTRING_PTR(str);
|
264
|
+
long curr_capa = rb_str_capacity( str );
|
265
|
+
if( curr_capa < curr_len + expand_len ){
|
266
|
+
rb_str_set_len( str, curr_len );
|
267
|
+
rb_str_modify_expand( str, (curr_len + expand_len) * 2 - curr_capa );
|
268
|
+
curr_ptr = RSTRING_PTR(str) + curr_len;
|
292
269
|
}
|
293
|
-
|
270
|
+
if( end_ptr )
|
271
|
+
*end_ptr = RSTRING_PTR(str) + rb_str_capacity( str );
|
272
|
+
return curr_ptr;
|
273
|
+
}
|
294
274
|
|
295
275
|
|
296
276
|
/**************************************************************************
|
297
277
|
* Module Methods
|
298
278
|
**************************************************************************/
|
299
279
|
|
300
|
-
#ifdef HAVE_PQLIBVERSION
|
301
280
|
/*
|
302
281
|
* call-seq:
|
303
282
|
* PG.library_version -> Integer
|
@@ -315,7 +294,6 @@ pg_s_library_version(VALUE self)
|
|
315
294
|
UNUSED( self );
|
316
295
|
return INT2NUM(PQlibVersion());
|
317
296
|
}
|
318
|
-
#endif
|
319
297
|
|
320
298
|
|
321
299
|
/*
|
@@ -409,9 +387,7 @@ Init_pg_ext()
|
|
409
387
|
/*************************
|
410
388
|
* PG module methods
|
411
389
|
*************************/
|
412
|
-
#ifdef HAVE_PQLIBVERSION
|
413
390
|
rb_define_singleton_method( rb_mPG, "library_version", pg_s_library_version, 0 );
|
414
|
-
#endif
|
415
391
|
rb_define_singleton_method( rb_mPG, "isthreadsafe", pg_s_threadsafe_p, 0 );
|
416
392
|
SINGLETON_ALIAS( rb_mPG, "is_threadsafe?", "isthreadsafe" );
|
417
393
|
SINGLETON_ALIAS( rb_mPG, "threadsafe?", "isthreadsafe" );
|
@@ -477,7 +453,6 @@ Init_pg_ext()
|
|
477
453
|
/* Verbose error verbosity level (#set_error_verbosity) */
|
478
454
|
rb_define_const(rb_mPGconstants, "PQERRORS_VERBOSE", INT2FIX(PQERRORS_VERBOSE));
|
479
455
|
|
480
|
-
#ifdef HAVE_PQPING
|
481
456
|
/****** PG::Connection CLASS CONSTANTS: Check Server Status ******/
|
482
457
|
|
483
458
|
/* Server is accepting connections. */
|
@@ -488,7 +463,6 @@ Init_pg_ext()
|
|
488
463
|
rb_define_const(rb_mPGconstants, "PQPING_NO_RESPONSE", INT2FIX(PQPING_NO_RESPONSE));
|
489
464
|
/* Connection not attempted (bad params). */
|
490
465
|
rb_define_const(rb_mPGconstants, "PQPING_NO_ATTEMPT", INT2FIX(PQPING_NO_ATTEMPT));
|
491
|
-
#endif
|
492
466
|
|
493
467
|
/****** PG::Connection CLASS CONSTANTS: Large Objects ******/
|
494
468
|
|
@@ -523,13 +497,9 @@ Init_pg_ext()
|
|
523
497
|
/* #result_status constant: A fatal error occurred. */
|
524
498
|
rb_define_const(rb_mPGconstants, "PGRES_FATAL_ERROR", INT2FIX(PGRES_FATAL_ERROR));
|
525
499
|
/* #result_status constant: Copy In/Out data transfer in progress. */
|
526
|
-
#ifdef HAVE_CONST_PGRES_COPY_BOTH
|
527
500
|
rb_define_const(rb_mPGconstants, "PGRES_COPY_BOTH", INT2FIX(PGRES_COPY_BOTH));
|
528
|
-
#endif
|
529
501
|
/* #result_status constant: Single tuple from larger resultset. */
|
530
|
-
#ifdef HAVE_CONST_PGRES_SINGLE_TUPLE
|
531
502
|
rb_define_const(rb_mPGconstants, "PGRES_SINGLE_TUPLE", INT2FIX(PGRES_SINGLE_TUPLE));
|
532
|
-
#endif
|
533
503
|
|
534
504
|
/****** Result CONSTANTS: result error field codes ******/
|
535
505
|
|
@@ -641,9 +611,7 @@ Init_pg_ext()
|
|
641
611
|
/* Add the constants to the toplevel namespace */
|
642
612
|
rb_include_module( rb_mPG, rb_mPGconstants );
|
643
613
|
|
644
|
-
#ifdef M17N_SUPPORTED
|
645
614
|
enc_pg2ruby = st_init_numtable();
|
646
|
-
#endif
|
647
615
|
|
648
616
|
/* Initialize the main extension classes */
|
649
617
|
init_pg_connection();
|