pgsql 1.9.2 → 1.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/conn.c +36 -22
- data/lib/conn_exec.c +7 -7
- data/lib/module.c +1 -1
- data/lib/result.c +84 -47
- data/lib/result.h +8 -5
- data/lib/undef.h +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc0106f3924d41c61e9f64a26231d1cd464a1e989ee06b8282805387dc244fe0
|
4
|
+
data.tar.gz: 90c900d16b8b8d97c0357a04f1fc3ad6235932e626b591126c0d57b6f7b234b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e20984f294736af96653d37a3fd855373b94b4911035e901d9ba97536fb600ae0fe99ede1c967e77c84ffb301b3a62f1a00643145cc4464567f0464f23fdee14
|
7
|
+
data.tar.gz: 6edd020112c1313e0a25f4a8c6186895193a609d91a0aee893a6828192a7c198c8368475fc2f001e8c04c79b545735272724728fb689b778cef9e62f8ff7f51c
|
data/lib/conn.c
CHANGED
@@ -16,8 +16,9 @@
|
|
16
16
|
extern void pg_check_conninvalid( struct pgconn_data *c);
|
17
17
|
static VALUE pgconnfailederror_new( struct pgconn_data *c, VALUE params);
|
18
18
|
|
19
|
-
static void
|
20
|
-
static void
|
19
|
+
static void pgconn_mark( void *ptr);
|
20
|
+
static void pgconn_free( void *ptr);
|
21
|
+
static size_t pgconn_memsize( const void *ptr);
|
21
22
|
extern struct pgconn_data *get_pgconn( VALUE obj);
|
22
23
|
static VALUE pgconn_encode_in4out( struct pgconn_data *ptr, VALUE str);
|
23
24
|
extern const char *pgconn_destring( struct pgconn_data *ptr, VALUE str, int *len);
|
@@ -76,6 +77,12 @@ static VALUE sym_password = Qundef;
|
|
76
77
|
|
77
78
|
static ID id_to_s;
|
78
79
|
|
80
|
+
static const rb_data_type_t pgconn_data_data_type = {
|
81
|
+
"pgsql:pgconn_data",
|
82
|
+
{ &pgconn_mark, &pgconn_free, &pgconn_memsize,},
|
83
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
84
|
+
};
|
85
|
+
|
79
86
|
|
80
87
|
void
|
81
88
|
pg_check_conninvalid( struct pgconn_data *c)
|
@@ -99,21 +106,29 @@ pgconnfailederror_new( struct pgconn_data *c, VALUE params)
|
|
99
106
|
|
100
107
|
|
101
108
|
void
|
102
|
-
pgconn_mark(
|
109
|
+
pgconn_mark( void *ptr)
|
103
110
|
{
|
104
|
-
|
111
|
+
struct pgconn_data *pd = ptr;
|
105
112
|
#ifdef RUBY_ENCODING
|
106
|
-
rb_gc_mark(
|
107
|
-
rb_gc_mark(
|
113
|
+
rb_gc_mark( pd->external);
|
114
|
+
rb_gc_mark( pd->internal);
|
108
115
|
#endif
|
116
|
+
rb_gc_mark( pd->notice);
|
109
117
|
}
|
110
118
|
|
111
119
|
void
|
112
|
-
pgconn_free(
|
120
|
+
pgconn_free( void *ptr)
|
121
|
+
{
|
122
|
+
struct pgconn_data *pd = ptr;
|
123
|
+
if (pd->conn != NULL)
|
124
|
+
PQfinish( pd->conn);
|
125
|
+
ruby_xfree( ptr);
|
126
|
+
}
|
127
|
+
|
128
|
+
static size_t
|
129
|
+
pgconn_memsize( const void *ptr)
|
113
130
|
{
|
114
|
-
|
115
|
-
PQfinish( ptr->conn);
|
116
|
-
free( ptr);
|
131
|
+
return sizeof (struct pgconn_data);
|
117
132
|
}
|
118
133
|
|
119
134
|
struct pgconn_data *
|
@@ -121,7 +136,7 @@ get_pgconn( VALUE obj)
|
|
121
136
|
{
|
122
137
|
struct pgconn_data *c;
|
123
138
|
|
124
|
-
|
139
|
+
TypedData_Get_Struct( obj, struct pgconn_data, &pgconn_data_data_type, c);
|
125
140
|
pg_check_conninvalid( c);
|
126
141
|
return c;
|
127
142
|
}
|
@@ -190,17 +205,16 @@ VALUE
|
|
190
205
|
pgconn_alloc( VALUE cls)
|
191
206
|
{
|
192
207
|
struct pgconn_data *c;
|
193
|
-
VALUE
|
208
|
+
VALUE obj;
|
194
209
|
|
195
|
-
|
196
|
-
&pgconn_mark, &pgconn_free, c);
|
210
|
+
obj = TypedData_Make_Struct( cls, struct pgconn_data, &pgconn_data_data_type, c);
|
197
211
|
c->conn = NULL;
|
198
212
|
#ifdef RUBY_ENCODING
|
199
213
|
c->external = rb_enc_from_encoding( rb_default_external_encoding());
|
200
214
|
c->internal = rb_enc_from_encoding( rb_default_internal_encoding());
|
201
215
|
#endif
|
202
216
|
c->notice = Qnil;
|
203
|
-
return
|
217
|
+
return obj;
|
204
218
|
}
|
205
219
|
|
206
220
|
/*
|
@@ -287,7 +301,7 @@ pgconn_init( int argc, VALUE *argv, VALUE self)
|
|
287
301
|
str = Qnil;
|
288
302
|
}
|
289
303
|
|
290
|
-
|
304
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
291
305
|
|
292
306
|
if (NIL_P( params)) {
|
293
307
|
c->conn = PQconnectdb( RSTRING_PTR( rb_funcall( str, id_to_s, 0)));
|
@@ -405,7 +419,7 @@ pgconn_close( VALUE self)
|
|
405
419
|
{
|
406
420
|
struct pgconn_data *c;
|
407
421
|
|
408
|
-
|
422
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
409
423
|
PQfinish( c->conn);
|
410
424
|
c->conn = NULL;
|
411
425
|
return Qnil;
|
@@ -470,7 +484,7 @@ pgconn_externalenc( VALUE self)
|
|
470
484
|
{
|
471
485
|
struct pgconn_data *c;
|
472
486
|
|
473
|
-
|
487
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
474
488
|
return c->external;
|
475
489
|
}
|
476
490
|
|
@@ -487,7 +501,7 @@ pgconn_set_externalenc( VALUE self, VALUE enc)
|
|
487
501
|
rb_encoding *e;
|
488
502
|
|
489
503
|
e = NIL_P( enc) ? rb_to_encoding( enc) : rb_default_external_encoding();
|
490
|
-
|
504
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
491
505
|
c->external = rb_enc_from_encoding( e);
|
492
506
|
|
493
507
|
return Qnil;
|
@@ -504,7 +518,7 @@ pgconn_internalenc( VALUE self)
|
|
504
518
|
{
|
505
519
|
struct pgconn_data *c;
|
506
520
|
|
507
|
-
|
521
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
508
522
|
return c->internal;
|
509
523
|
}
|
510
524
|
|
@@ -521,7 +535,7 @@ pgconn_set_internalenc( VALUE self, VALUE enc)
|
|
521
535
|
rb_encoding *e;
|
522
536
|
|
523
537
|
e = NIL_P( enc) ? rb_to_encoding( enc) : rb_default_internal_encoding();
|
524
|
-
|
538
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
525
539
|
c->internal = rb_enc_from_encoding( e);
|
526
540
|
|
527
541
|
return Qnil;
|
@@ -785,7 +799,7 @@ pgconn_on_notice( VALUE self)
|
|
785
799
|
{
|
786
800
|
struct pgconn_data *c;
|
787
801
|
|
788
|
-
|
802
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
789
803
|
if (PQsetNoticeReceiver( c->conn, NULL, NULL) != ¬ice_receiver) {
|
790
804
|
PQsetNoticeReceiver( c->conn, ¬ice_receiver, (void *) c);
|
791
805
|
}
|
data/lib/conn_exec.c
CHANGED
@@ -93,7 +93,7 @@ pg_statement_exec( VALUE conn, VALUE cmd, VALUE par)
|
|
93
93
|
}
|
94
94
|
if (result == NULL)
|
95
95
|
pg_raise_connexec( c);
|
96
|
-
return pgresult_new( result,
|
96
|
+
return pgresult_new( result, conn, cmd, par);
|
97
97
|
}
|
98
98
|
|
99
99
|
|
@@ -268,7 +268,7 @@ pgconn_fetch( int argc, VALUE *argv, VALUE conn)
|
|
268
268
|
while ((result = PQgetResult( c->conn)) != NULL) {
|
269
269
|
VALUE res;
|
270
270
|
|
271
|
-
res = pgresult_new( result,
|
271
|
+
res = pgresult_new( result, conn, Qnil, Qnil);
|
272
272
|
rb_ensure( rb_yield, res, pgresult_clear, res);
|
273
273
|
}
|
274
274
|
return Qnil;
|
@@ -430,7 +430,7 @@ pgconn_select_row( int argc, VALUE *argv, VALUE self)
|
|
430
430
|
pg_parse_parameters( argc, argv, &cmd, &par);
|
431
431
|
res = pg_statement_exec( self, cmd, par);
|
432
432
|
|
433
|
-
|
433
|
+
TypedData_Get_Struct( res, struct pgresult_data, &pgresult_data_data_type, r);
|
434
434
|
return pg_fetchrow( r, 0);
|
435
435
|
}
|
436
436
|
|
@@ -451,7 +451,7 @@ pgconn_select_value( int argc, VALUE *argv, VALUE self)
|
|
451
451
|
pg_parse_parameters( argc, argv, &cmd, &par);
|
452
452
|
res = pg_statement_exec( self, cmd, par);
|
453
453
|
|
454
|
-
|
454
|
+
TypedData_Get_Struct( res, struct pgresult_data, &pgresult_data_data_type, r);
|
455
455
|
return PQntuples( r->res) > 0 && PQnfields( r->res) > 0 ?
|
456
456
|
pg_fetchresult( r, 0, 0) : Qnil;
|
457
457
|
}
|
@@ -476,7 +476,7 @@ pgconn_select_values( int argc, VALUE *argv, VALUE self)
|
|
476
476
|
pg_parse_parameters( argc, argv, &cmd, &par);
|
477
477
|
res = pg_statement_exec( self, cmd, par);
|
478
478
|
|
479
|
-
|
479
|
+
TypedData_Get_Struct( res, struct pgresult_data, &pgresult_data_data_type, r);
|
480
480
|
m = PQntuples( r->res), n = PQnfields( r->res);
|
481
481
|
l = m * n;
|
482
482
|
if (l == 0)
|
@@ -735,7 +735,7 @@ put_end( VALUE self)
|
|
735
735
|
if (r < 0)
|
736
736
|
rb_raise( rb_ePgConnCopy, "Copy from stdin failed to finish.");
|
737
737
|
while ((res = PQgetResult( c->conn)) != NULL)
|
738
|
-
pgresult_new( res,
|
738
|
+
pgresult_new( res, self, Qnil, Qnil);
|
739
739
|
return Qnil;
|
740
740
|
}
|
741
741
|
|
@@ -836,7 +836,7 @@ get_end( VALUE self)
|
|
836
836
|
|
837
837
|
c = get_pgconn( self);
|
838
838
|
if ((res = PQgetResult( c->conn)) != NULL)
|
839
|
-
pgresult_new( res,
|
839
|
+
pgresult_new( res, self, Qnil, Qnil);
|
840
840
|
return Qnil;
|
841
841
|
}
|
842
842
|
|
data/lib/module.c
CHANGED
data/lib/result.c
CHANGED
@@ -8,7 +8,6 @@
|
|
8
8
|
#include "conn_quote.h"
|
9
9
|
|
10
10
|
|
11
|
-
static void pgresult_init( struct pgresult_data *r, PGresult *result, struct pgconn_data *conn);
|
12
11
|
static VALUE pgreserror_new( VALUE result, VALUE cmd, VALUE par);
|
13
12
|
|
14
13
|
static struct pgresult_data *pgreserror_result( VALUE self);
|
@@ -22,8 +21,11 @@ static VALUE pgreserror_diag( VALUE self, VALUE field);
|
|
22
21
|
|
23
22
|
static VALUE pgresult_s_translate_results_set( VALUE cls, VALUE fact);
|
24
23
|
|
25
|
-
static void
|
26
|
-
|
24
|
+
static void pgresult_mark( void *ptr);
|
25
|
+
static void pgresult_free( void *ptr);
|
26
|
+
static size_t pgresult_memsize( const void *ptr);
|
27
|
+
static VALUE pgresult_alloc( VALUE cls);
|
28
|
+
extern VALUE pgresult_new( PGresult *result, VALUE conn, VALUE cmd, VALUE par);
|
27
29
|
|
28
30
|
extern VALUE pgresult_clear( VALUE self);
|
29
31
|
|
@@ -64,6 +66,14 @@ static int translate_results = 1;
|
|
64
66
|
|
65
67
|
|
66
68
|
|
69
|
+
const rb_data_type_t pgresult_data_data_type = {
|
70
|
+
"mydata",
|
71
|
+
{ &pgresult_mark, &pgresult_free, &pgresult_memsize,},
|
72
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
73
|
+
};
|
74
|
+
|
75
|
+
|
76
|
+
|
67
77
|
|
68
78
|
VALUE
|
69
79
|
pgreserror_new( VALUE result, VALUE cmd, VALUE par)
|
@@ -71,8 +81,8 @@ pgreserror_new( VALUE result, VALUE cmd, VALUE par)
|
|
71
81
|
struct pgresult_data *r;
|
72
82
|
VALUE rse, msg;
|
73
83
|
|
74
|
-
|
75
|
-
msg = pgconn_mkstring( r->conn, PQresultErrorMessage( r->res));
|
84
|
+
TypedData_Get_Struct( result, struct pgresult_data, &pgresult_data_data_type, r);
|
85
|
+
msg = pgconn_mkstring( get_pgconn( r->conn), PQresultErrorMessage( r->res));
|
76
86
|
rse = rb_class_new_instance( 1, &msg, rb_ePgResError);
|
77
87
|
rb_ivar_set( rse, id_result, result);
|
78
88
|
rb_ivar_set( rse, rb_intern( "@command"), cmd);
|
@@ -87,7 +97,7 @@ pgreserror_result( VALUE self)
|
|
87
97
|
{
|
88
98
|
struct pgresult_data *r;
|
89
99
|
|
90
|
-
|
100
|
+
TypedData_Get_Struct( rb_ivar_get( self, id_result), struct pgresult_data, &pgresult_data_data_type, r);
|
91
101
|
return r;
|
92
102
|
}
|
93
103
|
|
@@ -120,7 +130,7 @@ pgreserror_sqlst( VALUE self)
|
|
120
130
|
struct pgresult_data *r;
|
121
131
|
|
122
132
|
r = pgreserror_result( self);
|
123
|
-
return pgconn_mkstring( r->conn, PQresultErrorField( r->res, PG_DIAG_SQLSTATE));
|
133
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQresultErrorField( r->res, PG_DIAG_SQLSTATE));
|
124
134
|
}
|
125
135
|
|
126
136
|
/*
|
@@ -136,7 +146,7 @@ pgreserror_primary( VALUE self)
|
|
136
146
|
struct pgresult_data *r;
|
137
147
|
|
138
148
|
r = pgreserror_result( self);
|
139
|
-
return pgconn_mkstring( r->conn, PQresultErrorField( r->res, PG_DIAG_MESSAGE_PRIMARY));
|
149
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQresultErrorField( r->res, PG_DIAG_MESSAGE_PRIMARY));
|
140
150
|
}
|
141
151
|
|
142
152
|
|
@@ -153,7 +163,7 @@ pgreserror_detail( VALUE self)
|
|
153
163
|
struct pgresult_data *r;
|
154
164
|
|
155
165
|
r = pgreserror_result( self);
|
156
|
-
return pgconn_mkstring( r->conn, PQresultErrorField( r->res, PG_DIAG_MESSAGE_DETAIL));
|
166
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQresultErrorField( r->res, PG_DIAG_MESSAGE_DETAIL));
|
157
167
|
}
|
158
168
|
|
159
169
|
|
@@ -170,7 +180,7 @@ pgreserror_hint( VALUE self)
|
|
170
180
|
struct pgresult_data *r;
|
171
181
|
|
172
182
|
r = pgreserror_result( self);
|
173
|
-
return pgconn_mkstring( r->conn, PQresultErrorField( r->res, PG_DIAG_MESSAGE_HINT));
|
183
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQresultErrorField( r->res, PG_DIAG_MESSAGE_HINT));
|
174
184
|
}
|
175
185
|
|
176
186
|
|
@@ -188,7 +198,7 @@ pgreserror_diag( VALUE self, VALUE field)
|
|
188
198
|
struct pgresult_data *r;
|
189
199
|
|
190
200
|
r = pgreserror_result( self);
|
191
|
-
return pgconn_mkstring( r->conn, PQresultErrorField( r->res, NUM2INT( field)));
|
201
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQresultErrorField( r->res, NUM2INT( field)));
|
192
202
|
}
|
193
203
|
|
194
204
|
|
@@ -211,30 +221,57 @@ pgresult_s_translate_results_set( VALUE cls, VALUE fact)
|
|
211
221
|
|
212
222
|
|
213
223
|
void
|
214
|
-
|
224
|
+
pgresult_mark( void *ptr)
|
215
225
|
{
|
216
|
-
|
217
|
-
|
218
|
-
|
226
|
+
struct pgresult_data *rd = ptr;
|
227
|
+
rb_gc_mark( rd->conn);
|
228
|
+
rb_gc_mark( rd->fields);
|
229
|
+
rb_gc_mark( rd->indices);
|
219
230
|
}
|
220
231
|
|
221
232
|
void
|
222
|
-
|
233
|
+
pgresult_free( void *ptr)
|
223
234
|
{
|
224
|
-
|
225
|
-
|
235
|
+
struct pgresult_data *rd = ptr;
|
236
|
+
if (rd->res != NULL)
|
237
|
+
PQclear( rd->res);
|
238
|
+
ruby_xfree( ptr);
|
239
|
+
}
|
240
|
+
|
241
|
+
size_t
|
242
|
+
pgresult_memsize( const void *ptr)
|
243
|
+
{
|
244
|
+
return sizeof (struct pgresult_data);
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
VALUE
|
250
|
+
pgresult_alloc( VALUE cls)
|
251
|
+
{
|
252
|
+
struct pgresult_data *r;
|
253
|
+
VALUE obj;
|
254
|
+
|
255
|
+
obj = TypedData_Make_Struct( cls, struct pgresult_data, &pgresult_data_data_type, r);
|
256
|
+
r->res = NULL;
|
257
|
+
r->conn = Qnil;
|
226
258
|
r->fields = Qnil;
|
227
259
|
r->indices = Qnil;
|
260
|
+
return obj;
|
228
261
|
}
|
229
262
|
|
230
263
|
VALUE
|
231
|
-
pgresult_new( PGresult *result,
|
264
|
+
pgresult_new( PGresult *result, VALUE conn, VALUE cmd, VALUE par)
|
232
265
|
{
|
233
266
|
struct pgresult_data *r;
|
234
267
|
VALUE res;
|
235
268
|
|
236
|
-
res =
|
237
|
-
|
269
|
+
res = rb_class_new_instance( 0, NULL, rb_cPgResult);
|
270
|
+
TypedData_Get_Struct( res, struct pgresult_data, &pgresult_data_data_type, r);
|
271
|
+
r->res = result;
|
272
|
+
r->conn = conn;
|
273
|
+
r->fields = Qnil;
|
274
|
+
r->indices = Qnil;
|
238
275
|
switch (PQresultStatus( result)) {
|
239
276
|
case PGRES_EMPTY_QUERY:
|
240
277
|
case PGRES_COMMAND_OK:
|
@@ -267,7 +304,7 @@ pgresult_clear( VALUE self)
|
|
267
304
|
{
|
268
305
|
struct pgresult_data *r;
|
269
306
|
|
270
|
-
|
307
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
271
308
|
if (r->res != NULL) {
|
272
309
|
PQclear( r->res);
|
273
310
|
r->res = NULL;
|
@@ -292,7 +329,7 @@ pgresult_status( VALUE self)
|
|
292
329
|
{
|
293
330
|
struct pgresult_data *r;
|
294
331
|
|
295
|
-
|
332
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
296
333
|
return INT2FIX( PQresultStatus( r->res));
|
297
334
|
}
|
298
335
|
|
@@ -313,7 +350,7 @@ pgresult_fields( VALUE self)
|
|
313
350
|
{
|
314
351
|
struct pgresult_data *r;
|
315
352
|
|
316
|
-
|
353
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
317
354
|
if (NIL_P( r->fields)) {
|
318
355
|
VALUE ary;
|
319
356
|
int n, i;
|
@@ -322,7 +359,7 @@ pgresult_fields( VALUE self)
|
|
322
359
|
n = PQnfields( r->res);
|
323
360
|
ary = rb_ary_new2( n);
|
324
361
|
for (i = 0; n; i++, n--) {
|
325
|
-
str = pgconn_mkstring( r->conn, PQfname( r->res, i));
|
362
|
+
str = pgconn_mkstring( get_pgconn( r->conn), PQfname( r->res, i));
|
326
363
|
rb_str_freeze( str);
|
327
364
|
rb_ary_push( ary, str);
|
328
365
|
}
|
@@ -347,7 +384,7 @@ pgresult_field_indices( VALUE self)
|
|
347
384
|
{
|
348
385
|
struct pgresult_data *r;
|
349
386
|
|
350
|
-
|
387
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
351
388
|
if (NIL_P( r->indices)) {
|
352
389
|
VALUE hsh;
|
353
390
|
int n, i;
|
@@ -356,7 +393,7 @@ pgresult_field_indices( VALUE self)
|
|
356
393
|
n = PQnfields( r->res);
|
357
394
|
hsh = rb_hash_new();
|
358
395
|
for (i = 0; n; i++, n--) {
|
359
|
-
str = pgconn_mkstring( r->conn, PQfname( r->res, i));
|
396
|
+
str = pgconn_mkstring( get_pgconn( r->conn), PQfname( r->res, i));
|
360
397
|
rb_str_freeze( str);
|
361
398
|
rb_hash_aset( hsh, str, INT2FIX( i));
|
362
399
|
}
|
@@ -379,7 +416,7 @@ pgresult_num_fields( VALUE self)
|
|
379
416
|
{
|
380
417
|
struct pgresult_data *r;
|
381
418
|
|
382
|
-
|
419
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
383
420
|
return INT2FIX( PQnfields( r->res));
|
384
421
|
}
|
385
422
|
|
@@ -400,8 +437,8 @@ pgresult_fieldname( VALUE self, VALUE index)
|
|
400
437
|
{
|
401
438
|
struct pgresult_data *r;
|
402
439
|
|
403
|
-
|
404
|
-
return pgconn_mkstring( r->conn, PQfname( r->res, NUM2INT( index)));
|
440
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
441
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQfname( r->res, NUM2INT( index)));
|
405
442
|
}
|
406
443
|
|
407
444
|
/*
|
@@ -423,8 +460,8 @@ pgresult_fieldnum( VALUE self, VALUE name)
|
|
423
460
|
int n;
|
424
461
|
|
425
462
|
StringValue( name);
|
426
|
-
|
427
|
-
n = PQfnumber( r->res, pgconn_destring( r->conn, name, NULL));
|
463
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
464
|
+
n = PQfnumber( r->res, pgconn_destring( get_pgconn( r->conn), name, NULL));
|
428
465
|
if (n == -1)
|
429
466
|
rb_raise( rb_eArgError, "Unknown field: %s", RSTRING_PTR( name));
|
430
467
|
return INT2FIX( n);
|
@@ -448,7 +485,7 @@ pgresult_each( VALUE self)
|
|
448
485
|
struct pgresult_data *r;
|
449
486
|
int m, j;
|
450
487
|
|
451
|
-
|
488
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
452
489
|
for (j = 0, m = PQntuples( r->res); m; j++, m--)
|
453
490
|
rb_yield( pg_fetchrow( r, j));
|
454
491
|
return m ? INT2FIX( m) : Qnil;
|
@@ -472,7 +509,7 @@ pgresult_aref( int argc, VALUE *argv, VALUE self)
|
|
472
509
|
VALUE aj, ai;
|
473
510
|
int j, i;
|
474
511
|
|
475
|
-
|
512
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
476
513
|
a = rb_scan_args( argc, argv, "11", &aj, &ai);
|
477
514
|
j = NUM2INT( aj);
|
478
515
|
if (j < PQntuples( r->res)) {
|
@@ -524,7 +561,7 @@ pg_fetchresult( struct pgresult_data *r, int row, int col)
|
|
524
561
|
return Qnil;
|
525
562
|
|
526
563
|
if (!translate_results)
|
527
|
-
return pgconn_mkstring( r->conn, string);
|
564
|
+
return pgconn_mkstring( get_pgconn( r->conn), string);
|
528
565
|
|
529
566
|
typ = PQftype( r->res, col);
|
530
567
|
cls = Qnil;
|
@@ -575,7 +612,7 @@ pg_fetchresult( struct pgresult_data *r, int row, int col)
|
|
575
612
|
break;
|
576
613
|
}
|
577
614
|
if (NIL_P( ret)) {
|
578
|
-
ret = pgconn_mkstring( r->conn, string);
|
615
|
+
ret = pgconn_mkstring( get_pgconn( r->conn), string);
|
579
616
|
if (RTEST( cls))
|
580
617
|
ret = rb_funcall( cls, id_parse, 1, ret);
|
581
618
|
}
|
@@ -595,7 +632,7 @@ pgresult_num_tuples( VALUE self)
|
|
595
632
|
{
|
596
633
|
struct pgresult_data *r;
|
597
634
|
|
598
|
-
|
635
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
599
636
|
return INT2FIX( PQntuples( r->res));
|
600
637
|
}
|
601
638
|
|
@@ -617,7 +654,7 @@ pgresult_type( VALUE self, VALUE index)
|
|
617
654
|
struct pgresult_data *r;
|
618
655
|
int n;
|
619
656
|
|
620
|
-
|
657
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
621
658
|
n = PQftype( r->res, NUM2INT( index));
|
622
659
|
return n ? INT2FIX( n) : Qnil;
|
623
660
|
}
|
@@ -639,7 +676,7 @@ pgresult_size( VALUE self, VALUE index)
|
|
639
676
|
struct pgresult_data *r;
|
640
677
|
int n;
|
641
678
|
|
642
|
-
|
679
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
643
680
|
n = PQfsize( r->res, NUM2INT( index));
|
644
681
|
return n ? INT2FIX( n) : Qnil;
|
645
682
|
}
|
@@ -659,7 +696,7 @@ pgresult_getvalue( VALUE self, VALUE row, VALUE col)
|
|
659
696
|
{
|
660
697
|
struct pgresult_data *r;
|
661
698
|
|
662
|
-
|
699
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
663
700
|
return pg_fetchresult( r, NUM2INT( row), NUM2INT( col));
|
664
701
|
}
|
665
702
|
|
@@ -678,7 +715,7 @@ pgresult_getlength( VALUE self, VALUE row, VALUE col)
|
|
678
715
|
{
|
679
716
|
struct pgresult_data *r;
|
680
717
|
|
681
|
-
|
718
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
682
719
|
return INT2FIX( PQgetlength( r->res, NUM2INT( row), NUM2INT( col)));
|
683
720
|
}
|
684
721
|
|
@@ -696,7 +733,7 @@ pgresult_getisnull( VALUE self, VALUE row, VALUE col)
|
|
696
733
|
{
|
697
734
|
struct pgresult_data *r;
|
698
735
|
|
699
|
-
|
736
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
700
737
|
return PQgetisnull( r->res, NUM2INT( row), NUM2INT( col)) ? Qtrue : Qfalse;
|
701
738
|
}
|
702
739
|
|
@@ -739,7 +776,7 @@ pgresult_cmdtuples( VALUE self)
|
|
739
776
|
struct pgresult_data *r;
|
740
777
|
char *n;
|
741
778
|
|
742
|
-
|
779
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
743
780
|
n = PQcmdTuples( r->res);
|
744
781
|
return *n ? rb_cstr_to_inum( n, 10, 0) : Qnil;
|
745
782
|
}
|
@@ -756,9 +793,9 @@ pgresult_cmdstatus( VALUE self)
|
|
756
793
|
struct pgresult_data *r;
|
757
794
|
char *n;
|
758
795
|
|
759
|
-
|
796
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
760
797
|
n = PQcmdStatus( r->res);
|
761
|
-
return n ? pgconn_mkstring( r->conn, n) : Qnil;
|
798
|
+
return n ? pgconn_mkstring( get_pgconn( r->conn), n) : Qnil;
|
762
799
|
}
|
763
800
|
|
764
801
|
/*
|
@@ -773,7 +810,7 @@ pgresult_oid( VALUE self)
|
|
773
810
|
struct pgresult_data *r;
|
774
811
|
Oid n;
|
775
812
|
|
776
|
-
|
813
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
777
814
|
n = PQoidValue( r->res);
|
778
815
|
return n == InvalidOid ? Qnil : INT2FIX( n);
|
779
816
|
}
|
@@ -836,7 +873,7 @@ Init_pgsql_result( void)
|
|
836
873
|
|
837
874
|
rb_define_singleton_method( rb_cPgResult, "translate_results=", pgresult_s_translate_results_set, 1);
|
838
875
|
|
839
|
-
|
876
|
+
rb_define_alloc_func( rb_cPgResult, pgresult_alloc);
|
840
877
|
rb_define_method( rb_cPgResult, "clear", &pgresult_clear, 0);
|
841
878
|
rb_define_alias( rb_cPgResult, "close", "clear");
|
842
879
|
|
data/lib/result.h
CHANGED
@@ -10,15 +10,18 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
struct pgresult_data {
|
13
|
-
PGresult
|
14
|
-
|
15
|
-
VALUE
|
16
|
-
VALUE
|
13
|
+
PGresult *res;
|
14
|
+
VALUE conn;
|
15
|
+
VALUE fields;
|
16
|
+
VALUE indices;
|
17
17
|
};
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
extern
|
21
|
+
extern const rb_data_type_t pgresult_data_data_type;
|
22
|
+
|
23
|
+
|
24
|
+
extern VALUE pgresult_new( PGresult *result, VALUE conn, VALUE cmd, VALUE par);
|
22
25
|
extern VALUE pgresult_clear( VALUE self);
|
23
26
|
extern VALUE pgresult_each( VALUE self);
|
24
27
|
extern VALUE pg_fetchrow( struct pgresult_data *r, int num);
|
data/lib/undef.h
CHANGED
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgsql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bertram Scharpf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: autorake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
27
41
|
description: |
|
28
42
|
This is not the official PostgreSQL library that was originally written by Guy
|
29
43
|
Decoux. As the project wasn't maintained a long time after Guy's decease, I
|
@@ -73,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
87
|
version: '0'
|
74
88
|
requirements:
|
75
89
|
- PostgreSQL
|
76
|
-
rubygems_version: 3.4.
|
90
|
+
rubygems_version: 3.4.19
|
77
91
|
signing_key:
|
78
92
|
specification_version: 4
|
79
93
|
summary: PostgreSQL-API for Ruby
|