pgsql 1.5.1 → 1.9
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 +4 -4
- data/lib/Rakefile +2 -2
- data/lib/conn.c +86 -89
- data/lib/conn_exec.c +154 -85
- data/lib/conn_quote.c +16 -15
- data/lib/mkrf_conf +7 -15
- data/lib/module.c +1 -1
- data/lib/module.h +3 -9
- data/lib/result.c +2 -11
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2519cf85dd607a31191b7992cc99a93c31fb0b1103a38462f28cd77081599f0c
|
4
|
+
data.tar.gz: 026e108f08ffa63454f29504120c04f8fe8b3b1ffb664bd4626e7ca9f98f078a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 608f44789a6b5c009558c75b1d37f71fd2b86d283c2b78bf361d76bf3d7bb37065b6426a26f7ecb7d97829b3b31e4e7cf4a0f53453e11fc7327a914d2d65ca8c
|
7
|
+
data.tar.gz: 5e4e1fe2084fb5ba67646128d145de12840ad66c3fd54e0b22e65ea150c0d16444fc157ff19f61864fe048dd1eca4b3d7731ca8411376708ac81a2c7114b9774
|
data/lib/Rakefile
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
require "autorake"
|
6
6
|
|
7
|
-
c = compiler "-O2", "-fPIC"
|
7
|
+
c = compiler "-O2", "-fPIC", "-Wall"
|
8
8
|
l = linker "-shared"
|
9
9
|
|
10
10
|
rule ".o" => ".c" do |t|
|
@@ -17,7 +17,7 @@ DLs = {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
DLs.each { |k,v|
|
20
|
-
|
20
|
+
file k => v do |t|
|
21
21
|
l.cc t.name, t.prerequisites
|
22
22
|
end
|
23
23
|
}
|
data/lib/conn.c
CHANGED
@@ -26,12 +26,12 @@ extern VALUE pgconn_mkstring( struct pgconn_data *ptr, const char *str);
|
|
26
26
|
extern VALUE pgconn_mkstringn( struct pgconn_data *ptr, const char *str, int len);
|
27
27
|
static VALUE pgconn_alloc( VALUE cls);
|
28
28
|
static VALUE pgconn_s_connect( int argc, VALUE *argv, VALUE cls);
|
29
|
-
static VALUE pgconn_s_parse( VALUE cls, VALUE str);
|
30
29
|
static VALUE pgconn_init( int argc, VALUE *argv, VALUE self);
|
31
30
|
static int set_connect_params( st_data_t key, st_data_t val, st_data_t args);
|
32
|
-
static
|
33
|
-
static
|
34
|
-
static VALUE
|
31
|
+
static VALUE connstr_sym_dbname( void);
|
32
|
+
static VALUE connstr_sym_password( void);
|
33
|
+
static void connstr_passwd( VALUE self, VALUE orig_params, VALUE *params);
|
34
|
+
static VALUE connstr_getparam( RB_BLOCK_CALL_FUNC_ARGLIST( yielded, params));
|
35
35
|
|
36
36
|
static VALUE pgconn_close( VALUE self);
|
37
37
|
static VALUE pgconn_reset( VALUE self);
|
@@ -71,6 +71,10 @@ VALUE rb_cPgConn;
|
|
71
71
|
static VALUE rb_ePgConnFailed;
|
72
72
|
static VALUE rb_ePgConnInvalid;
|
73
73
|
|
74
|
+
static VALUE sym_dbname = Qundef;
|
75
|
+
static VALUE sym_password = Qundef;
|
76
|
+
|
77
|
+
static ID id_to_s;
|
74
78
|
|
75
79
|
|
76
80
|
void
|
@@ -221,24 +225,6 @@ pgconn_s_connect( int argc, VALUE *argv, VALUE cls)
|
|
221
225
|
rb_ensure( rb_yield, pgconn, pgconn_close, pgconn) : pgconn;
|
222
226
|
}
|
223
227
|
|
224
|
-
/*
|
225
|
-
* call-seq:
|
226
|
-
* Pg::Conn.parse( str) -> hash
|
227
|
-
*
|
228
|
-
* Parse a connection string and return a hash with keys <code>:dbname</code>,
|
229
|
-
* <code>:user</code>, <code>:host</code>, etc.
|
230
|
-
*
|
231
|
-
*/
|
232
|
-
VALUE
|
233
|
-
pgconn_s_parse( VALUE cls, VALUE str)
|
234
|
-
{
|
235
|
-
VALUE params;
|
236
|
-
|
237
|
-
params = rb_hash_new();
|
238
|
-
connstr_to_hash( params, str);
|
239
|
-
return params;
|
240
|
-
}
|
241
|
-
|
242
228
|
|
243
229
|
/*
|
244
230
|
* Document-method: Pg::Conn.new
|
@@ -252,23 +238,39 @@ pgconn_s_parse( VALUE cls, VALUE str)
|
|
252
238
|
*
|
253
239
|
* c = Pg::Conn.new :dbname => "movies", :host => "jupiter", ...
|
254
240
|
*
|
255
|
-
*
|
256
|
-
*
|
241
|
+
* If the +str+ argument is given but no further parameters,
|
242
|
+
* the PQconnectdb() (not PQconnectdbParams()) function will be called.
|
243
|
+
* If further arguments are present, the +str+ argument will be made into
|
244
|
+
* the "dbname" parameter, but without overwriting an existing one.
|
245
|
+
*
|
246
|
+
* The "dbname" parameter may be a +conninfo+ string as described in the
|
247
|
+
* PostgreSQL documentation:
|
257
248
|
*
|
258
|
-
* "user:password@host:port/dbname"
|
249
|
+
* c = Pg::Conn.new "postgresql://user:password@host:port/dbname"
|
250
|
+
* c = Pg::Conn.new "postgres://user:password@host:port/dbname"
|
251
|
+
* c = Pg::Conn.new "dbname=... host=... user=..."
|
259
252
|
*
|
260
|
-
*
|
261
|
-
*
|
253
|
+
* The password may be specified as an extra parameter:
|
254
|
+
*
|
255
|
+
* c = Pg::Conn.new "postgresql://user@host/dbname", password: "verysecret"
|
262
256
|
*
|
263
257
|
* If the password is the empty string, and there is either an instance method
|
264
258
|
* or a class method <code>password?</code>, that method will be asked. This
|
265
259
|
* method may ask <code>yield :user</code> or <code>yield :dbname</code> and so
|
266
260
|
* on to get the connection parameters.
|
267
261
|
*
|
262
|
+
* class Pg::Conn
|
263
|
+
* def password?
|
264
|
+
* "tercesyrev".reverse
|
265
|
+
* end
|
266
|
+
* end
|
267
|
+
* c = Pg::Conn.new "postgresql://user@host/dbname", password: ""
|
268
|
+
*
|
268
269
|
* See the PostgreSQL documentation for a full list:
|
269
270
|
* [http://www.postgresql.org/docs/current/interactive/libpq-connect.html#LIBPQ-PQCONNECTDBPARAMS]
|
270
271
|
*
|
271
272
|
* On failure, a +Pg::Error+ exception will be raised.
|
273
|
+
*
|
272
274
|
*/
|
273
275
|
VALUE
|
274
276
|
pgconn_init( int argc, VALUE *argv, VALUE self)
|
@@ -280,32 +282,43 @@ pgconn_init( int argc, VALUE *argv, VALUE self)
|
|
280
282
|
struct pgconn_data *c;
|
281
283
|
|
282
284
|
if (rb_scan_args( argc, argv, "02", &str, ¶ms) < 2)
|
283
|
-
if (TYPE( str)
|
285
|
+
if (TYPE( str) == T_HASH) {
|
284
286
|
params = str;
|
285
287
|
str = Qnil;
|
286
288
|
}
|
287
|
-
if (NIL_P( params))
|
288
|
-
params = rb_hash_new();
|
289
|
-
else if (TYPE( params) != T_HASH)
|
290
|
-
params = rb_convert_type( params, T_HASH, "Hash", "to_hash");
|
291
|
-
else
|
292
|
-
params = rb_obj_dup( params);
|
293
|
-
if (!NIL_P( str))
|
294
|
-
connstr_to_hash( params, str);
|
295
|
-
connstr_passwd( self, params);
|
296
289
|
|
297
290
|
Data_Get_Struct( self, struct pgconn_data, c);
|
298
291
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
292
|
+
if (NIL_P( params)) {
|
293
|
+
c->conn = PQconnectdb( RSTRING_PTR( rb_funcall( str, id_to_s, 0)));
|
294
|
+
} else {
|
295
|
+
int expand_dbname;
|
296
|
+
VALUE orig_params = params;
|
297
|
+
|
298
|
+
if (TYPE( params) != T_HASH)
|
299
|
+
params = rb_convert_type( params, T_HASH, "Hash", "to_hash");
|
300
|
+
|
301
|
+
if (!NIL_P( str) && NIL_P( rb_hash_aref( params, connstr_sym_dbname()))) {
|
302
|
+
if (params == orig_params)
|
303
|
+
params = rb_obj_dup( params);
|
304
|
+
rb_hash_aset( params, sym_dbname, str);
|
305
|
+
expand_dbname = 1;
|
306
|
+
} else
|
307
|
+
expand_dbname = 0;
|
308
|
+
|
309
|
+
connstr_passwd( self, orig_params, ¶ms);
|
310
|
+
|
311
|
+
l = RHASH_SIZE( params) + 1;
|
312
|
+
keywords = (const char **) ALLOCA_N( char *, l);
|
313
|
+
values = (const char **) ALLOCA_N( char *, l);
|
314
|
+
ptrs[ 0] = keywords;
|
315
|
+
ptrs[ 1] = values;
|
316
|
+
ptrs[ 2] = (const char **) c;
|
317
|
+
st_foreach( RHASH_TBL( params), &set_connect_params, (st_data_t) ptrs);
|
318
|
+
*(ptrs[ 0]) = *(ptrs[ 1]) = NULL;
|
319
|
+
|
320
|
+
c->conn = PQconnectdbParams( keywords, values, expand_dbname);
|
321
|
+
}
|
309
322
|
if (PQstatus( c->conn) == CONNECTION_BAD)
|
310
323
|
rb_exc_raise( pgconnfailederror_new( c, params));
|
311
324
|
|
@@ -331,50 +344,29 @@ set_connect_params( st_data_t key, st_data_t val, st_data_t args)
|
|
331
344
|
return ST_CONTINUE;
|
332
345
|
}
|
333
346
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
;
|
340
|
-
|
341
|
-
#define KEY_USER "user"
|
342
|
-
#define KEY_PASSWORD "password"
|
343
|
-
#define KEY_HOST "host"
|
344
|
-
#define KEY_PORT "port"
|
345
|
-
#define KEY_DBNAME "dbname"
|
347
|
+
VALUE
|
348
|
+
connstr_sym_dbname( void)
|
349
|
+
{
|
350
|
+
if (sym_dbname == Qundef)
|
351
|
+
sym_dbname = ID2SYM( rb_intern( "dbname"));
|
352
|
+
return sym_dbname;
|
353
|
+
}
|
346
354
|
|
347
|
-
|
348
|
-
|
349
|
-
{
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
if (RTEST( rb_reg_match( re, str))) {
|
354
|
-
match = rb_backref_get();
|
355
|
-
#define ADD_TO_RES( key, n) \
|
356
|
-
k = ID2SYM( rb_intern( key)); m = rb_reg_nth_match( n, match); \
|
357
|
-
if (NIL_P( rb_hash_aref( params, k)) && !NIL_P(m)) \
|
358
|
-
rb_hash_aset( params, k, m)
|
359
|
-
ADD_TO_RES( KEY_USER, 1);
|
360
|
-
ADD_TO_RES( KEY_PASSWORD, 2);
|
361
|
-
ADD_TO_RES( KEY_HOST, 3);
|
362
|
-
ADD_TO_RES( KEY_PORT, 4);
|
363
|
-
ADD_TO_RES( KEY_DBNAME, 5);
|
364
|
-
#undef ADD_TO_RES
|
365
|
-
} else
|
366
|
-
rb_raise( rb_eArgError, "Invalid connection: %s", RSTRING_PTR( str));
|
355
|
+
VALUE
|
356
|
+
connstr_sym_password( void)
|
357
|
+
{
|
358
|
+
if (sym_password == Qundef)
|
359
|
+
sym_password = ID2SYM( rb_intern( "password"));
|
360
|
+
return sym_password;
|
367
361
|
}
|
368
362
|
|
363
|
+
|
369
364
|
void
|
370
|
-
connstr_passwd( VALUE self, VALUE params)
|
365
|
+
connstr_passwd( VALUE self, VALUE orig_params, VALUE *params)
|
371
366
|
{
|
372
|
-
static VALUE sym_password = Qundef;
|
373
367
|
VALUE pw;
|
374
368
|
|
375
|
-
|
376
|
-
sym_password = ID2SYM( rb_intern( KEY_PASSWORD));
|
377
|
-
pw = rb_hash_aref( params, sym_password);
|
369
|
+
pw = rb_hash_aref( *params, connstr_sym_password());
|
378
370
|
if (TYPE( pw) == T_STRING && RSTRING_LEN( pw) == 0) {
|
379
371
|
static ID id_password_q = 0;
|
380
372
|
VALUE pwobj;
|
@@ -386,14 +378,18 @@ connstr_passwd( VALUE self, VALUE params)
|
|
386
378
|
pwobj = self;
|
387
379
|
if (rb_respond_to( CLASS_OF( self), id_password_q))
|
388
380
|
pwobj = CLASS_OF( self);
|
389
|
-
if (pwobj != Qundef)
|
390
|
-
|
381
|
+
if (pwobj != Qundef) {
|
382
|
+
if (*params == orig_params)
|
383
|
+
*params = rb_obj_dup( *params);
|
384
|
+
rb_hash_aset( *params, sym_password,
|
391
385
|
rb_block_call( pwobj, id_password_q, 0, NULL,
|
392
|
-
&connstr_getparam, params));
|
386
|
+
&connstr_getparam, *params));
|
387
|
+
}
|
393
388
|
}
|
394
389
|
}
|
395
390
|
|
396
|
-
VALUE
|
391
|
+
VALUE
|
392
|
+
connstr_getparam( RB_BLOCK_CALL_FUNC_ARGLIST( yielded, params))
|
397
393
|
{
|
398
394
|
return rb_hash_aref( params, yielded);
|
399
395
|
}
|
@@ -865,7 +861,6 @@ Init_pgsql_conn( void)
|
|
865
861
|
rb_define_alloc_func( rb_cPgConn, pgconn_alloc);
|
866
862
|
rb_define_singleton_method( rb_cPgConn, "connect", pgconn_s_connect, -1);
|
867
863
|
rb_define_alias( rb_singleton_class( rb_cPgConn), "open", "connect");
|
868
|
-
rb_define_singleton_method( rb_cPgConn, "parse", pgconn_s_parse, 1);
|
869
864
|
rb_define_method( rb_cPgConn, "initialize", &pgconn_init, -1);
|
870
865
|
rb_define_method( rb_cPgConn, "close", &pgconn_close, 0);
|
871
866
|
rb_define_alias( rb_cPgConn, "finish", "close");
|
@@ -905,6 +900,8 @@ Init_pgsql_conn( void)
|
|
905
900
|
|
906
901
|
rb_define_method( rb_cPgConn, "on_notice", &pgconn_on_notice, 0);
|
907
902
|
|
903
|
+
id_to_s = rb_intern( "to_s");
|
904
|
+
|
908
905
|
Init_pgsql_conn_quote();
|
909
906
|
Init_pgsql_conn_exec();
|
910
907
|
}
|
data/lib/conn_exec.c
CHANGED
@@ -8,12 +8,7 @@
|
|
8
8
|
#include "conn_quote.h"
|
9
9
|
#include "result.h"
|
10
10
|
|
11
|
-
|
12
|
-
#ifdef HAVE_FUNC_RB_ERRINFO
|
13
|
-
#define RB_ERRINFO (rb_errinfo())
|
14
|
-
#else
|
15
|
-
#define RB_ERRINFO ruby_errinfo
|
16
|
-
#endif
|
11
|
+
#include <math.h>
|
17
12
|
|
18
13
|
|
19
14
|
static void pg_raise_connexec( struct pgconn_data *c);
|
@@ -26,22 +21,23 @@ static void pg_parse_parameters( int argc, VALUE *argv, VALUE *cmd, VALUE *par);
|
|
26
21
|
|
27
22
|
static VALUE pgconn_exec( int argc, VALUE *argv, VALUE obj);
|
28
23
|
static VALUE pgconn_send( int argc, VALUE *argv, VALUE obj);
|
29
|
-
static VALUE pgconn_fetch( VALUE
|
24
|
+
static VALUE pgconn_fetch( int argc, VALUE *argv, VALUE conn);
|
25
|
+
static void wait_for_pgsocket( PGconn *c, VALUE to);
|
30
26
|
static VALUE yield_or_return_result( VALUE res);
|
31
27
|
static VALUE clear_resultqueue( VALUE self);
|
32
28
|
|
33
29
|
static VALUE pgconn_query( int argc, VALUE *argv, VALUE self);
|
34
|
-
static VALUE
|
30
|
+
static VALUE pgconn_select_row( int argc, VALUE *argv, VALUE self);
|
35
31
|
static VALUE pgconn_select_value( int argc, VALUE *argv, VALUE self);
|
36
32
|
static VALUE pgconn_select_values( int argc, VALUE *argv, VALUE self);
|
37
33
|
static VALUE pgconn_get_notify( VALUE self);
|
38
34
|
|
39
35
|
static VALUE pgconn_transaction( int argc, VALUE *argv, VALUE self);
|
40
|
-
static VALUE rollback_transaction( VALUE
|
36
|
+
static VALUE rollback_transaction( VALUE conn, VALUE err);
|
41
37
|
static VALUE commit_transaction( VALUE self);
|
42
|
-
static VALUE yield_transaction( VALUE
|
38
|
+
static VALUE yield_transaction( VALUE conn);
|
43
39
|
static VALUE pgconn_subtransaction( int argc, VALUE *argv, VALUE self);
|
44
|
-
static VALUE rollback_subtransaction( VALUE ary);
|
40
|
+
static VALUE rollback_subtransaction( VALUE ary, VALUE err);
|
45
41
|
static VALUE release_subtransaction( VALUE ary);
|
46
42
|
static VALUE yield_subtransaction( VALUE ary);
|
47
43
|
static VALUE pgconn_transaction_status( VALUE self);
|
@@ -60,6 +56,7 @@ static VALUE backup_end( VALUE conn);
|
|
60
56
|
|
61
57
|
|
62
58
|
static VALUE rb_ePgConnExec;
|
59
|
+
static VALUE rb_ePgConnTimeout;
|
63
60
|
static VALUE rb_ePgConnTrans;
|
64
61
|
static VALUE rb_ePgConnCopy;
|
65
62
|
|
@@ -79,8 +76,7 @@ pg_statement_exec( VALUE conn, VALUE cmd, VALUE par)
|
|
79
76
|
struct pgconn_data *c;
|
80
77
|
PGresult *result;
|
81
78
|
|
82
|
-
|
83
|
-
pg_check_conninvalid( c);
|
79
|
+
c = get_pgconn( conn);
|
84
80
|
if (NIL_P( par))
|
85
81
|
result = PQexec( c->conn, pgconn_destring( c, cmd, NULL));
|
86
82
|
else {
|
@@ -104,8 +100,7 @@ pg_statement_send( VALUE conn, VALUE cmd, VALUE par)
|
|
104
100
|
struct pgconn_data *c;
|
105
101
|
int res;
|
106
102
|
|
107
|
-
|
108
|
-
pg_check_conninvalid( c);
|
103
|
+
c = get_pgconn( conn);
|
109
104
|
if (NIL_P( par))
|
110
105
|
res = PQsendQuery( c->conn, pgconn_destring( c, cmd, NULL));
|
111
106
|
else {
|
@@ -119,6 +114,7 @@ pg_statement_send( VALUE conn, VALUE cmd, VALUE par)
|
|
119
114
|
}
|
120
115
|
if (res <= 0)
|
121
116
|
pg_raise_connexec( c);
|
117
|
+
PQsetSingleRowMode( c->conn);
|
122
118
|
}
|
123
119
|
|
124
120
|
char **
|
@@ -130,7 +126,7 @@ params_to_strings( VALUE conn, VALUE params, int *len)
|
|
130
126
|
char **values, **v;
|
131
127
|
char *a;
|
132
128
|
|
133
|
-
|
129
|
+
c = get_pgconn( conn);
|
134
130
|
ptr = RARRAY_PTR( params);
|
135
131
|
*len = l = RARRAY_LEN( params);
|
136
132
|
values = ALLOC_N( char *, l);
|
@@ -166,8 +162,6 @@ free_strings( char **strs, int len)
|
|
166
162
|
void
|
167
163
|
pg_parse_parameters( int argc, VALUE *argv, VALUE *cmd, VALUE *par)
|
168
164
|
{
|
169
|
-
int len;
|
170
|
-
|
171
165
|
rb_scan_args( argc, argv, "1*", cmd, par);
|
172
166
|
StringValue( *cmd);
|
173
167
|
if (RARRAY_LEN( *par) <= 0)
|
@@ -204,18 +198,29 @@ pgconn_exec( int argc, VALUE *argv, VALUE self)
|
|
204
198
|
* Sends an asynchronous SQL query request specified by +sql+ to the
|
205
199
|
* PostgreSQL server.
|
206
200
|
*
|
201
|
+
* This sets the query into single row mode. You have to call +Pg::Conn#fetch+
|
202
|
+
* what will yield one-row results. You may cancel the delivery by breaking
|
203
|
+
* the loop.
|
204
|
+
*
|
207
205
|
* Use Pg::Conn#fetch to fetch the results after you waited for data.
|
208
206
|
*
|
209
207
|
* Pg::Conn.connect do |conn|
|
210
208
|
* conn.send "SELECT pg_sleep(3), * FROM t;" do
|
211
|
-
*
|
212
|
-
*
|
213
|
-
*
|
214
|
-
*
|
215
|
-
*
|
216
|
-
*
|
217
|
-
*
|
218
|
-
*
|
209
|
+
* conn.fetch { |res|
|
210
|
+
* puts res.first.inspect
|
211
|
+
* break if (rand 3) < 1
|
212
|
+
* }
|
213
|
+
* end
|
214
|
+
* end
|
215
|
+
*
|
216
|
+
* Multiple select statements will not be separated by an empty result
|
217
|
+
* or something similar. Query twice if you want to separate them.
|
218
|
+
*
|
219
|
+
* Pg::Conn.connect do |conn|
|
220
|
+
* conn.send "SELECT 33; SELECT 'foo';" do
|
221
|
+
* conn.fetch { |res|
|
222
|
+
* puts res.first.inspect
|
223
|
+
* }
|
219
224
|
* end
|
220
225
|
* end
|
221
226
|
*/
|
@@ -231,8 +236,7 @@ pgconn_send( int argc, VALUE *argv, VALUE self)
|
|
231
236
|
|
232
237
|
/*
|
233
238
|
* call-seq:
|
234
|
-
* conn.fetch()
|
235
|
-
* conn.fetch() { |result| ... } -> obj
|
239
|
+
* conn.fetch( timeout = nil) { |result| ... } -> obj
|
236
240
|
*
|
237
241
|
* Fetches the results of the previous Pg::Conn#send call.
|
238
242
|
* See there for an example.
|
@@ -240,42 +244,105 @@ pgconn_send( int argc, VALUE *argv, VALUE self)
|
|
240
244
|
* The result will be +nil+ if there are no more results.
|
241
245
|
*/
|
242
246
|
VALUE
|
243
|
-
pgconn_fetch( VALUE
|
247
|
+
pgconn_fetch( int argc, VALUE *argv, VALUE conn)
|
244
248
|
{
|
245
249
|
struct pgconn_data *c;
|
246
250
|
PGresult *result;
|
247
|
-
VALUE
|
251
|
+
VALUE to;
|
252
|
+
|
253
|
+
rb_scan_args( argc, argv, "01", &to);
|
248
254
|
|
249
|
-
|
250
|
-
|
255
|
+
c = get_pgconn( conn);
|
256
|
+
wait_for_pgsocket( c->conn, to);
|
251
257
|
if (PQconsumeInput( c->conn) == 0)
|
252
258
|
pg_raise_connexec( c);
|
253
|
-
if (PQisBusy( c->conn)
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
259
|
+
if (PQisBusy( c->conn) == 0)
|
260
|
+
while ((result = PQgetResult( c->conn)) != NULL) {
|
261
|
+
if (PQntuples( result) == 0)
|
262
|
+
PQclear( result);
|
263
|
+
else
|
264
|
+
rb_yield( pgresult_new( result, c, Qnil, Qnil));
|
265
|
+
}
|
266
|
+
return Qnil;
|
267
|
+
}
|
268
|
+
|
269
|
+
void
|
270
|
+
wait_for_pgsocket( PGconn *c, VALUE to)
|
271
|
+
{
|
272
|
+
int fd;
|
273
|
+
fd_set readset;
|
274
|
+
struct timeval tv, *ptv;
|
275
|
+
|
276
|
+
fd = PQsocket( c);
|
277
|
+
|
278
|
+
FD_ZERO(&readset);
|
279
|
+
FD_SET(fd, &readset);
|
280
|
+
|
281
|
+
ptv = NULL;
|
282
|
+
if (!NIL_P( to)) {
|
283
|
+
int type = TYPE( to);
|
284
|
+
if (type == T_FIXNUM) {
|
285
|
+
tv.tv_sec = FIX2LONG( to);
|
286
|
+
tv.tv_usec = 0;
|
287
|
+
} else {
|
288
|
+
double x;
|
289
|
+
switch (type) {
|
290
|
+
case T_FLOAT:
|
291
|
+
x = RFLOAT_VALUE( to);
|
292
|
+
break;
|
293
|
+
case T_BIGNUM:
|
294
|
+
x = rb_big2dbl( to);
|
295
|
+
break;
|
296
|
+
case T_RATIONAL:
|
297
|
+
x = rb_num2dbl( to);
|
298
|
+
break;
|
299
|
+
default:
|
300
|
+
x = RFLOAT_VALUE( rb_funcall( to, rb_intern( "to_f"), 0));
|
301
|
+
break;
|
302
|
+
}
|
303
|
+
tv.tv_sec = floor( x);
|
304
|
+
tv.tv_usec = round( (x-tv.tv_sec)*1000000);
|
305
|
+
}
|
306
|
+
ptv = &tv;
|
307
|
+
}
|
308
|
+
|
309
|
+
if (select( fd+1, &readset, NULL, NULL, ptv) < 0 || !FD_ISSET( fd, &readset))
|
310
|
+
rb_raise( rb_ePgConnTimeout, "Wait for data timed out.");
|
258
311
|
}
|
259
312
|
|
260
313
|
VALUE
|
261
314
|
yield_or_return_result( VALUE result)
|
262
315
|
{
|
263
|
-
struct pgresult_data *r;
|
264
|
-
|
265
|
-
Data_Get_Struct( result, struct pgresult_data, r);
|
266
316
|
return rb_block_given_p() ?
|
267
317
|
rb_ensure( rb_yield, result, pgresult_clear, result) : result;
|
268
318
|
}
|
269
319
|
|
270
320
|
VALUE
|
271
|
-
clear_resultqueue( VALUE
|
321
|
+
clear_resultqueue( VALUE conn)
|
272
322
|
{
|
273
323
|
struct pgconn_data *c;
|
274
324
|
PGresult *result;
|
325
|
+
int cancelled;
|
275
326
|
|
276
|
-
|
277
|
-
|
327
|
+
c = get_pgconn( conn);
|
328
|
+
cancelled = 0;
|
329
|
+
while ((result = PQgetResult( c->conn)) != NULL) {
|
278
330
|
PQclear( result);
|
331
|
+
if (!cancelled) {
|
332
|
+
char errbuf[ 256];
|
333
|
+
PGcancel *cancel;
|
334
|
+
int ret;
|
335
|
+
|
336
|
+
cancel = PQgetCancel( c->conn);
|
337
|
+
if (cancel == NULL)
|
338
|
+
rb_raise( rb_ePgConnTrans, "Could not get cancel object.");
|
339
|
+
ret = PQcancel( cancel, errbuf, sizeof errbuf);
|
340
|
+
PQfreeCancel( cancel);
|
341
|
+
if (ret == 0)
|
342
|
+
rb_raise( rb_ePgConnTrans, "Cancel of sent query failed: %s", errbuf);
|
343
|
+
cancelled = 1;
|
344
|
+
}
|
345
|
+
}
|
279
346
|
return Qnil;
|
280
347
|
}
|
281
348
|
|
@@ -316,13 +383,13 @@ pgconn_query( int argc, VALUE *argv, VALUE self)
|
|
316
383
|
|
317
384
|
/*
|
318
385
|
* call-seq:
|
319
|
-
* conn.
|
386
|
+
* conn.select_row( query, *bind_values)
|
320
387
|
*
|
321
388
|
* Return the first row of the query results.
|
322
389
|
* Equivalent to <code>conn.query( query, *bind_values).first</code>.
|
323
390
|
*/
|
324
391
|
VALUE
|
325
|
-
|
392
|
+
pgconn_select_row( int argc, VALUE *argv, VALUE self)
|
326
393
|
{
|
327
394
|
VALUE cmd, par;
|
328
395
|
VALUE res;
|
@@ -340,7 +407,7 @@ pgconn_select_one( int argc, VALUE *argv, VALUE self)
|
|
340
407
|
* conn.select_value( query, *bind_values)
|
341
408
|
*
|
342
409
|
* Return the first value of the first row of the query results.
|
343
|
-
* Equivalent to conn.query( query, *bind_values).first
|
410
|
+
* Equivalent to conn.query( query, *bind_values).first&.first
|
344
411
|
*/
|
345
412
|
VALUE
|
346
413
|
pgconn_select_value( int argc, VALUE *argv, VALUE self)
|
@@ -361,6 +428,7 @@ pgconn_select_value( int argc, VALUE *argv, VALUE self)
|
|
361
428
|
* call-seq:
|
362
429
|
* conn.select_values( query, *bind_values)
|
363
430
|
*
|
431
|
+
* Return the all values over all rows as one array.
|
364
432
|
* Equivalent to conn.query( query, *bind_values).flatten
|
365
433
|
*/
|
366
434
|
VALUE
|
@@ -399,14 +467,14 @@ pgconn_select_values( int argc, VALUE *argv, VALUE self)
|
|
399
467
|
* Returns a notifier. If there is no unprocessed notifier, it returns +nil+.
|
400
468
|
*/
|
401
469
|
VALUE
|
402
|
-
pgconn_get_notify( VALUE
|
470
|
+
pgconn_get_notify( VALUE conn)
|
403
471
|
{
|
404
472
|
struct pgconn_data *c;
|
405
473
|
PGnotify *notify;
|
406
474
|
VALUE rel, pid, ext;
|
407
475
|
VALUE ret;
|
408
476
|
|
409
|
-
|
477
|
+
c = get_pgconn( conn);
|
410
478
|
if (PQconsumeInput( c->conn) == 0)
|
411
479
|
pg_raise_connexec( c);
|
412
480
|
notify = PQnotifies( c->conn);
|
@@ -435,7 +503,7 @@ pgconn_get_notify( VALUE self)
|
|
435
503
|
*
|
436
504
|
*/
|
437
505
|
VALUE
|
438
|
-
pgconn_transaction( int argc, VALUE *argv, VALUE
|
506
|
+
pgconn_transaction( int argc, VALUE *argv, VALUE conn)
|
439
507
|
{
|
440
508
|
struct pgconn_data *c;
|
441
509
|
VALUE ser, ro;
|
@@ -443,50 +511,50 @@ pgconn_transaction( int argc, VALUE *argv, VALUE self)
|
|
443
511
|
int p;
|
444
512
|
|
445
513
|
rb_scan_args( argc, argv, "02", &ser, &ro);
|
446
|
-
cmd = rb_str_buf_new2( "
|
514
|
+
cmd = rb_str_buf_new2( "BEGIN");
|
447
515
|
p = 0;
|
448
516
|
if (!NIL_P( ser)) {
|
449
|
-
rb_str_buf_cat2( cmd, "
|
450
|
-
rb_str_buf_cat2( cmd, RTEST(ser) ? "
|
517
|
+
rb_str_buf_cat2( cmd, " ISOLATION LEVEL ");
|
518
|
+
rb_str_buf_cat2( cmd, RTEST(ser) ? "SERIALIZABLE" : "READ COMMITTED");
|
451
519
|
p++;
|
452
520
|
}
|
453
521
|
if (!NIL_P( ro)) {
|
454
522
|
if (p) rb_str_buf_cat2( cmd, ",");
|
455
|
-
rb_str_buf_cat2( cmd, "
|
456
|
-
rb_str_buf_cat2( cmd, (RTEST(ro) ? "
|
523
|
+
rb_str_buf_cat2( cmd, " READ ");
|
524
|
+
rb_str_buf_cat2( cmd, (RTEST(ro) ? "ONLY" : "WRITE"));
|
457
525
|
}
|
458
526
|
rb_str_buf_cat2( cmd, ";");
|
459
527
|
|
460
|
-
|
528
|
+
c = get_pgconn( conn);
|
461
529
|
if (PQtransactionStatus( c->conn) > PQTRANS_IDLE)
|
462
530
|
rb_raise( rb_ePgConnTrans,
|
463
531
|
"Nested transaction block. Use Conn#subtransaction.");
|
464
|
-
pgresult_clear( pg_statement_exec(
|
465
|
-
return rb_ensure( yield_transaction,
|
532
|
+
pgresult_clear( pg_statement_exec( conn, cmd, Qnil));
|
533
|
+
return rb_ensure( yield_transaction, conn, commit_transaction, conn);
|
466
534
|
}
|
467
535
|
|
468
536
|
VALUE
|
469
|
-
yield_transaction( VALUE
|
537
|
+
yield_transaction( VALUE conn)
|
470
538
|
{
|
471
|
-
return rb_rescue( rb_yield,
|
539
|
+
return rb_rescue( rb_yield, conn, rollback_transaction, conn);
|
472
540
|
}
|
473
541
|
|
474
542
|
VALUE
|
475
|
-
rollback_transaction( VALUE
|
543
|
+
rollback_transaction( VALUE conn, VALUE err)
|
476
544
|
{
|
477
|
-
pgresult_clear( pg_statement_exec(
|
478
|
-
rb_exc_raise(
|
545
|
+
pgresult_clear( pg_statement_exec( conn, rb_str_new2( "ROLLBACK;"), Qnil));
|
546
|
+
rb_exc_raise( err);
|
479
547
|
return Qnil;
|
480
548
|
}
|
481
549
|
|
482
550
|
VALUE
|
483
|
-
commit_transaction( VALUE
|
551
|
+
commit_transaction( VALUE conn)
|
484
552
|
{
|
485
553
|
struct pgconn_data *c;
|
486
554
|
|
487
|
-
|
555
|
+
c = get_pgconn( conn);
|
488
556
|
if (PQtransactionStatus( c->conn) > PQTRANS_IDLE)
|
489
|
-
pgresult_clear( pg_statement_exec(
|
557
|
+
pgresult_clear( pg_statement_exec( conn, rb_str_new2( "COMMIT;"), Qnil));
|
490
558
|
return Qnil;
|
491
559
|
}
|
492
560
|
|
@@ -508,13 +576,13 @@ pgconn_subtransaction( int argc, VALUE *argv, VALUE self)
|
|
508
576
|
char *p;
|
509
577
|
int n;
|
510
578
|
|
511
|
-
|
579
|
+
c = get_pgconn( self);
|
512
580
|
a = rb_scan_args( argc, argv, "1*", &sp, &par);
|
513
581
|
StringValue( sp);
|
514
582
|
if (a > 1)
|
515
583
|
sp = rb_str_format(RARRAY_LEN(par), RARRAY_PTR(par), sp);
|
516
584
|
|
517
|
-
cmd = rb_str_buf_new2( "
|
585
|
+
cmd = rb_str_buf_new2( "SAVEPOINT ");
|
518
586
|
q = pgconn_destring( c, sp, &n);
|
519
587
|
p = PQescapeIdentifier( c->conn, q, n);
|
520
588
|
rb_str_buf_cat2( cmd, p);
|
@@ -533,16 +601,16 @@ yield_subtransaction( VALUE ary)
|
|
533
601
|
}
|
534
602
|
|
535
603
|
VALUE
|
536
|
-
rollback_subtransaction( VALUE ary)
|
604
|
+
rollback_subtransaction( VALUE ary, VALUE err)
|
537
605
|
{
|
538
606
|
VALUE cmd;
|
539
607
|
|
540
|
-
cmd = rb_str_buf_new2( "
|
608
|
+
cmd = rb_str_buf_new2( "ROLLBACK TO SAVEPOINT ");
|
541
609
|
rb_str_buf_append( cmd, rb_ary_entry( ary, 1));
|
542
610
|
rb_str_buf_cat2( cmd, ";");
|
543
611
|
pgresult_clear( pg_statement_exec( rb_ary_entry( ary, 0), cmd, Qnil));
|
544
612
|
rb_ary_store( ary, 1, Qnil);
|
545
|
-
rb_exc_raise(
|
613
|
+
rb_exc_raise( err);
|
546
614
|
return Qnil;
|
547
615
|
}
|
548
616
|
|
@@ -554,7 +622,7 @@ release_subtransaction( VALUE ary)
|
|
554
622
|
|
555
623
|
n = rb_ary_entry( ary, 1);
|
556
624
|
if (!NIL_P( n)) {
|
557
|
-
cmd = rb_str_buf_new2( "
|
625
|
+
cmd = rb_str_buf_new2( "RELEASE SAVEPOINT ");
|
558
626
|
rb_str_buf_append( cmd, n);
|
559
627
|
rb_str_buf_cat2( cmd, ";");
|
560
628
|
pgresult_clear( pg_statement_exec( rb_ary_entry( ary, 0), cmd, Qnil));
|
@@ -582,7 +650,7 @@ pgconn_transaction_status( VALUE self)
|
|
582
650
|
{
|
583
651
|
struct pgconn_data *c;
|
584
652
|
|
585
|
-
|
653
|
+
c = get_pgconn( self);
|
586
654
|
return INT2FIX( PQtransactionStatus( c->conn));
|
587
655
|
}
|
588
656
|
|
@@ -597,7 +665,7 @@ pgconn_transaction_status( VALUE self)
|
|
597
665
|
*
|
598
666
|
* conn.copy_stdin "COPY t FROM STDIN;" do
|
599
667
|
* ary = ...
|
600
|
-
* l = stringize_line ary
|
668
|
+
* l = conn.stringize_line ary
|
601
669
|
* conn.put l
|
602
670
|
* end
|
603
671
|
*
|
@@ -622,10 +690,10 @@ put_end( VALUE self)
|
|
622
690
|
int r;
|
623
691
|
PGresult *res;
|
624
692
|
|
625
|
-
|
693
|
+
c = get_pgconn( self);
|
626
694
|
/*
|
627
695
|
* I would like to hand over something like
|
628
|
-
* RSTRING_PTR( rb_obj_as_string(
|
696
|
+
* RSTRING_PTR( rb_obj_as_string( rb_errinfo()))
|
629
697
|
* here but when execution is inside a rescue block
|
630
698
|
* the error info will be non-null even though the
|
631
699
|
* exception just has been caught.
|
@@ -682,7 +750,7 @@ pgconn_putline( VALUE self, VALUE arg)
|
|
682
750
|
str = t;
|
683
751
|
}
|
684
752
|
|
685
|
-
|
753
|
+
c = get_pgconn( self);
|
686
754
|
p = pgconn_destring( c, str, &l);
|
687
755
|
r = PQputCopyData( c->conn, p, l);
|
688
756
|
if (r < 0)
|
@@ -734,7 +802,7 @@ get_end( VALUE self)
|
|
734
802
|
struct pgconn_data *c;
|
735
803
|
PGresult *res;
|
736
804
|
|
737
|
-
|
805
|
+
c = get_pgconn( self);
|
738
806
|
if ((res = PQgetResult( c->conn)) != NULL)
|
739
807
|
pgresult_new( res, c, Qnil, Qnil);
|
740
808
|
return Qnil;
|
@@ -765,7 +833,7 @@ pgconn_getline( int argc, VALUE *argv, VALUE self)
|
|
765
833
|
|
766
834
|
async = rb_scan_args( argc, argv, "01", &as) > 0 && !NIL_P( as) ? 1 : 0;
|
767
835
|
|
768
|
-
|
836
|
+
c = get_pgconn( self);
|
769
837
|
r = PQgetCopyData( c->conn, &b, async);
|
770
838
|
if (r > 0) {
|
771
839
|
VALUE ret;
|
@@ -799,7 +867,7 @@ pgconn_each_line( VALUE self)
|
|
799
867
|
int r;
|
800
868
|
VALUE s;
|
801
869
|
|
802
|
-
|
870
|
+
c = get_pgconn( self);
|
803
871
|
for (; (r = PQgetCopyData( c->conn, &b, 0)) > 0;) {
|
804
872
|
s = pgconn_mkstringn( c, b, r);
|
805
873
|
PQfreemem( b);
|
@@ -869,16 +937,17 @@ Init_pgsql_conn_exec( void)
|
|
869
937
|
rb_cPgConn = rb_define_class_under( rb_mPg, "Conn", rb_cObject);
|
870
938
|
#endif
|
871
939
|
|
872
|
-
rb_ePgConnExec
|
873
|
-
|
874
|
-
|
940
|
+
rb_ePgConnExec = rb_define_class_under( rb_cPgConn, "ExecError", rb_ePgError);
|
941
|
+
rb_ePgConnTimeout = rb_define_class_under( rb_cPgConn, "Timeout", rb_ePgError);
|
942
|
+
rb_ePgConnTrans = rb_define_class_under( rb_cPgConn, "TransactionError", rb_ePgError);
|
943
|
+
rb_ePgConnCopy = rb_define_class_under( rb_cPgConn, "CopyError", rb_ePgError);
|
875
944
|
|
876
945
|
rb_define_method( rb_cPgConn, "exec", &pgconn_exec, -1);
|
877
946
|
rb_define_method( rb_cPgConn, "send", &pgconn_send, -1);
|
878
|
-
rb_define_method( rb_cPgConn, "fetch", &pgconn_fetch,
|
947
|
+
rb_define_method( rb_cPgConn, "fetch", &pgconn_fetch, -1);
|
879
948
|
|
880
949
|
rb_define_method( rb_cPgConn, "query", &pgconn_query, -1);
|
881
|
-
rb_define_method( rb_cPgConn, "
|
950
|
+
rb_define_method( rb_cPgConn, "select_row", &pgconn_select_row, -1);
|
882
951
|
rb_define_method( rb_cPgConn, "select_value", &pgconn_select_value, -1);
|
883
952
|
rb_define_method( rb_cPgConn, "select_values", &pgconn_select_values, -1);
|
884
953
|
rb_define_method( rb_cPgConn, "get_notify", &pgconn_get_notify, 0);
|
@@ -908,6 +977,6 @@ Init_pgsql_conn_exec( void)
|
|
908
977
|
|
909
978
|
rb_define_method( rb_cPgConn, "backup", &pgconn_backup, 1);
|
910
979
|
|
911
|
-
|
980
|
+
id_to_a = 0;
|
912
981
|
}
|
913
982
|
|
data/lib/conn_quote.c
CHANGED
@@ -23,7 +23,8 @@ extern VALUE pgconn_for_copy( VALUE self, VALUE str);
|
|
23
23
|
static int needs_dquote_string( VALUE str);
|
24
24
|
static VALUE dquote_string( VALUE str);
|
25
25
|
static VALUE stringize_array( VALUE self, VALUE result, VALUE ary);
|
26
|
-
static VALUE gsub_escape_i(
|
26
|
+
static VALUE gsub_escape_i( RB_BLOCK_CALL_FUNC_ARGLIST( c, arg));
|
27
|
+
|
27
28
|
|
28
29
|
static VALUE pgconn_quote( VALUE self, VALUE obj);
|
29
30
|
static VALUE pgconn_quote_all( int argc, VALUE *argv, VALUE self);
|
@@ -199,11 +200,11 @@ pgconn_unescape_bytea( VALUE self, VALUE obj)
|
|
199
200
|
size_t l;
|
200
201
|
VALUE ret;
|
201
202
|
|
202
|
-
if (NIL_P( obj))
|
203
|
-
return Qnil;
|
204
203
|
#ifdef RUBY_ENCODING
|
205
204
|
rb_scan_args( argc, argv, "11", &obj, &enc);
|
206
205
|
#endif
|
206
|
+
if (NIL_P( obj))
|
207
|
+
return Qnil;
|
207
208
|
StringValue( obj);
|
208
209
|
|
209
210
|
s = PQunescapeBytea( (unsigned char *) RSTRING_PTR( obj), &l);
|
@@ -319,7 +320,7 @@ pgconn_stringize_line( VALUE self, VALUE ary)
|
|
319
320
|
VALUE a;
|
320
321
|
VALUE *p;
|
321
322
|
int l;
|
322
|
-
VALUE ret
|
323
|
+
VALUE ret;
|
323
324
|
|
324
325
|
a = rb_check_convert_type( ary, T_ARRAY, "Array", "to_ary");
|
325
326
|
if (NIL_P(a))
|
@@ -411,13 +412,13 @@ dquote_string( VALUE str)
|
|
411
412
|
VALUE
|
412
413
|
stringize_array( VALUE self, VALUE result, VALUE ary)
|
413
414
|
{
|
414
|
-
long i
|
415
|
+
long i;
|
415
416
|
VALUE *o;
|
416
417
|
VALUE cf, co;
|
417
418
|
VALUE r;
|
418
419
|
|
419
420
|
cf = Qundef;
|
420
|
-
for (o = RARRAY_PTR( ary),
|
421
|
+
for (o = RARRAY_PTR( ary), i = RARRAY_LEN( ary); i; ++o, --i) {
|
421
422
|
co = CLASS_OF( *o);
|
422
423
|
if (cf == Qundef)
|
423
424
|
cf = co;
|
@@ -438,7 +439,7 @@ stringize_array( VALUE self, VALUE result, VALUE ary)
|
|
438
439
|
|
439
440
|
|
440
441
|
VALUE
|
441
|
-
gsub_escape_i(
|
442
|
+
gsub_escape_i( RB_BLOCK_CALL_FUNC_ARGLIST( c, arg))
|
442
443
|
{
|
443
444
|
const char *r;
|
444
445
|
|
@@ -471,7 +472,7 @@ gsub_escape_i( VALUE c, VALUE arg)
|
|
471
472
|
* This method is to prevent you from saying something like <code>"insert into
|
472
473
|
* ... (E'#{conn.stringize obj}', ...);"</code>. It is more efficient to say
|
473
474
|
*
|
474
|
-
* conn.exec "
|
475
|
+
* conn.exec "INSERT INTO ... (#{conn.quote obj}, ...);"
|
475
476
|
*
|
476
477
|
* Your self-defined classes will be checked whether they have a method named
|
477
478
|
* +to_postgres+. If that doesn't exist the object will be converted by
|
@@ -516,25 +517,25 @@ VALUE pgconn_quote( VALUE self, VALUE obj)
|
|
516
517
|
co = CLASS_OF( obj);
|
517
518
|
if (co == rb_cTime) {
|
518
519
|
res = rb_funcall( obj, id_iso8601, 0);
|
519
|
-
type = "
|
520
|
+
type = "TIMESTAMPTZ";
|
520
521
|
} else if (co == rb_cDate) {
|
521
522
|
res = rb_obj_as_string( obj);
|
522
|
-
type = "
|
523
|
+
type = "DATE";
|
523
524
|
} else if (co == rb_cDateTime) {
|
524
525
|
res = rb_obj_as_string( obj);
|
525
|
-
type = "
|
526
|
+
type = "TIMESTAMPTZ";
|
526
527
|
} else if (co == pg_monetary_class() &&
|
527
528
|
rb_respond_to( obj, id_raw)) {
|
528
529
|
res = rb_funcall( obj, id_raw, 0);
|
529
530
|
StringValue( res);
|
530
|
-
type = "
|
531
|
+
type = "MONEY";
|
531
532
|
} else if (rb_respond_to( obj, id_to_postgres)) {
|
532
533
|
res = rb_funcall( obj, id_to_postgres, 0);
|
533
534
|
StringValue( res);
|
534
535
|
type = NULL;
|
535
536
|
} else {
|
536
537
|
res = rb_obj_as_string( obj);
|
537
|
-
type = "
|
538
|
+
type = "UNKNOWN";
|
538
539
|
}
|
539
540
|
res = quote_string( self, res);
|
540
541
|
if (type != NULL) {
|
@@ -584,12 +585,12 @@ quote_string( VALUE conn, VALUE str)
|
|
584
585
|
VALUE
|
585
586
|
quote_array( VALUE self, VALUE result, VALUE ary)
|
586
587
|
{
|
587
|
-
long i
|
588
|
+
long i;
|
588
589
|
VALUE *o;
|
589
590
|
VALUE cf, co;
|
590
591
|
|
591
592
|
cf = Qundef;
|
592
|
-
for (o = RARRAY_PTR( ary),
|
593
|
+
for (o = RARRAY_PTR( ary), i = RARRAY_LEN( ary); i; ++o, --i) {
|
593
594
|
co = CLASS_OF( *o);
|
594
595
|
if (cf == Qundef)
|
595
596
|
cf = co;
|
data/lib/mkrf_conf
CHANGED
@@ -10,27 +10,19 @@ Autorake.configure {
|
|
10
10
|
|
11
11
|
extending_ruby
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
have_header "st.h"
|
17
|
-
else
|
18
|
-
have_header "ruby/ruby.h"
|
19
|
-
have_header "ruby/io.h"
|
20
|
-
end
|
13
|
+
need_header "ruby/ruby.h"
|
14
|
+
need_header "ruby/io.h"
|
15
|
+
|
21
16
|
|
22
17
|
incdir :postgres, `pg_config --pkgincludedir`
|
23
18
|
incdir :postgres_server, `pg_config --includedir-server`
|
24
19
|
|
25
|
-
|
26
|
-
have_library "ssl"
|
27
|
-
have_library "pq"
|
20
|
+
need_library "pq"
|
28
21
|
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
need_header "postgres.h"
|
23
|
+
need_header "libpq-fe.h"
|
24
|
+
need_header "catalog/pg_type.h"
|
32
25
|
|
33
|
-
have_func "rb_errinfo"
|
34
26
|
have_func "rb_io_stdio_file"
|
35
27
|
have_func "rb_locale_encoding"
|
36
28
|
|
data/lib/module.c
CHANGED
data/lib/module.h
CHANGED
@@ -18,15 +18,9 @@
|
|
18
18
|
#endif
|
19
19
|
#include "undef.h"
|
20
20
|
|
21
|
-
#
|
22
|
-
|
23
|
-
#
|
24
|
-
#ifdef HAVE_HEADER_LIBPQ_FE_H
|
25
|
-
#include <libpq-fe.h>
|
26
|
-
#endif
|
27
|
-
#ifdef HAVE_HEADER_CATALOG_PG_TYPE_H
|
28
|
-
#include <catalog/pg_type.h>
|
29
|
-
#endif
|
21
|
+
#include <postgres.h>
|
22
|
+
#include <libpq-fe.h>
|
23
|
+
#include <catalog/pg_type.h>
|
30
24
|
#include "undef.h"
|
31
25
|
|
32
26
|
|
data/lib/result.c
CHANGED
@@ -11,9 +11,6 @@
|
|
11
11
|
static void pgresult_init( struct pgresult_data *r, PGresult *result, struct pgconn_data *conn);
|
12
12
|
static VALUE pgreserror_new( VALUE result, VALUE cmd, VALUE par);
|
13
13
|
|
14
|
-
static VALUE pgreserror_command( VALUE self);
|
15
|
-
static VALUE pgreserror_params( VALUE self);
|
16
|
-
|
17
14
|
static struct pgresult_data *pgreserror_result( VALUE self);
|
18
15
|
static VALUE pgreserror_status( VALUE self);
|
19
16
|
static VALUE pgreserror_sqlst( VALUE self);
|
@@ -25,7 +22,6 @@ static VALUE pgreserror_diag( VALUE self, VALUE field);
|
|
25
22
|
|
26
23
|
static VALUE pgresult_s_translate_results_set( VALUE cls, VALUE fact);
|
27
24
|
|
28
|
-
static void pgresult_mark( struct pgresult_data *ptr);
|
29
25
|
static void pgresult_free( struct pgresult_data *ptr);
|
30
26
|
extern VALUE pgresult_new( PGresult *result, struct pgconn_data *conn, VALUE cmd, VALUE par);
|
31
27
|
|
@@ -214,13 +210,6 @@ pgresult_s_translate_results_set( VALUE cls, VALUE fact)
|
|
214
210
|
|
215
211
|
|
216
212
|
|
217
|
-
void
|
218
|
-
pgresult_mark( struct pgresult_data *ptr)
|
219
|
-
{
|
220
|
-
rb_gc_mark( ptr->fields);
|
221
|
-
rb_gc_mark( ptr->indices);
|
222
|
-
}
|
223
|
-
|
224
213
|
void
|
225
214
|
pgresult_free( struct pgresult_data *ptr)
|
226
215
|
{
|
@@ -252,6 +241,8 @@ pgresult_new( PGresult *result, struct pgconn_data *conn, VALUE cmd, VALUE par)
|
|
252
241
|
case PGRES_TUPLES_OK:
|
253
242
|
case PGRES_COPY_OUT:
|
254
243
|
case PGRES_COPY_IN:
|
244
|
+
case PGRES_COPY_BOTH:
|
245
|
+
case PGRES_SINGLE_TUPLE:
|
255
246
|
break;
|
256
247
|
case PGRES_BAD_RESPONSE:
|
257
248
|
case PGRES_NONFATAL_ERROR:
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgsql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.9'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bertram Scharpf
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: autorake
|
@@ -55,7 +55,7 @@ homepage: http://www.bertram-scharpf.de/software/pgsql
|
|
55
55
|
licenses:
|
56
56
|
- BSD-2-Clause
|
57
57
|
metadata: {}
|
58
|
-
post_install_message:
|
58
|
+
post_install_message:
|
59
59
|
rdoc_options:
|
60
60
|
- "--main"
|
61
61
|
- README
|
@@ -73,8 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
version: '0'
|
74
74
|
requirements:
|
75
75
|
- PostgreSQL
|
76
|
-
rubygems_version: 3.0.
|
77
|
-
signing_key:
|
76
|
+
rubygems_version: 3.0.8
|
77
|
+
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: PostgreSQL-API for Ruby
|
80
80
|
test_files: []
|