pg 1.3.0.rc1 → 1.3.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.github/workflows/binary-gems.yml +14 -9
- data/.github/workflows/source-gem.yml +9 -8
- data/Gemfile +1 -1
- data/History.rdoc +4 -2
- data/Rakefile.cross +2 -1
- data/ext/pg.c +24 -3
- data/ext/pg_connection.c +88 -274
- data/lib/pg/basic_type_registry.rb +1 -1
- data/lib/pg/connection.rb +236 -27
- data/lib/pg/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +27 -19
- metadata.gz.sig +0 -0
data/ext/pg_connection.c
CHANGED
@@ -249,68 +249,13 @@ pgconn_s_allocate( VALUE klass )
|
|
249
249
|
return self;
|
250
250
|
}
|
251
251
|
|
252
|
-
|
253
|
-
/*
|
254
|
-
* Document-method: new
|
255
|
-
*
|
256
|
-
* call-seq:
|
257
|
-
* PG::Connection.new -> conn
|
258
|
-
* PG::Connection.new(connection_hash) -> conn
|
259
|
-
* PG::Connection.new(connection_string) -> conn
|
260
|
-
* PG::Connection.new(host, port, options, tty, dbname, user, password) -> conn
|
261
|
-
*
|
262
|
-
* Create a connection to the specified server.
|
263
|
-
*
|
264
|
-
* +connection_hash+ must be a ruby Hash with connection parameters.
|
265
|
-
* See the {list of valid parameters}[https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS] in the PostgreSQL documentation.
|
266
|
-
*
|
267
|
-
* There are two accepted formats for +connection_string+: plain <code>keyword = value</code> strings and URIs.
|
268
|
-
* See the documentation of {connection strings}[https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING].
|
269
|
-
*
|
270
|
-
* The positional parameter form has the same functionality except that the missing parameters will always take on default values. The parameters are:
|
271
|
-
* [+host+]
|
272
|
-
* server hostname
|
273
|
-
* [+port+]
|
274
|
-
* server port number
|
275
|
-
* [+options+]
|
276
|
-
* backend options
|
277
|
-
* [+tty+]
|
278
|
-
* (ignored in all versions of PostgreSQL)
|
279
|
-
* [+dbname+]
|
280
|
-
* connecting database name
|
281
|
-
* [+user+]
|
282
|
-
* login user name
|
283
|
-
* [+password+]
|
284
|
-
* login password
|
285
|
-
*
|
286
|
-
* Examples:
|
287
|
-
*
|
288
|
-
* # Connect using all defaults
|
289
|
-
* PG::Connection.new
|
290
|
-
*
|
291
|
-
* # As a Hash
|
292
|
-
* PG::Connection.new( dbname: 'test', port: 5432 )
|
293
|
-
*
|
294
|
-
* # As a String
|
295
|
-
* PG::Connection.new( "dbname=test port=5432" )
|
296
|
-
*
|
297
|
-
* # As an Array
|
298
|
-
* PG::Connection.new( nil, 5432, nil, nil, 'test', nil, nil )
|
299
|
-
*
|
300
|
-
* # As an URI
|
301
|
-
* PG::Connection.new( "postgresql://user:pass@pgsql.example.com:5432/testdb?sslmode=require" )
|
302
|
-
*
|
303
|
-
* If the Ruby default internal encoding is set (i.e., <code>Encoding.default_internal != nil</code>), the
|
304
|
-
* connection will have its +client_encoding+ set accordingly.
|
305
|
-
*
|
306
|
-
* Raises a PG::Error if the connection fails.
|
307
|
-
*/
|
308
252
|
static VALUE
|
309
|
-
|
253
|
+
pgconn_s_sync_connect(int argc, VALUE *argv, VALUE klass)
|
310
254
|
{
|
311
255
|
t_pg_connection *this;
|
312
256
|
VALUE conninfo;
|
313
257
|
VALUE error;
|
258
|
+
VALUE self = pgconn_s_allocate( klass );
|
314
259
|
|
315
260
|
this = pg_get_connection( self );
|
316
261
|
conninfo = rb_funcall2( rb_cPGconn, rb_intern("parse_connect_args"), argc, argv );
|
@@ -383,28 +328,8 @@ pgconn_s_connect_start( int argc, VALUE *argv, VALUE klass )
|
|
383
328
|
return rb_conn;
|
384
329
|
}
|
385
330
|
|
386
|
-
/*
|
387
|
-
* call-seq:
|
388
|
-
* PG::Connection.ping(connection_hash) -> Integer
|
389
|
-
* PG::Connection.ping(connection_string) -> Integer
|
390
|
-
* PG::Connection.ping(host, port, options, tty, dbname, login, password) -> Integer
|
391
|
-
*
|
392
|
-
* Check server status.
|
393
|
-
*
|
394
|
-
* See PG::Connection.new for a description of the parameters.
|
395
|
-
*
|
396
|
-
* Returns one of:
|
397
|
-
* [+PQPING_OK+]
|
398
|
-
* server is accepting connections
|
399
|
-
* [+PQPING_REJECT+]
|
400
|
-
* server is alive but rejecting connections
|
401
|
-
* [+PQPING_NO_RESPONSE+]
|
402
|
-
* could not establish connection
|
403
|
-
* [+PQPING_NO_ATTEMPT+]
|
404
|
-
* connection not attempted (bad params)
|
405
|
-
*/
|
406
331
|
static VALUE
|
407
|
-
|
332
|
+
pgconn_s_sync_ping( int argc, VALUE *argv, VALUE klass )
|
408
333
|
{
|
409
334
|
PGPing ping;
|
410
335
|
VALUE conninfo;
|
@@ -453,30 +378,8 @@ pgconn_s_conndefaults(VALUE self)
|
|
453
378
|
|
454
379
|
|
455
380
|
#ifdef HAVE_PQENCRYPTPASSWORDCONN
|
456
|
-
/*
|
457
|
-
* call-seq:
|
458
|
-
* conn.encrypt_password( password, username, algorithm=nil ) -> String
|
459
|
-
*
|
460
|
-
* This function is intended to be used by client applications that wish to send commands like <tt>ALTER USER joe PASSWORD 'pwd'</tt>.
|
461
|
-
* It is good practice not to send the original cleartext password in such a command, because it might be exposed in command logs, activity displays, and so on.
|
462
|
-
* Instead, use this function to convert the password to encrypted form before it is sent.
|
463
|
-
*
|
464
|
-
* The +password+ and +username+ arguments are the cleartext password, and the SQL name of the user it is for.
|
465
|
-
* +algorithm+ specifies the encryption algorithm to use to encrypt the password.
|
466
|
-
* Currently supported algorithms are +md5+ and +scram-sha-256+ (+on+ and +off+ are also accepted as aliases for +md5+, for compatibility with older server versions).
|
467
|
-
* Note that support for +scram-sha-256+ was introduced in PostgreSQL version 10, and will not work correctly with older server versions.
|
468
|
-
* If algorithm is omitted or +nil+, this function will query the server for the current value of the +password_encryption+ setting.
|
469
|
-
* That can block, and will fail if the current transaction is aborted, or if the connection is busy executing another query.
|
470
|
-
* If you wish to use the default algorithm for the server but want to avoid blocking, query +password_encryption+ yourself before calling #encrypt_password, and pass that value as the algorithm.
|
471
|
-
*
|
472
|
-
* Return value is the encrypted password.
|
473
|
-
* The caller can assume the string doesn't contain any special characters that would require escaping.
|
474
|
-
*
|
475
|
-
* Available since PostgreSQL-10.
|
476
|
-
* See also corresponding {libpq function}[https://www.postgresql.org/docs/current/libpq-misc.html#LIBPQ-PQENCRYPTPASSWORDCONN].
|
477
|
-
*/
|
478
381
|
static VALUE
|
479
|
-
|
382
|
+
pgconn_sync_encrypt_password(int argc, VALUE *argv, VALUE self)
|
480
383
|
{
|
481
384
|
char *encrypted = NULL;
|
482
385
|
VALUE rval = Qnil;
|
@@ -571,6 +474,11 @@ pgconn_connect_poll(VALUE self)
|
|
571
474
|
{
|
572
475
|
PostgresPollingStatusType status;
|
573
476
|
status = gvl_PQconnectPoll(pg_get_pgconn(self));
|
477
|
+
|
478
|
+
if ( status == PGRES_POLLING_FAILED ) {
|
479
|
+
pgconn_close_socket_io(self);
|
480
|
+
}
|
481
|
+
|
574
482
|
return INT2FIX((int)status);
|
575
483
|
}
|
576
484
|
|
@@ -607,15 +515,8 @@ pgconn_finished_p( VALUE self )
|
|
607
515
|
}
|
608
516
|
|
609
517
|
|
610
|
-
/*
|
611
|
-
* call-seq:
|
612
|
-
* conn.reset()
|
613
|
-
*
|
614
|
-
* Resets the backend connection. This method closes the
|
615
|
-
* backend connection and tries to re-connect.
|
616
|
-
*/
|
617
518
|
static VALUE
|
618
|
-
|
519
|
+
pgconn_sync_reset( VALUE self )
|
619
520
|
{
|
620
521
|
pgconn_close_socket_io( self );
|
621
522
|
gvl_PQreset( pg_get_pgconn(self) );
|
@@ -654,6 +555,11 @@ pgconn_reset_poll(VALUE self)
|
|
654
555
|
{
|
655
556
|
PostgresPollingStatusType status;
|
656
557
|
status = gvl_PQresetPoll(pg_get_pgconn(self));
|
558
|
+
|
559
|
+
if ( status == PGRES_POLLING_FAILED ) {
|
560
|
+
pgconn_close_socket_io(self);
|
561
|
+
}
|
562
|
+
|
657
563
|
return INT2FIX((int)status);
|
658
564
|
}
|
659
565
|
|
@@ -779,7 +685,11 @@ pgconn_conninfo( VALUE self )
|
|
779
685
|
* call-seq:
|
780
686
|
* conn.status()
|
781
687
|
*
|
782
|
-
* Returns status of connection
|
688
|
+
* Returns the status of the connection, which is one:
|
689
|
+
* PG::Constants::CONNECTION_OK
|
690
|
+
* PG::Constants::CONNECTION_BAD
|
691
|
+
*
|
692
|
+
* ... and other constants of kind PG::Constants::CONNECTION_*
|
783
693
|
*/
|
784
694
|
static VALUE
|
785
695
|
pgconn_status(VALUE self)
|
@@ -1044,7 +954,7 @@ pgconn_connection_used_password(VALUE self)
|
|
1044
954
|
/* :TODO: get_ssl */
|
1045
955
|
|
1046
956
|
|
1047
|
-
static VALUE
|
957
|
+
static VALUE pgconn_sync_exec_params( int, VALUE *, VALUE );
|
1048
958
|
|
1049
959
|
/*
|
1050
960
|
* call-seq:
|
@@ -1062,7 +972,7 @@ static VALUE pgconn_exec_params( int, VALUE *, VALUE );
|
|
1062
972
|
* It can therefore schedule things like garbage collection, while queries are running like in this proposal: https://bugs.ruby-lang.org/issues/14723
|
1063
973
|
*/
|
1064
974
|
static VALUE
|
1065
|
-
|
975
|
+
pgconn_sync_exec(int argc, VALUE *argv, VALUE self)
|
1066
976
|
{
|
1067
977
|
t_pg_connection *this = pg_get_connection_safe( self );
|
1068
978
|
PGresult *result = NULL;
|
@@ -1083,7 +993,7 @@ pgconn_exec(int argc, VALUE *argv, VALUE self)
|
|
1083
993
|
pg_deprecated(0, ("forwarding exec to exec_params is deprecated"));
|
1084
994
|
|
1085
995
|
/* Otherwise, just call #exec_params instead for backward-compatibility */
|
1086
|
-
return
|
996
|
+
return pgconn_sync_exec_params( argc, argv, self );
|
1087
997
|
|
1088
998
|
}
|
1089
999
|
|
@@ -1365,7 +1275,7 @@ pgconn_query_assign_typemap( VALUE self, struct query_params_data *paramsData )
|
|
1365
1275
|
* It's not recommended to use explicit sync or async variants but #exec_params instead, unless you have a good reason to do so.
|
1366
1276
|
*/
|
1367
1277
|
static VALUE
|
1368
|
-
|
1278
|
+
pgconn_sync_exec_params( int argc, VALUE *argv, VALUE self )
|
1369
1279
|
{
|
1370
1280
|
t_pg_connection *this = pg_get_connection_safe( self );
|
1371
1281
|
PGresult *result = NULL;
|
@@ -1385,7 +1295,7 @@ pgconn_exec_params( int argc, VALUE *argv, VALUE self )
|
|
1385
1295
|
*/
|
1386
1296
|
if ( NIL_P(paramsData.params) ) {
|
1387
1297
|
pg_deprecated(1, ("forwarding exec_params to exec is deprecated"));
|
1388
|
-
return
|
1298
|
+
return pgconn_sync_exec( 1, argv, self );
|
1389
1299
|
}
|
1390
1300
|
pgconn_query_assign_typemap( self, ¶msData );
|
1391
1301
|
|
@@ -1416,7 +1326,7 @@ pgconn_exec_params( int argc, VALUE *argv, VALUE self )
|
|
1416
1326
|
* It's not recommended to use explicit sync or async variants but #prepare instead, unless you have a good reason to do so.
|
1417
1327
|
*/
|
1418
1328
|
static VALUE
|
1419
|
-
|
1329
|
+
pgconn_sync_prepare(int argc, VALUE *argv, VALUE self)
|
1420
1330
|
{
|
1421
1331
|
t_pg_connection *this = pg_get_connection_safe( self );
|
1422
1332
|
PGresult *result = NULL;
|
@@ -1465,7 +1375,7 @@ pgconn_prepare(int argc, VALUE *argv, VALUE self)
|
|
1465
1375
|
* It's not recommended to use explicit sync or async variants but #exec_prepared instead, unless you have a good reason to do so.
|
1466
1376
|
*/
|
1467
1377
|
static VALUE
|
1468
|
-
|
1378
|
+
pgconn_sync_exec_prepared(int argc, VALUE *argv, VALUE self)
|
1469
1379
|
{
|
1470
1380
|
t_pg_connection *this = pg_get_connection_safe( self );
|
1471
1381
|
PGresult *result = NULL;
|
@@ -1510,7 +1420,7 @@ pgconn_exec_prepared(int argc, VALUE *argv, VALUE self)
|
|
1510
1420
|
* It's not recommended to use explicit sync or async variants but #describe_prepared instead, unless you have a good reason to do so.
|
1511
1421
|
*/
|
1512
1422
|
static VALUE
|
1513
|
-
|
1423
|
+
pgconn_sync_describe_prepared(VALUE self, VALUE stmt_name)
|
1514
1424
|
{
|
1515
1425
|
PGresult *result;
|
1516
1426
|
VALUE rb_pgresult;
|
@@ -1538,7 +1448,7 @@ pgconn_describe_prepared(VALUE self, VALUE stmt_name)
|
|
1538
1448
|
* It's not recommended to use explicit sync or async variants but #describe_portal instead, unless you have a good reason to do so.
|
1539
1449
|
*/
|
1540
1450
|
static VALUE
|
1541
|
-
|
1451
|
+
pgconn_sync_describe_portal(self, stmt_name)
|
1542
1452
|
VALUE self, stmt_name;
|
1543
1453
|
{
|
1544
1454
|
PGresult *result;
|
@@ -2133,24 +2043,8 @@ pgconn_send_describe_portal(VALUE self, VALUE portal)
|
|
2133
2043
|
}
|
2134
2044
|
|
2135
2045
|
|
2136
|
-
/*
|
2137
|
-
* call-seq:
|
2138
|
-
* conn.get_result() -> PG::Result
|
2139
|
-
* conn.get_result() {|pg_result| block }
|
2140
|
-
*
|
2141
|
-
* Blocks waiting for the next result from a call to
|
2142
|
-
* #send_query (or another asynchronous command), and returns
|
2143
|
-
* it. Returns +nil+ if no more results are available.
|
2144
|
-
*
|
2145
|
-
* Note: call this function repeatedly until it returns +nil+, or else
|
2146
|
-
* you will not be able to issue further commands.
|
2147
|
-
*
|
2148
|
-
* If the optional code block is given, it will be passed <i>result</i> as an argument,
|
2149
|
-
* and the PG::Result object will automatically be cleared when the block terminates.
|
2150
|
-
* In this instance, <code>conn.exec</code> returns the value of the block.
|
2151
|
-
*/
|
2152
2046
|
static VALUE
|
2153
|
-
|
2047
|
+
pgconn_sync_get_result(VALUE self)
|
2154
2048
|
{
|
2155
2049
|
PGconn *conn = pg_get_pgconn(self);
|
2156
2050
|
PGresult *result;
|
@@ -2183,6 +2077,7 @@ pgconn_consume_input(self)
|
|
2183
2077
|
PGconn *conn = pg_get_pgconn(self);
|
2184
2078
|
/* returns 0 on error */
|
2185
2079
|
if(PQconsumeInput(conn) == 0) {
|
2080
|
+
pgconn_close_socket_io(self);
|
2186
2081
|
error = rb_exc_new2(rb_eConnectionBad, PQerrorMessage(conn));
|
2187
2082
|
rb_iv_set(error, "@connection", self);
|
2188
2083
|
rb_exc_raise(error);
|
@@ -2195,7 +2090,7 @@ pgconn_consume_input(self)
|
|
2195
2090
|
* conn.is_busy() -> Boolean
|
2196
2091
|
*
|
2197
2092
|
* Returns +true+ if a command is busy, that is, if
|
2198
|
-
*
|
2093
|
+
* #get_result would block. Otherwise returns +false+.
|
2199
2094
|
*/
|
2200
2095
|
static VALUE
|
2201
2096
|
pgconn_is_busy(self)
|
@@ -2204,24 +2099,8 @@ pgconn_is_busy(self)
|
|
2204
2099
|
return gvl_PQisBusy(pg_get_pgconn(self)) ? Qtrue : Qfalse;
|
2205
2100
|
}
|
2206
2101
|
|
2207
|
-
/*
|
2208
|
-
* call-seq:
|
2209
|
-
* conn.setnonblocking(Boolean) -> nil
|
2210
|
-
*
|
2211
|
-
* Sets the nonblocking status of the connection.
|
2212
|
-
* In the blocking state, calls to #send_query
|
2213
|
-
* will block until the message is sent to the server,
|
2214
|
-
* but will not wait for the query results.
|
2215
|
-
* In the nonblocking state, calls to #send_query
|
2216
|
-
* will return an error if the socket is not ready for
|
2217
|
-
* writing.
|
2218
|
-
* Note: This function does not affect #exec, because
|
2219
|
-
* that function doesn't return until the server has
|
2220
|
-
* processed the query and returned the results.
|
2221
|
-
* Returns +nil+.
|
2222
|
-
*/
|
2223
2102
|
static VALUE
|
2224
|
-
|
2103
|
+
pgconn_sync_setnonblocking(self, state)
|
2225
2104
|
VALUE self, state;
|
2226
2105
|
{
|
2227
2106
|
int arg;
|
@@ -2243,30 +2122,13 @@ pgconn_setnonblocking(self, state)
|
|
2243
2122
|
}
|
2244
2123
|
|
2245
2124
|
|
2246
|
-
/*
|
2247
|
-
* call-seq:
|
2248
|
-
* conn.isnonblocking() -> Boolean
|
2249
|
-
*
|
2250
|
-
* Returns +true+ if a command is busy, that is, if
|
2251
|
-
* PQgetResult would block. Otherwise returns +false+.
|
2252
|
-
*/
|
2253
2125
|
static VALUE
|
2254
|
-
|
2126
|
+
pgconn_sync_isnonblocking(self)
|
2255
2127
|
VALUE self;
|
2256
2128
|
{
|
2257
2129
|
return PQisnonblocking(pg_get_pgconn(self)) ? Qtrue : Qfalse;
|
2258
2130
|
}
|
2259
2131
|
|
2260
|
-
/*
|
2261
|
-
* call-seq:
|
2262
|
-
* conn.flush() -> Boolean
|
2263
|
-
*
|
2264
|
-
* Attempts to flush any queued output data to the server.
|
2265
|
-
* Returns +true+ if data is successfully flushed, +false+
|
2266
|
-
* if not (can only return +false+ if connection is
|
2267
|
-
* nonblocking.
|
2268
|
-
* Raises PG::Error if some other failure occurred.
|
2269
|
-
*/
|
2270
2132
|
static VALUE
|
2271
2133
|
pgconn_sync_flush(VALUE self)
|
2272
2134
|
{
|
@@ -2282,18 +2144,8 @@ pgconn_sync_flush(VALUE self)
|
|
2282
2144
|
return (ret) ? Qfalse : Qtrue;
|
2283
2145
|
}
|
2284
2146
|
|
2285
|
-
/*
|
2286
|
-
* call-seq:
|
2287
|
-
* conn.cancel() -> String
|
2288
|
-
*
|
2289
|
-
* Requests cancellation of the command currently being
|
2290
|
-
* processed.
|
2291
|
-
*
|
2292
|
-
* Returns +nil+ on success, or a string containing the
|
2293
|
-
* error message if a failure occurs.
|
2294
|
-
*/
|
2295
2147
|
static VALUE
|
2296
|
-
|
2148
|
+
pgconn_sync_cancel(VALUE self)
|
2297
2149
|
{
|
2298
2150
|
char errbuf[256];
|
2299
2151
|
PGcancel *cancel;
|
@@ -2395,8 +2247,10 @@ wait_socket_readable( VALUE self, struct timeval *ptimeout, void *(*is_readable)
|
|
2395
2247
|
socket_io = pgconn_socket_io(self);
|
2396
2248
|
|
2397
2249
|
/* Check for connection errors (PQisBusy is true on connection errors) */
|
2398
|
-
if ( PQconsumeInput(conn) == 0 )
|
2250
|
+
if ( PQconsumeInput(conn) == 0 ) {
|
2251
|
+
pgconn_close_socket_io(self);
|
2399
2252
|
rb_raise( rb_eConnectionBad, "PQconsumeInput() %s", PQerrorMessage(conn) );
|
2253
|
+
}
|
2400
2254
|
|
2401
2255
|
if ( ptimeout ) {
|
2402
2256
|
gettimeofday(&currtime, NULL);
|
@@ -2425,6 +2279,7 @@ wait_socket_readable( VALUE self, struct timeval *ptimeout, void *(*is_readable)
|
|
2425
2279
|
|
2426
2280
|
/* Check for connection errors (PQisBusy is true on connection errors) */
|
2427
2281
|
if ( PQconsumeInput(conn) == 0 ){
|
2282
|
+
pgconn_close_socket_io(self);
|
2428
2283
|
rb_raise( rb_eConnectionBad, "PQconsumeInput() %s", PQerrorMessage(conn) );
|
2429
2284
|
}
|
2430
2285
|
}
|
@@ -2432,6 +2287,16 @@ wait_socket_readable( VALUE self, struct timeval *ptimeout, void *(*is_readable)
|
|
2432
2287
|
return retval;
|
2433
2288
|
}
|
2434
2289
|
|
2290
|
+
/*
|
2291
|
+
* call-seq:
|
2292
|
+
* conn.flush() -> Boolean
|
2293
|
+
*
|
2294
|
+
* Attempts to flush any queued output data to the server.
|
2295
|
+
* Returns +true+ if data is successfully flushed, +false+
|
2296
|
+
* if not (can only return +false+ if connection is
|
2297
|
+
* nonblocking.
|
2298
|
+
* Raises PG::Error if some other failure occurred.
|
2299
|
+
*/
|
2435
2300
|
static VALUE
|
2436
2301
|
pgconn_async_flush(VALUE self)
|
2437
2302
|
{
|
@@ -2520,28 +2385,8 @@ pgconn_wait_for_notify(int argc, VALUE *argv, VALUE self)
|
|
2520
2385
|
}
|
2521
2386
|
|
2522
2387
|
|
2523
|
-
/*
|
2524
|
-
* call-seq:
|
2525
|
-
* conn.put_copy_data( buffer [, encoder] ) -> Boolean
|
2526
|
-
*
|
2527
|
-
* Transmits _buffer_ as copy data to the server.
|
2528
|
-
* Returns true if the data was sent, false if it was
|
2529
|
-
* not sent (false is only possible if the connection
|
2530
|
-
* is in nonblocking mode, and this command would block).
|
2531
|
-
*
|
2532
|
-
* _encoder_ can be a PG::Coder derivation (typically PG::TextEncoder::CopyRow).
|
2533
|
-
* This encodes the data fields given as _buffer_ from an Array of Strings to
|
2534
|
-
* PostgreSQL's COPY text format inclusive proper escaping. Optionally
|
2535
|
-
* the encoder can type cast the fields from various Ruby types in one step,
|
2536
|
-
* if PG::TextEncoder::CopyRow#type_map is set accordingly.
|
2537
|
-
*
|
2538
|
-
* Raises an exception if an error occurs.
|
2539
|
-
*
|
2540
|
-
* See also #copy_data.
|
2541
|
-
*
|
2542
|
-
*/
|
2543
2388
|
static VALUE
|
2544
|
-
|
2389
|
+
pgconn_sync_put_copy_data(int argc, VALUE *argv, VALUE self)
|
2545
2390
|
{
|
2546
2391
|
int ret;
|
2547
2392
|
int len;
|
@@ -2596,22 +2441,8 @@ pgconn_put_copy_data(int argc, VALUE *argv, VALUE self)
|
|
2596
2441
|
return (ret) ? Qtrue : Qfalse;
|
2597
2442
|
}
|
2598
2443
|
|
2599
|
-
/*
|
2600
|
-
* call-seq:
|
2601
|
-
* conn.put_copy_end( [ error_message ] ) -> Boolean
|
2602
|
-
*
|
2603
|
-
* Sends end-of-data indication to the server.
|
2604
|
-
*
|
2605
|
-
* _error_message_ is an optional parameter, and if set,
|
2606
|
-
* forces the COPY command to fail with the string
|
2607
|
-
* _error_message_.
|
2608
|
-
*
|
2609
|
-
* Returns true if the end-of-data was sent, *false* if it was
|
2610
|
-
* not sent (*false* is only possible if the connection
|
2611
|
-
* is in nonblocking mode, and this command would block).
|
2612
|
-
*/
|
2613
2444
|
static VALUE
|
2614
|
-
|
2445
|
+
pgconn_sync_put_copy_end(int argc, VALUE *argv, VALUE self)
|
2615
2446
|
{
|
2616
2447
|
VALUE str;
|
2617
2448
|
VALUE error;
|
@@ -2633,27 +2464,8 @@ pgconn_put_copy_end(int argc, VALUE *argv, VALUE self)
|
|
2633
2464
|
return (ret) ? Qtrue : Qfalse;
|
2634
2465
|
}
|
2635
2466
|
|
2636
|
-
/*
|
2637
|
-
* call-seq:
|
2638
|
-
* conn.get_copy_data( [ nonblock = false [, decoder = nil ]] ) -> Object
|
2639
|
-
*
|
2640
|
-
* Return one row of data, +nil+
|
2641
|
-
* if the copy is done, or +false+ if the call would
|
2642
|
-
* block (only possible if _nonblock_ is true).
|
2643
|
-
*
|
2644
|
-
* If _decoder_ is not set or +nil+, data is returned as binary string.
|
2645
|
-
*
|
2646
|
-
* If _decoder_ is set to a PG::Coder derivation, the return type depends on this decoder.
|
2647
|
-
* PG::TextDecoder::CopyRow decodes the received data fields from one row of PostgreSQL's
|
2648
|
-
* COPY text format to an Array of Strings.
|
2649
|
-
* Optionally the decoder can type cast the single fields to various Ruby types in one step,
|
2650
|
-
* if PG::TextDecoder::CopyRow#type_map is set accordingly.
|
2651
|
-
*
|
2652
|
-
* See also #copy_data.
|
2653
|
-
*
|
2654
|
-
*/
|
2655
2467
|
static VALUE
|
2656
|
-
|
2468
|
+
pgconn_sync_get_copy_data(int argc, VALUE *argv, VALUE self )
|
2657
2469
|
{
|
2658
2470
|
VALUE async_in;
|
2659
2471
|
VALUE error;
|
@@ -2978,7 +2790,7 @@ pgconn_get_client_encoding(VALUE self)
|
|
2978
2790
|
* It's not recommended to use explicit sync or async variants but #set_client_encoding instead, unless you have a good reason to do so.
|
2979
2791
|
*/
|
2980
2792
|
static VALUE
|
2981
|
-
|
2793
|
+
pgconn_sync_set_client_encoding(VALUE self, VALUE str)
|
2982
2794
|
{
|
2983
2795
|
PGconn *conn = pg_get_pgconn( self );
|
2984
2796
|
|
@@ -3099,7 +2911,7 @@ pgconn_block( int argc, VALUE *argv, VALUE self ) {
|
|
3099
2911
|
* It's not recommended to use explicit sync or async variants but #get_last_result instead, unless you have a good reason to do so.
|
3100
2912
|
*/
|
3101
2913
|
static VALUE
|
3102
|
-
|
2914
|
+
pgconn_sync_get_last_result(VALUE self)
|
3103
2915
|
{
|
3104
2916
|
PGconn *conn = pg_get_pgconn(self);
|
3105
2917
|
VALUE rb_pgresult = Qnil;
|
@@ -3205,8 +3017,10 @@ pgconn_discard_results(VALUE self)
|
|
3205
3017
|
*/
|
3206
3018
|
while( gvl_PQisBusy(conn) ){
|
3207
3019
|
rb_io_wait(socket_io, RB_INT2NUM(RUBY_IO_READABLE), Qnil);
|
3208
|
-
if ( PQconsumeInput(conn) == 0 )
|
3020
|
+
if ( PQconsumeInput(conn) == 0 ) {
|
3021
|
+
pgconn_close_socket_io(self);
|
3209
3022
|
return Qfalse;
|
3023
|
+
}
|
3210
3024
|
}
|
3211
3025
|
|
3212
3026
|
cur = gvl_PQgetResult(conn);
|
@@ -3224,8 +3038,10 @@ pgconn_discard_results(VALUE self)
|
|
3224
3038
|
if( st == 0 ) {
|
3225
3039
|
/* would block -> wait for readable data */
|
3226
3040
|
rb_io_wait(socket_io, RB_INT2NUM(RUBY_IO_READABLE), Qnil);
|
3227
|
-
if ( PQconsumeInput(conn) == 0 )
|
3041
|
+
if ( PQconsumeInput(conn) == 0 ) {
|
3042
|
+
pgconn_close_socket_io(self);
|
3228
3043
|
return Qfalse;
|
3044
|
+
}
|
3229
3045
|
} else if( st > 0 ) {
|
3230
3046
|
/* some data retrieved -> discard it */
|
3231
3047
|
PQfreemem(buffer);
|
@@ -4037,11 +3853,11 @@ static VALUE
|
|
4037
3853
|
pgconn_internal_encoding_set(VALUE self, VALUE enc)
|
4038
3854
|
{
|
4039
3855
|
if (NIL_P(enc)) {
|
4040
|
-
|
3856
|
+
pgconn_sync_set_client_encoding( self, rb_usascii_str_new_cstr("SQL_ASCII") );
|
4041
3857
|
return enc;
|
4042
3858
|
}
|
4043
3859
|
else if ( TYPE(enc) == T_STRING && strcasecmp("JOHAB", StringValueCStr(enc)) == 0 ) {
|
4044
|
-
|
3860
|
+
pgconn_sync_set_client_encoding(self, rb_usascii_str_new_cstr("JOHAB"));
|
4045
3861
|
return enc;
|
4046
3862
|
}
|
4047
3863
|
else {
|
@@ -4405,10 +4221,6 @@ init_pg_connection()
|
|
4405
4221
|
/****** PG::Connection CLASS METHODS ******/
|
4406
4222
|
rb_define_alloc_func( rb_cPGconn, pgconn_s_allocate );
|
4407
4223
|
|
4408
|
-
SINGLETON_ALIAS(rb_cPGconn, "connect", "new");
|
4409
|
-
SINGLETON_ALIAS(rb_cPGconn, "open", "new");
|
4410
|
-
SINGLETON_ALIAS(rb_cPGconn, "setdb", "new");
|
4411
|
-
SINGLETON_ALIAS(rb_cPGconn, "setdblogin", "new");
|
4412
4224
|
rb_define_singleton_method(rb_cPGconn, "escape_string", pgconn_s_escape, 1);
|
4413
4225
|
SINGLETON_ALIAS(rb_cPGconn, "escape", "escape_string");
|
4414
4226
|
rb_define_singleton_method(rb_cPGconn, "escape_bytea", pgconn_s_escape_bytea, 1);
|
@@ -4417,14 +4229,14 @@ init_pg_connection()
|
|
4417
4229
|
rb_define_singleton_method(rb_cPGconn, "quote_ident", pgconn_s_quote_ident, 1);
|
4418
4230
|
rb_define_singleton_method(rb_cPGconn, "connect_start", pgconn_s_connect_start, -1);
|
4419
4231
|
rb_define_singleton_method(rb_cPGconn, "conndefaults", pgconn_s_conndefaults, 0);
|
4420
|
-
rb_define_singleton_method(rb_cPGconn, "
|
4232
|
+
rb_define_singleton_method(rb_cPGconn, "sync_ping", pgconn_s_sync_ping, -1);
|
4233
|
+
rb_define_singleton_method(rb_cPGconn, "sync_connect", pgconn_s_sync_connect, -1);
|
4421
4234
|
|
4422
4235
|
/****** PG::Connection INSTANCE METHODS: Connection Control ******/
|
4423
|
-
rb_define_method(rb_cPGconn, "initialize", pgconn_init, -1);
|
4424
4236
|
rb_define_method(rb_cPGconn, "connect_poll", pgconn_connect_poll, 0);
|
4425
4237
|
rb_define_method(rb_cPGconn, "finish", pgconn_finish, 0);
|
4426
4238
|
rb_define_method(rb_cPGconn, "finished?", pgconn_finished_p, 0);
|
4427
|
-
rb_define_method(rb_cPGconn, "
|
4239
|
+
rb_define_method(rb_cPGconn, "sync_reset", pgconn_sync_reset, 0);
|
4428
4240
|
rb_define_method(rb_cPGconn, "reset_start", pgconn_reset_start, 0);
|
4429
4241
|
rb_define_method(rb_cPGconn, "reset_poll", pgconn_reset_poll, 0);
|
4430
4242
|
rb_define_alias(rb_cPGconn, "close", "finish");
|
@@ -4453,12 +4265,12 @@ init_pg_connection()
|
|
4453
4265
|
/* rb_define_method(rb_cPGconn, "getssl", pgconn_getssl, 0); */
|
4454
4266
|
|
4455
4267
|
/****** PG::Connection INSTANCE METHODS: Command Execution ******/
|
4456
|
-
rb_define_method(rb_cPGconn, "sync_exec",
|
4457
|
-
rb_define_method(rb_cPGconn, "sync_exec_params",
|
4458
|
-
rb_define_method(rb_cPGconn, "sync_prepare",
|
4459
|
-
rb_define_method(rb_cPGconn, "sync_exec_prepared",
|
4460
|
-
rb_define_method(rb_cPGconn, "sync_describe_prepared",
|
4461
|
-
rb_define_method(rb_cPGconn, "sync_describe_portal",
|
4268
|
+
rb_define_method(rb_cPGconn, "sync_exec", pgconn_sync_exec, -1);
|
4269
|
+
rb_define_method(rb_cPGconn, "sync_exec_params", pgconn_sync_exec_params, -1);
|
4270
|
+
rb_define_method(rb_cPGconn, "sync_prepare", pgconn_sync_prepare, -1);
|
4271
|
+
rb_define_method(rb_cPGconn, "sync_exec_prepared", pgconn_sync_exec_prepared, -1);
|
4272
|
+
rb_define_method(rb_cPGconn, "sync_describe_prepared", pgconn_sync_describe_prepared, 1);
|
4273
|
+
rb_define_method(rb_cPGconn, "sync_describe_portal", pgconn_sync_describe_portal, 1);
|
4462
4274
|
|
4463
4275
|
rb_define_method(rb_cPGconn, "exec", pgconn_async_exec, -1);
|
4464
4276
|
rb_define_method(rb_cPGconn, "exec_params", pgconn_async_exec_params, -1);
|
@@ -4491,26 +4303,26 @@ init_pg_connection()
|
|
4491
4303
|
rb_define_method(rb_cPGconn, "send_query_prepared", pgconn_send_query_prepared, -1);
|
4492
4304
|
rb_define_method(rb_cPGconn, "send_describe_prepared", pgconn_send_describe_prepared, 1);
|
4493
4305
|
rb_define_method(rb_cPGconn, "send_describe_portal", pgconn_send_describe_portal, 1);
|
4494
|
-
rb_define_method(rb_cPGconn, "
|
4306
|
+
rb_define_method(rb_cPGconn, "sync_get_result", pgconn_sync_get_result, 0);
|
4495
4307
|
rb_define_method(rb_cPGconn, "consume_input", pgconn_consume_input, 0);
|
4496
4308
|
rb_define_method(rb_cPGconn, "is_busy", pgconn_is_busy, 0);
|
4497
|
-
rb_define_method(rb_cPGconn, "
|
4498
|
-
rb_define_method(rb_cPGconn, "
|
4499
|
-
rb_define_alias(rb_cPGconn, "nonblocking?", "isnonblocking");
|
4309
|
+
rb_define_method(rb_cPGconn, "sync_setnonblocking", pgconn_sync_setnonblocking, 1);
|
4310
|
+
rb_define_method(rb_cPGconn, "sync_isnonblocking", pgconn_sync_isnonblocking, 0);
|
4500
4311
|
rb_define_method(rb_cPGconn, "sync_flush", pgconn_sync_flush, 0);
|
4501
|
-
rb_define_method(rb_cPGconn, "
|
4312
|
+
rb_define_method(rb_cPGconn, "flush", pgconn_async_flush, 0);
|
4313
|
+
rb_define_alias(rb_cPGconn, "async_flush", "flush");
|
4502
4314
|
rb_define_method(rb_cPGconn, "discard_results", pgconn_discard_results, 0);
|
4503
4315
|
|
4504
4316
|
/****** PG::Connection INSTANCE METHODS: Cancelling Queries in Progress ******/
|
4505
|
-
rb_define_method(rb_cPGconn, "
|
4317
|
+
rb_define_method(rb_cPGconn, "sync_cancel", pgconn_sync_cancel, 0);
|
4506
4318
|
|
4507
4319
|
/****** PG::Connection INSTANCE METHODS: NOTIFY ******/
|
4508
4320
|
rb_define_method(rb_cPGconn, "notifies", pgconn_notifies, 0);
|
4509
4321
|
|
4510
4322
|
/****** PG::Connection INSTANCE METHODS: COPY ******/
|
4511
|
-
rb_define_method(rb_cPGconn, "
|
4512
|
-
rb_define_method(rb_cPGconn, "
|
4513
|
-
rb_define_method(rb_cPGconn, "
|
4323
|
+
rb_define_method(rb_cPGconn, "sync_put_copy_data", pgconn_sync_put_copy_data, -1);
|
4324
|
+
rb_define_method(rb_cPGconn, "sync_put_copy_end", pgconn_sync_put_copy_end, -1);
|
4325
|
+
rb_define_method(rb_cPGconn, "sync_get_copy_data", pgconn_sync_get_copy_data, -1);
|
4514
4326
|
|
4515
4327
|
/****** PG::Connection INSTANCE METHODS: Control Functions ******/
|
4516
4328
|
rb_define_method(rb_cPGconn, "set_error_verbosity", pgconn_set_error_verbosity, 1);
|
@@ -4526,18 +4338,20 @@ init_pg_connection()
|
|
4526
4338
|
|
4527
4339
|
/****** PG::Connection INSTANCE METHODS: Other ******/
|
4528
4340
|
rb_define_method(rb_cPGconn, "get_client_encoding", pgconn_get_client_encoding, 0);
|
4529
|
-
rb_define_method(rb_cPGconn, "sync_set_client_encoding",
|
4530
|
-
rb_define_method(rb_cPGconn, "
|
4531
|
-
rb_define_alias(rb_cPGconn, "
|
4341
|
+
rb_define_method(rb_cPGconn, "sync_set_client_encoding", pgconn_sync_set_client_encoding, 1);
|
4342
|
+
rb_define_method(rb_cPGconn, "set_client_encoding", pgconn_async_set_client_encoding, 1);
|
4343
|
+
rb_define_alias(rb_cPGconn, "async_set_client_encoding", "set_client_encoding");
|
4344
|
+
rb_define_alias(rb_cPGconn, "client_encoding=", "set_client_encoding");
|
4532
4345
|
rb_define_method(rb_cPGconn, "block", pgconn_block, -1);
|
4533
4346
|
rb_define_private_method(rb_cPGconn, "flush_data=", pgconn_flush_data_set, 1);
|
4534
4347
|
rb_define_method(rb_cPGconn, "wait_for_notify", pgconn_wait_for_notify, -1);
|
4535
4348
|
rb_define_alias(rb_cPGconn, "notifies_wait", "wait_for_notify");
|
4536
4349
|
rb_define_method(rb_cPGconn, "quote_ident", pgconn_s_quote_ident, 1);
|
4537
|
-
rb_define_method(rb_cPGconn, "sync_get_last_result",
|
4538
|
-
rb_define_method(rb_cPGconn, "
|
4350
|
+
rb_define_method(rb_cPGconn, "sync_get_last_result", pgconn_sync_get_last_result, 0);
|
4351
|
+
rb_define_method(rb_cPGconn, "get_last_result", pgconn_async_get_last_result, 0);
|
4352
|
+
rb_define_alias(rb_cPGconn, "async_get_last_result", "get_last_result");
|
4539
4353
|
#ifdef HAVE_PQENCRYPTPASSWORDCONN
|
4540
|
-
rb_define_method(rb_cPGconn, "
|
4354
|
+
rb_define_method(rb_cPGconn, "sync_encrypt_password", pgconn_sync_encrypt_password, -1);
|
4541
4355
|
#endif
|
4542
4356
|
|
4543
4357
|
#ifdef HAVE_PQSSLATTRIBUTE
|