pgsql 1.9.2 → 1.10
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/LICENSE +31 -8
- data/README.md +57 -0
- data/lib/conn.c +36 -27
- data/lib/conn_exec.c +25 -42
- data/lib/conn_quote.c +2 -5
- data/lib/module.c +1 -1
- data/lib/result.c +83 -52
- data/lib/result.h +8 -5
- data/lib/undef.h +1 -1
- metadata +26 -15
- data/README +0 -48
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d5e250aaea34af2f5b9f76ebb8d6ef7d590836e8826dd189ef9c1721a8aced6b
|
|
4
|
+
data.tar.gz: e24f7f58eb083c0c95c544ac72ed17c8423759fc335798ce8957e8c085262fab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 62aea91052765eb84cbedae7140e05574cc919eb53a18123a5b9818f58cd188b7bad70c17ebb175019056db33f46da6c810fd1483b78694680338a51cd88ba37
|
|
7
|
+
data.tar.gz: 86eb5356770eea1bbd0a66151f49ba61d6c221a4cdfcc2f86d11c5982c6fe6adc9d0d0a41ca9d128bd2796c07c40a0305d6828be80df509b0b933bc765bbeac8
|
data/LICENSE
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
# BSD-2-clause license, extended by language use conditions
|
|
2
2
|
|
|
3
|
-
Copyright (C) 2011-
|
|
3
|
+
Copyright (C) 2011-2025, Bertram Scharpf <software@bertram-scharpf.de>.
|
|
4
4
|
All rights reserved.
|
|
5
5
|
|
|
6
6
|
Redistribution and use in source and binary forms, with or without
|
|
7
7
|
modification, are permitted provided that the following conditions are
|
|
8
8
|
met:
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
* Redistributions of source code must retain the above copyright
|
|
11
|
+
notice, this list of conditions and the following disclaimer.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
14
|
+
notice, this list of conditions and the following disclaimer in
|
|
15
|
+
the documentation and/or other materials provided with the
|
|
16
|
+
distribution.
|
|
17
|
+
|
|
18
|
+
* Redistributions must not contain any clauses about anticipated
|
|
19
|
+
harassment or discrimination, nor must they be held in a so-called
|
|
20
|
+
"inclusive language". As far as German language is used, the
|
|
21
|
+
conditions mentioned below additionally apply.
|
|
17
22
|
|
|
18
23
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
19
24
|
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
@@ -27,3 +32,21 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
27
32
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
28
33
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
34
|
|
|
35
|
+
|
|
36
|
+
## Use of the German Language
|
|
37
|
+
|
|
38
|
+
Beim Gebrauch deutscher Sprache sind Weiterentwicklungen und
|
|
39
|
+
-verbreitungen nur gestattet unter Einhaltung sowie abermaligen
|
|
40
|
+
Einforderns folgender zusätzlicher Bedingungen:
|
|
41
|
+
|
|
42
|
+
* Keine Verwendung von sogenannter „geschlechtergerechter Sprache“,
|
|
43
|
+
also Anfügen von weiblichen Endungen mit Binnen-I, Sternchen,
|
|
44
|
+
Doppelpunkt, Unterstrich oder ähnlichem, oder Konstruktionen, die
|
|
45
|
+
den Sachverhalt falsch wiedergeben („Radfahrende“, „Studierende“).
|
|
46
|
+
|
|
47
|
+
* Keine Verwendung der „reformierten Rechtschreibung“ von 1996,
|
|
48
|
+
insbesondere Doppel-S am Silbenende, „plazieren“ mit T, sowie
|
|
49
|
+
Großschreibung von Wendungen wie „des weiteren“.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
<!-- vim:set ft=markdown : -->
|
data/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# pgsql Ruby Gem
|
|
2
|
+
|
|
3
|
+
A PostgreSQL library that was carefully designed.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Author
|
|
7
|
+
|
|
8
|
+
Bertram Scharpf <software@bertram-scharpf.de>
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
* Connection parameters from hash
|
|
14
|
+
* Query parameters
|
|
15
|
+
* Asynchronous queries
|
|
16
|
+
* Quick query of single lines or values
|
|
17
|
+
* Full PostgreSQL quoting support
|
|
18
|
+
* Built-in transactions and savepoints by Ruby blocks
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
Write something like this:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
require "pgsql"
|
|
27
|
+
|
|
28
|
+
Pg::Conn.open :dbname => "test1", :user => "jdoe" do |conn|
|
|
29
|
+
conn.exec "SELECT * FROM mytable;" do |result|
|
|
30
|
+
result.each { |row|
|
|
31
|
+
l = row.join ", "
|
|
32
|
+
...
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
cmd = <<~ENDSQL
|
|
36
|
+
SELECT * FROM mytable WHERE num=$1::INTEGER;
|
|
37
|
+
ENDSQL
|
|
38
|
+
conn.query cmd, 42 do |row|
|
|
39
|
+
l = row.join ", "
|
|
40
|
+
...
|
|
41
|
+
end
|
|
42
|
+
...
|
|
43
|
+
end
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## Thanks
|
|
48
|
+
|
|
49
|
+
In the remembrance of Guy Decoux.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## Copyright
|
|
53
|
+
|
|
54
|
+
* (C) 2011-2025 Bertram Scharpf <software@bertram-scharpf.de>
|
|
55
|
+
* License: [BSD-2-Clause+](./LICENSE)
|
|
56
|
+
* Repository: [ruby-pgsql](https://github.com/BertramScharpf/ruby-pgsql)
|
|
57
|
+
|
data/lib/conn.c
CHANGED
|
@@ -13,17 +13,13 @@
|
|
|
13
13
|
#endif
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
extern void pg_check_conninvalid( struct pgconn_data *c);
|
|
17
16
|
static VALUE pgconnfailederror_new( struct pgconn_data *c, VALUE params);
|
|
18
17
|
|
|
19
|
-
static void
|
|
20
|
-
static void
|
|
21
|
-
|
|
18
|
+
static void pgconn_mark( void *ptr);
|
|
19
|
+
static void pgconn_free( void *ptr);
|
|
20
|
+
static size_t pgconn_memsize( const void *ptr);
|
|
22
21
|
static VALUE pgconn_encode_in4out( struct pgconn_data *ptr, VALUE str);
|
|
23
|
-
extern const char *pgconn_destring( struct pgconn_data *ptr, VALUE str, int *len);
|
|
24
22
|
static VALUE pgconn_encode_out4in( struct pgconn_data *ptr, VALUE str);
|
|
25
|
-
extern VALUE pgconn_mkstring( struct pgconn_data *ptr, const char *str);
|
|
26
|
-
extern VALUE pgconn_mkstringn( struct pgconn_data *ptr, const char *str, int len);
|
|
27
23
|
static VALUE pgconn_alloc( VALUE cls);
|
|
28
24
|
static VALUE pgconn_s_connect( int argc, VALUE *argv, VALUE cls);
|
|
29
25
|
static VALUE pgconn_init( int argc, VALUE *argv, VALUE self);
|
|
@@ -76,6 +72,12 @@ static VALUE sym_password = Qundef;
|
|
|
76
72
|
|
|
77
73
|
static ID id_to_s;
|
|
78
74
|
|
|
75
|
+
static const rb_data_type_t pgconn_data_data_type = {
|
|
76
|
+
"pgsql:pgconn_data",
|
|
77
|
+
{ &pgconn_mark, &pgconn_free, &pgconn_memsize,},
|
|
78
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
|
79
|
+
};
|
|
80
|
+
|
|
79
81
|
|
|
80
82
|
void
|
|
81
83
|
pg_check_conninvalid( struct pgconn_data *c)
|
|
@@ -99,21 +101,29 @@ pgconnfailederror_new( struct pgconn_data *c, VALUE params)
|
|
|
99
101
|
|
|
100
102
|
|
|
101
103
|
void
|
|
102
|
-
pgconn_mark(
|
|
104
|
+
pgconn_mark( void *ptr)
|
|
103
105
|
{
|
|
104
|
-
|
|
106
|
+
struct pgconn_data *pd = ptr;
|
|
105
107
|
#ifdef RUBY_ENCODING
|
|
106
|
-
rb_gc_mark(
|
|
107
|
-
rb_gc_mark(
|
|
108
|
+
rb_gc_mark( pd->external);
|
|
109
|
+
rb_gc_mark( pd->internal);
|
|
108
110
|
#endif
|
|
111
|
+
rb_gc_mark( pd->notice);
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
void
|
|
112
|
-
pgconn_free(
|
|
115
|
+
pgconn_free( void *ptr)
|
|
116
|
+
{
|
|
117
|
+
struct pgconn_data *pd = ptr;
|
|
118
|
+
if (pd->conn != NULL)
|
|
119
|
+
PQfinish( pd->conn);
|
|
120
|
+
ruby_xfree( ptr);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static size_t
|
|
124
|
+
pgconn_memsize( const void *ptr)
|
|
113
125
|
{
|
|
114
|
-
|
|
115
|
-
PQfinish( ptr->conn);
|
|
116
|
-
free( ptr);
|
|
126
|
+
return sizeof (struct pgconn_data);
|
|
117
127
|
}
|
|
118
128
|
|
|
119
129
|
struct pgconn_data *
|
|
@@ -121,7 +131,7 @@ get_pgconn( VALUE obj)
|
|
|
121
131
|
{
|
|
122
132
|
struct pgconn_data *c;
|
|
123
133
|
|
|
124
|
-
|
|
134
|
+
TypedData_Get_Struct( obj, struct pgconn_data, &pgconn_data_data_type, c);
|
|
125
135
|
pg_check_conninvalid( c);
|
|
126
136
|
return c;
|
|
127
137
|
}
|
|
@@ -190,17 +200,16 @@ VALUE
|
|
|
190
200
|
pgconn_alloc( VALUE cls)
|
|
191
201
|
{
|
|
192
202
|
struct pgconn_data *c;
|
|
193
|
-
VALUE
|
|
203
|
+
VALUE obj;
|
|
194
204
|
|
|
195
|
-
|
|
196
|
-
&pgconn_mark, &pgconn_free, c);
|
|
205
|
+
obj = TypedData_Make_Struct( cls, struct pgconn_data, &pgconn_data_data_type, c);
|
|
197
206
|
c->conn = NULL;
|
|
198
207
|
#ifdef RUBY_ENCODING
|
|
199
208
|
c->external = rb_enc_from_encoding( rb_default_external_encoding());
|
|
200
209
|
c->internal = rb_enc_from_encoding( rb_default_internal_encoding());
|
|
201
210
|
#endif
|
|
202
211
|
c->notice = Qnil;
|
|
203
|
-
return
|
|
212
|
+
return obj;
|
|
204
213
|
}
|
|
205
214
|
|
|
206
215
|
/*
|
|
@@ -287,7 +296,7 @@ pgconn_init( int argc, VALUE *argv, VALUE self)
|
|
|
287
296
|
str = Qnil;
|
|
288
297
|
}
|
|
289
298
|
|
|
290
|
-
|
|
299
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
|
291
300
|
|
|
292
301
|
if (NIL_P( params)) {
|
|
293
302
|
c->conn = PQconnectdb( RSTRING_PTR( rb_funcall( str, id_to_s, 0)));
|
|
@@ -405,7 +414,7 @@ pgconn_close( VALUE self)
|
|
|
405
414
|
{
|
|
406
415
|
struct pgconn_data *c;
|
|
407
416
|
|
|
408
|
-
|
|
417
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
|
409
418
|
PQfinish( c->conn);
|
|
410
419
|
c->conn = NULL;
|
|
411
420
|
return Qnil;
|
|
@@ -470,7 +479,7 @@ pgconn_externalenc( VALUE self)
|
|
|
470
479
|
{
|
|
471
480
|
struct pgconn_data *c;
|
|
472
481
|
|
|
473
|
-
|
|
482
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
|
474
483
|
return c->external;
|
|
475
484
|
}
|
|
476
485
|
|
|
@@ -487,7 +496,7 @@ pgconn_set_externalenc( VALUE self, VALUE enc)
|
|
|
487
496
|
rb_encoding *e;
|
|
488
497
|
|
|
489
498
|
e = NIL_P( enc) ? rb_to_encoding( enc) : rb_default_external_encoding();
|
|
490
|
-
|
|
499
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
|
491
500
|
c->external = rb_enc_from_encoding( e);
|
|
492
501
|
|
|
493
502
|
return Qnil;
|
|
@@ -504,7 +513,7 @@ pgconn_internalenc( VALUE self)
|
|
|
504
513
|
{
|
|
505
514
|
struct pgconn_data *c;
|
|
506
515
|
|
|
507
|
-
|
|
516
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
|
508
517
|
return c->internal;
|
|
509
518
|
}
|
|
510
519
|
|
|
@@ -521,7 +530,7 @@ pgconn_set_internalenc( VALUE self, VALUE enc)
|
|
|
521
530
|
rb_encoding *e;
|
|
522
531
|
|
|
523
532
|
e = NIL_P( enc) ? rb_to_encoding( enc) : rb_default_internal_encoding();
|
|
524
|
-
|
|
533
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
|
525
534
|
c->internal = rb_enc_from_encoding( e);
|
|
526
535
|
|
|
527
536
|
return Qnil;
|
|
@@ -785,7 +794,7 @@ pgconn_on_notice( VALUE self)
|
|
|
785
794
|
{
|
|
786
795
|
struct pgconn_data *c;
|
|
787
796
|
|
|
788
|
-
|
|
797
|
+
TypedData_Get_Struct( self, struct pgconn_data, &pgconn_data_data_type, c);
|
|
789
798
|
if (PQsetNoticeReceiver( c->conn, NULL, NULL) != ¬ice_receiver) {
|
|
790
799
|
PQsetNoticeReceiver( c->conn, ¬ice_receiver, (void *) c);
|
|
791
800
|
}
|
data/lib/conn_exec.c
CHANGED
|
@@ -36,11 +36,9 @@ static VALUE pgconn_get_notify( VALUE self);
|
|
|
36
36
|
|
|
37
37
|
static VALUE pgconn_transaction( int argc, VALUE *argv, VALUE self);
|
|
38
38
|
static VALUE rollback_transaction( VALUE conn, VALUE err);
|
|
39
|
-
static VALUE commit_transaction( VALUE self);
|
|
40
39
|
static VALUE yield_transaction( VALUE conn);
|
|
41
40
|
static VALUE pgconn_subtransaction( int argc, VALUE *argv, VALUE self);
|
|
42
41
|
static VALUE rollback_subtransaction( VALUE ary, VALUE err);
|
|
43
|
-
static VALUE release_subtransaction( VALUE ary);
|
|
44
42
|
static VALUE yield_subtransaction( VALUE ary);
|
|
45
43
|
static VALUE pgconn_transaction_status( VALUE self);
|
|
46
44
|
|
|
@@ -93,7 +91,7 @@ pg_statement_exec( VALUE conn, VALUE cmd, VALUE par)
|
|
|
93
91
|
}
|
|
94
92
|
if (result == NULL)
|
|
95
93
|
pg_raise_connexec( c);
|
|
96
|
-
return pgresult_new( result,
|
|
94
|
+
return pgresult_new( result, conn, cmd, par);
|
|
97
95
|
}
|
|
98
96
|
|
|
99
97
|
|
|
@@ -268,7 +266,7 @@ pgconn_fetch( int argc, VALUE *argv, VALUE conn)
|
|
|
268
266
|
while ((result = PQgetResult( c->conn)) != NULL) {
|
|
269
267
|
VALUE res;
|
|
270
268
|
|
|
271
|
-
res = pgresult_new( result,
|
|
269
|
+
res = pgresult_new( result, conn, Qnil, Qnil);
|
|
272
270
|
rb_ensure( rb_yield, res, pgresult_clear, res);
|
|
273
271
|
}
|
|
274
272
|
return Qnil;
|
|
@@ -430,7 +428,7 @@ pgconn_select_row( int argc, VALUE *argv, VALUE self)
|
|
|
430
428
|
pg_parse_parameters( argc, argv, &cmd, &par);
|
|
431
429
|
res = pg_statement_exec( self, cmd, par);
|
|
432
430
|
|
|
433
|
-
|
|
431
|
+
TypedData_Get_Struct( res, struct pgresult_data, &pgresult_data_data_type, r);
|
|
434
432
|
return pg_fetchrow( r, 0);
|
|
435
433
|
}
|
|
436
434
|
|
|
@@ -451,7 +449,7 @@ pgconn_select_value( int argc, VALUE *argv, VALUE self)
|
|
|
451
449
|
pg_parse_parameters( argc, argv, &cmd, &par);
|
|
452
450
|
res = pg_statement_exec( self, cmd, par);
|
|
453
451
|
|
|
454
|
-
|
|
452
|
+
TypedData_Get_Struct( res, struct pgresult_data, &pgresult_data_data_type, r);
|
|
455
453
|
return PQntuples( r->res) > 0 && PQnfields( r->res) > 0 ?
|
|
456
454
|
pg_fetchresult( r, 0, 0) : Qnil;
|
|
457
455
|
}
|
|
@@ -476,7 +474,7 @@ pgconn_select_values( int argc, VALUE *argv, VALUE self)
|
|
|
476
474
|
pg_parse_parameters( argc, argv, &cmd, &par);
|
|
477
475
|
res = pg_statement_exec( self, cmd, par);
|
|
478
476
|
|
|
479
|
-
|
|
477
|
+
TypedData_Get_Struct( res, struct pgresult_data, &pgresult_data_data_type, r);
|
|
480
478
|
m = PQntuples( r->res), n = PQnfields( r->res);
|
|
481
479
|
l = m * n;
|
|
482
480
|
if (l == 0)
|
|
@@ -562,13 +560,17 @@ pgconn_transaction( int argc, VALUE *argv, VALUE conn)
|
|
|
562
560
|
rb_raise( rb_ePgConnTrans,
|
|
563
561
|
"Nested transaction block. Use Conn#subtransaction.");
|
|
564
562
|
pgresult_clear( pg_statement_exec( conn, cmd, Qnil));
|
|
565
|
-
return
|
|
563
|
+
return rb_rescue2( yield_transaction, conn, rollback_transaction, conn, rb_eException, (VALUE) 0);
|
|
566
564
|
}
|
|
567
565
|
|
|
568
566
|
VALUE
|
|
569
567
|
yield_transaction( VALUE conn)
|
|
570
568
|
{
|
|
571
|
-
|
|
569
|
+
VALUE r;
|
|
570
|
+
|
|
571
|
+
r = rb_yield( conn);
|
|
572
|
+
pgresult_clear( pg_statement_exec( conn, rb_str_new2( "COMMIT;"), Qnil));
|
|
573
|
+
return r;
|
|
572
574
|
}
|
|
573
575
|
|
|
574
576
|
VALUE
|
|
@@ -579,17 +581,6 @@ rollback_transaction( VALUE conn, VALUE err)
|
|
|
579
581
|
return Qnil;
|
|
580
582
|
}
|
|
581
583
|
|
|
582
|
-
VALUE
|
|
583
|
-
commit_transaction( VALUE conn)
|
|
584
|
-
{
|
|
585
|
-
struct pgconn_data *c;
|
|
586
|
-
|
|
587
|
-
c = get_pgconn( conn);
|
|
588
|
-
if (PQtransactionStatus( c->conn) > PQTRANS_IDLE)
|
|
589
|
-
pgresult_clear( pg_statement_exec( conn, rb_str_new2( "COMMIT;"), Qnil));
|
|
590
|
-
return Qnil;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
584
|
|
|
594
585
|
/*
|
|
595
586
|
* call-seq:
|
|
@@ -623,13 +614,23 @@ pgconn_subtransaction( int argc, VALUE *argv, VALUE self)
|
|
|
623
614
|
rb_str_buf_cat2( cmd, ";");
|
|
624
615
|
|
|
625
616
|
pgresult_clear( pg_statement_exec( self, cmd, Qnil));
|
|
626
|
-
return
|
|
617
|
+
return rb_rescue2( yield_subtransaction, ya, rollback_subtransaction, ya, rb_eException, (VALUE) 0);
|
|
627
618
|
}
|
|
628
619
|
|
|
629
620
|
VALUE
|
|
630
621
|
yield_subtransaction( VALUE ary)
|
|
631
622
|
{
|
|
632
|
-
|
|
623
|
+
VALUE conn;
|
|
624
|
+
VALUE r;
|
|
625
|
+
VALUE cmd;
|
|
626
|
+
|
|
627
|
+
conn = rb_ary_entry( ary, 0);
|
|
628
|
+
r = rb_yield( conn);
|
|
629
|
+
cmd = rb_str_buf_new2( "RELEASE SAVEPOINT ");
|
|
630
|
+
rb_str_buf_append( cmd, rb_ary_entry( ary, 1));
|
|
631
|
+
rb_str_buf_cat2( cmd, ";");
|
|
632
|
+
pgresult_clear( pg_statement_exec( conn, cmd, Qnil));
|
|
633
|
+
return r;
|
|
633
634
|
}
|
|
634
635
|
|
|
635
636
|
VALUE
|
|
@@ -646,24 +647,6 @@ rollback_subtransaction( VALUE ary, VALUE err)
|
|
|
646
647
|
return Qnil;
|
|
647
648
|
}
|
|
648
649
|
|
|
649
|
-
VALUE
|
|
650
|
-
release_subtransaction( VALUE ary)
|
|
651
|
-
{
|
|
652
|
-
VALUE cmd;
|
|
653
|
-
VALUE n;
|
|
654
|
-
|
|
655
|
-
n = rb_ary_entry( ary, 1);
|
|
656
|
-
if (!NIL_P( n)) {
|
|
657
|
-
cmd = rb_str_buf_new2( "RELEASE SAVEPOINT ");
|
|
658
|
-
rb_str_buf_append( cmd, n);
|
|
659
|
-
rb_str_buf_cat2( cmd, ";");
|
|
660
|
-
pgresult_clear( pg_statement_exec( rb_ary_entry( ary, 0), cmd, Qnil));
|
|
661
|
-
}
|
|
662
|
-
return Qnil;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
650
|
|
|
668
651
|
/*
|
|
669
652
|
* call-seq:
|
|
@@ -735,7 +718,7 @@ put_end( VALUE self)
|
|
|
735
718
|
if (r < 0)
|
|
736
719
|
rb_raise( rb_ePgConnCopy, "Copy from stdin failed to finish.");
|
|
737
720
|
while ((res = PQgetResult( c->conn)) != NULL)
|
|
738
|
-
pgresult_new( res,
|
|
721
|
+
pgresult_new( res, self, Qnil, Qnil);
|
|
739
722
|
return Qnil;
|
|
740
723
|
}
|
|
741
724
|
|
|
@@ -836,7 +819,7 @@ get_end( VALUE self)
|
|
|
836
819
|
|
|
837
820
|
c = get_pgconn( self);
|
|
838
821
|
if ((res = PQgetResult( c->conn)) != NULL)
|
|
839
|
-
pgresult_new( res,
|
|
822
|
+
pgresult_new( res, self, Qnil, Qnil);
|
|
840
823
|
return Qnil;
|
|
841
824
|
}
|
|
842
825
|
|
data/lib/conn_quote.c
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
#include "conn_quote.h"
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
extern VALUE pg_monetary_class( void);
|
|
10
|
-
|
|
11
9
|
static VALUE pgconn_format( VALUE self, VALUE obj);
|
|
12
10
|
|
|
13
11
|
static VALUE pgconn_escape_bytea( VALUE self, VALUE str);
|
|
@@ -17,9 +15,8 @@ static VALUE pgconn_unescape_bytea( int argc, VALUE *argv, VALUE self);
|
|
|
17
15
|
static VALUE pgconn_unescape_bytea( VALUE self, VALUE obj);
|
|
18
16
|
#endif
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
extern VALUE pgconn_for_copy( VALUE self, VALUE str);
|
|
18
|
+
static VALUE pgconn_for_copy( VALUE self, VALUE str);
|
|
19
|
+
|
|
23
20
|
static int needs_dquote_string( VALUE str);
|
|
24
21
|
static VALUE dquote_string( VALUE str);
|
|
25
22
|
static VALUE stringize_array( VALUE self, VALUE result, VALUE ary);
|
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,10 +21,10 @@ 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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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);
|
|
29
28
|
|
|
30
29
|
static VALUE pgresult_status( VALUE self);
|
|
31
30
|
|
|
@@ -35,10 +34,7 @@ static VALUE pgresult_num_fields( VALUE self);
|
|
|
35
34
|
static VALUE pgresult_fieldname( VALUE self, VALUE index);
|
|
36
35
|
static VALUE pgresult_fieldnum( VALUE self, VALUE name);
|
|
37
36
|
|
|
38
|
-
extern VALUE pgresult_each( VALUE self);
|
|
39
37
|
static VALUE pgresult_aref( int argc, VALUE *argv, VALUE self);
|
|
40
|
-
extern VALUE pg_fetchrow( struct pgresult_data *r, int num);
|
|
41
|
-
extern VALUE pg_fetchresult( struct pgresult_data *r, int row, int col);
|
|
42
38
|
static VALUE pgresult_num_tuples( VALUE self);
|
|
43
39
|
|
|
44
40
|
static VALUE pgresult_type( VALUE self, VALUE index);
|
|
@@ -64,6 +60,14 @@ static int translate_results = 1;
|
|
|
64
60
|
|
|
65
61
|
|
|
66
62
|
|
|
63
|
+
const rb_data_type_t pgresult_data_data_type = {
|
|
64
|
+
"mydata",
|
|
65
|
+
{ &pgresult_mark, &pgresult_free, &pgresult_memsize,},
|
|
66
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
67
71
|
|
|
68
72
|
VALUE
|
|
69
73
|
pgreserror_new( VALUE result, VALUE cmd, VALUE par)
|
|
@@ -71,8 +75,8 @@ pgreserror_new( VALUE result, VALUE cmd, VALUE par)
|
|
|
71
75
|
struct pgresult_data *r;
|
|
72
76
|
VALUE rse, msg;
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
msg = pgconn_mkstring( r->conn, PQresultErrorMessage( r->res));
|
|
78
|
+
TypedData_Get_Struct( result, struct pgresult_data, &pgresult_data_data_type, r);
|
|
79
|
+
msg = pgconn_mkstring( get_pgconn( r->conn), PQresultErrorMessage( r->res));
|
|
76
80
|
rse = rb_class_new_instance( 1, &msg, rb_ePgResError);
|
|
77
81
|
rb_ivar_set( rse, id_result, result);
|
|
78
82
|
rb_ivar_set( rse, rb_intern( "@command"), cmd);
|
|
@@ -87,7 +91,7 @@ pgreserror_result( VALUE self)
|
|
|
87
91
|
{
|
|
88
92
|
struct pgresult_data *r;
|
|
89
93
|
|
|
90
|
-
|
|
94
|
+
TypedData_Get_Struct( rb_ivar_get( self, id_result), struct pgresult_data, &pgresult_data_data_type, r);
|
|
91
95
|
return r;
|
|
92
96
|
}
|
|
93
97
|
|
|
@@ -120,7 +124,7 @@ pgreserror_sqlst( VALUE self)
|
|
|
120
124
|
struct pgresult_data *r;
|
|
121
125
|
|
|
122
126
|
r = pgreserror_result( self);
|
|
123
|
-
return pgconn_mkstring( r->conn, PQresultErrorField( r->res, PG_DIAG_SQLSTATE));
|
|
127
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQresultErrorField( r->res, PG_DIAG_SQLSTATE));
|
|
124
128
|
}
|
|
125
129
|
|
|
126
130
|
/*
|
|
@@ -136,7 +140,7 @@ pgreserror_primary( VALUE self)
|
|
|
136
140
|
struct pgresult_data *r;
|
|
137
141
|
|
|
138
142
|
r = pgreserror_result( self);
|
|
139
|
-
return pgconn_mkstring( r->conn, PQresultErrorField( r->res, PG_DIAG_MESSAGE_PRIMARY));
|
|
143
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQresultErrorField( r->res, PG_DIAG_MESSAGE_PRIMARY));
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
|
|
@@ -153,7 +157,7 @@ pgreserror_detail( VALUE self)
|
|
|
153
157
|
struct pgresult_data *r;
|
|
154
158
|
|
|
155
159
|
r = pgreserror_result( self);
|
|
156
|
-
return pgconn_mkstring( r->conn, PQresultErrorField( r->res, PG_DIAG_MESSAGE_DETAIL));
|
|
160
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQresultErrorField( r->res, PG_DIAG_MESSAGE_DETAIL));
|
|
157
161
|
}
|
|
158
162
|
|
|
159
163
|
|
|
@@ -170,7 +174,7 @@ pgreserror_hint( VALUE self)
|
|
|
170
174
|
struct pgresult_data *r;
|
|
171
175
|
|
|
172
176
|
r = pgreserror_result( self);
|
|
173
|
-
return pgconn_mkstring( r->conn, PQresultErrorField( r->res, PG_DIAG_MESSAGE_HINT));
|
|
177
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQresultErrorField( r->res, PG_DIAG_MESSAGE_HINT));
|
|
174
178
|
}
|
|
175
179
|
|
|
176
180
|
|
|
@@ -188,7 +192,7 @@ pgreserror_diag( VALUE self, VALUE field)
|
|
|
188
192
|
struct pgresult_data *r;
|
|
189
193
|
|
|
190
194
|
r = pgreserror_result( self);
|
|
191
|
-
return pgconn_mkstring( r->conn, PQresultErrorField( r->res, NUM2INT( field)));
|
|
195
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQresultErrorField( r->res, NUM2INT( field)));
|
|
192
196
|
}
|
|
193
197
|
|
|
194
198
|
|
|
@@ -211,30 +215,57 @@ pgresult_s_translate_results_set( VALUE cls, VALUE fact)
|
|
|
211
215
|
|
|
212
216
|
|
|
213
217
|
void
|
|
214
|
-
|
|
218
|
+
pgresult_mark( void *ptr)
|
|
215
219
|
{
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
220
|
+
struct pgresult_data *rd = ptr;
|
|
221
|
+
rb_gc_mark( rd->conn);
|
|
222
|
+
rb_gc_mark( rd->fields);
|
|
223
|
+
rb_gc_mark( rd->indices);
|
|
219
224
|
}
|
|
220
225
|
|
|
221
226
|
void
|
|
222
|
-
|
|
227
|
+
pgresult_free( void *ptr)
|
|
223
228
|
{
|
|
224
|
-
|
|
225
|
-
|
|
229
|
+
struct pgresult_data *rd = ptr;
|
|
230
|
+
if (rd->res != NULL)
|
|
231
|
+
PQclear( rd->res);
|
|
232
|
+
ruby_xfree( ptr);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
size_t
|
|
236
|
+
pgresult_memsize( const void *ptr)
|
|
237
|
+
{
|
|
238
|
+
return sizeof (struct pgresult_data);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
VALUE
|
|
244
|
+
pgresult_alloc( VALUE cls)
|
|
245
|
+
{
|
|
246
|
+
struct pgresult_data *r;
|
|
247
|
+
VALUE obj;
|
|
248
|
+
|
|
249
|
+
obj = TypedData_Make_Struct( cls, struct pgresult_data, &pgresult_data_data_type, r);
|
|
250
|
+
r->res = NULL;
|
|
251
|
+
r->conn = Qnil;
|
|
226
252
|
r->fields = Qnil;
|
|
227
253
|
r->indices = Qnil;
|
|
254
|
+
return obj;
|
|
228
255
|
}
|
|
229
256
|
|
|
230
257
|
VALUE
|
|
231
|
-
pgresult_new( PGresult *result,
|
|
258
|
+
pgresult_new( PGresult *result, VALUE conn, VALUE cmd, VALUE par)
|
|
232
259
|
{
|
|
233
260
|
struct pgresult_data *r;
|
|
234
261
|
VALUE res;
|
|
235
262
|
|
|
236
|
-
res =
|
|
237
|
-
|
|
263
|
+
res = rb_class_new_instance( 0, NULL, rb_cPgResult);
|
|
264
|
+
TypedData_Get_Struct( res, struct pgresult_data, &pgresult_data_data_type, r);
|
|
265
|
+
r->res = result;
|
|
266
|
+
r->conn = conn;
|
|
267
|
+
r->fields = Qnil;
|
|
268
|
+
r->indices = Qnil;
|
|
238
269
|
switch (PQresultStatus( result)) {
|
|
239
270
|
case PGRES_EMPTY_QUERY:
|
|
240
271
|
case PGRES_COMMAND_OK:
|
|
@@ -267,7 +298,7 @@ pgresult_clear( VALUE self)
|
|
|
267
298
|
{
|
|
268
299
|
struct pgresult_data *r;
|
|
269
300
|
|
|
270
|
-
|
|
301
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
271
302
|
if (r->res != NULL) {
|
|
272
303
|
PQclear( r->res);
|
|
273
304
|
r->res = NULL;
|
|
@@ -292,7 +323,7 @@ pgresult_status( VALUE self)
|
|
|
292
323
|
{
|
|
293
324
|
struct pgresult_data *r;
|
|
294
325
|
|
|
295
|
-
|
|
326
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
296
327
|
return INT2FIX( PQresultStatus( r->res));
|
|
297
328
|
}
|
|
298
329
|
|
|
@@ -313,7 +344,7 @@ pgresult_fields( VALUE self)
|
|
|
313
344
|
{
|
|
314
345
|
struct pgresult_data *r;
|
|
315
346
|
|
|
316
|
-
|
|
347
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
317
348
|
if (NIL_P( r->fields)) {
|
|
318
349
|
VALUE ary;
|
|
319
350
|
int n, i;
|
|
@@ -322,7 +353,7 @@ pgresult_fields( VALUE self)
|
|
|
322
353
|
n = PQnfields( r->res);
|
|
323
354
|
ary = rb_ary_new2( n);
|
|
324
355
|
for (i = 0; n; i++, n--) {
|
|
325
|
-
str = pgconn_mkstring( r->conn, PQfname( r->res, i));
|
|
356
|
+
str = pgconn_mkstring( get_pgconn( r->conn), PQfname( r->res, i));
|
|
326
357
|
rb_str_freeze( str);
|
|
327
358
|
rb_ary_push( ary, str);
|
|
328
359
|
}
|
|
@@ -347,7 +378,7 @@ pgresult_field_indices( VALUE self)
|
|
|
347
378
|
{
|
|
348
379
|
struct pgresult_data *r;
|
|
349
380
|
|
|
350
|
-
|
|
381
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
351
382
|
if (NIL_P( r->indices)) {
|
|
352
383
|
VALUE hsh;
|
|
353
384
|
int n, i;
|
|
@@ -356,7 +387,7 @@ pgresult_field_indices( VALUE self)
|
|
|
356
387
|
n = PQnfields( r->res);
|
|
357
388
|
hsh = rb_hash_new();
|
|
358
389
|
for (i = 0; n; i++, n--) {
|
|
359
|
-
str = pgconn_mkstring( r->conn, PQfname( r->res, i));
|
|
390
|
+
str = pgconn_mkstring( get_pgconn( r->conn), PQfname( r->res, i));
|
|
360
391
|
rb_str_freeze( str);
|
|
361
392
|
rb_hash_aset( hsh, str, INT2FIX( i));
|
|
362
393
|
}
|
|
@@ -379,7 +410,7 @@ pgresult_num_fields( VALUE self)
|
|
|
379
410
|
{
|
|
380
411
|
struct pgresult_data *r;
|
|
381
412
|
|
|
382
|
-
|
|
413
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
383
414
|
return INT2FIX( PQnfields( r->res));
|
|
384
415
|
}
|
|
385
416
|
|
|
@@ -400,8 +431,8 @@ pgresult_fieldname( VALUE self, VALUE index)
|
|
|
400
431
|
{
|
|
401
432
|
struct pgresult_data *r;
|
|
402
433
|
|
|
403
|
-
|
|
404
|
-
return pgconn_mkstring( r->conn, PQfname( r->res, NUM2INT( index)));
|
|
434
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
435
|
+
return pgconn_mkstring( get_pgconn( r->conn), PQfname( r->res, NUM2INT( index)));
|
|
405
436
|
}
|
|
406
437
|
|
|
407
438
|
/*
|
|
@@ -423,8 +454,8 @@ pgresult_fieldnum( VALUE self, VALUE name)
|
|
|
423
454
|
int n;
|
|
424
455
|
|
|
425
456
|
StringValue( name);
|
|
426
|
-
|
|
427
|
-
n = PQfnumber( r->res, pgconn_destring( r->conn, name, NULL));
|
|
457
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
458
|
+
n = PQfnumber( r->res, pgconn_destring( get_pgconn( r->conn), name, NULL));
|
|
428
459
|
if (n == -1)
|
|
429
460
|
rb_raise( rb_eArgError, "Unknown field: %s", RSTRING_PTR( name));
|
|
430
461
|
return INT2FIX( n);
|
|
@@ -448,7 +479,7 @@ pgresult_each( VALUE self)
|
|
|
448
479
|
struct pgresult_data *r;
|
|
449
480
|
int m, j;
|
|
450
481
|
|
|
451
|
-
|
|
482
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
452
483
|
for (j = 0, m = PQntuples( r->res); m; j++, m--)
|
|
453
484
|
rb_yield( pg_fetchrow( r, j));
|
|
454
485
|
return m ? INT2FIX( m) : Qnil;
|
|
@@ -472,7 +503,7 @@ pgresult_aref( int argc, VALUE *argv, VALUE self)
|
|
|
472
503
|
VALUE aj, ai;
|
|
473
504
|
int j, i;
|
|
474
505
|
|
|
475
|
-
|
|
506
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
476
507
|
a = rb_scan_args( argc, argv, "11", &aj, &ai);
|
|
477
508
|
j = NUM2INT( aj);
|
|
478
509
|
if (j < PQntuples( r->res)) {
|
|
@@ -524,7 +555,7 @@ pg_fetchresult( struct pgresult_data *r, int row, int col)
|
|
|
524
555
|
return Qnil;
|
|
525
556
|
|
|
526
557
|
if (!translate_results)
|
|
527
|
-
return pgconn_mkstring( r->conn, string);
|
|
558
|
+
return pgconn_mkstring( get_pgconn( r->conn), string);
|
|
528
559
|
|
|
529
560
|
typ = PQftype( r->res, col);
|
|
530
561
|
cls = Qnil;
|
|
@@ -575,7 +606,7 @@ pg_fetchresult( struct pgresult_data *r, int row, int col)
|
|
|
575
606
|
break;
|
|
576
607
|
}
|
|
577
608
|
if (NIL_P( ret)) {
|
|
578
|
-
ret = pgconn_mkstring( r->conn, string);
|
|
609
|
+
ret = pgconn_mkstring( get_pgconn( r->conn), string);
|
|
579
610
|
if (RTEST( cls))
|
|
580
611
|
ret = rb_funcall( cls, id_parse, 1, ret);
|
|
581
612
|
}
|
|
@@ -595,7 +626,7 @@ pgresult_num_tuples( VALUE self)
|
|
|
595
626
|
{
|
|
596
627
|
struct pgresult_data *r;
|
|
597
628
|
|
|
598
|
-
|
|
629
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
599
630
|
return INT2FIX( PQntuples( r->res));
|
|
600
631
|
}
|
|
601
632
|
|
|
@@ -617,7 +648,7 @@ pgresult_type( VALUE self, VALUE index)
|
|
|
617
648
|
struct pgresult_data *r;
|
|
618
649
|
int n;
|
|
619
650
|
|
|
620
|
-
|
|
651
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
621
652
|
n = PQftype( r->res, NUM2INT( index));
|
|
622
653
|
return n ? INT2FIX( n) : Qnil;
|
|
623
654
|
}
|
|
@@ -639,7 +670,7 @@ pgresult_size( VALUE self, VALUE index)
|
|
|
639
670
|
struct pgresult_data *r;
|
|
640
671
|
int n;
|
|
641
672
|
|
|
642
|
-
|
|
673
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
643
674
|
n = PQfsize( r->res, NUM2INT( index));
|
|
644
675
|
return n ? INT2FIX( n) : Qnil;
|
|
645
676
|
}
|
|
@@ -659,7 +690,7 @@ pgresult_getvalue( VALUE self, VALUE row, VALUE col)
|
|
|
659
690
|
{
|
|
660
691
|
struct pgresult_data *r;
|
|
661
692
|
|
|
662
|
-
|
|
693
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
663
694
|
return pg_fetchresult( r, NUM2INT( row), NUM2INT( col));
|
|
664
695
|
}
|
|
665
696
|
|
|
@@ -678,7 +709,7 @@ pgresult_getlength( VALUE self, VALUE row, VALUE col)
|
|
|
678
709
|
{
|
|
679
710
|
struct pgresult_data *r;
|
|
680
711
|
|
|
681
|
-
|
|
712
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
682
713
|
return INT2FIX( PQgetlength( r->res, NUM2INT( row), NUM2INT( col)));
|
|
683
714
|
}
|
|
684
715
|
|
|
@@ -696,7 +727,7 @@ pgresult_getisnull( VALUE self, VALUE row, VALUE col)
|
|
|
696
727
|
{
|
|
697
728
|
struct pgresult_data *r;
|
|
698
729
|
|
|
699
|
-
|
|
730
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
700
731
|
return PQgetisnull( r->res, NUM2INT( row), NUM2INT( col)) ? Qtrue : Qfalse;
|
|
701
732
|
}
|
|
702
733
|
|
|
@@ -739,7 +770,7 @@ pgresult_cmdtuples( VALUE self)
|
|
|
739
770
|
struct pgresult_data *r;
|
|
740
771
|
char *n;
|
|
741
772
|
|
|
742
|
-
|
|
773
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
743
774
|
n = PQcmdTuples( r->res);
|
|
744
775
|
return *n ? rb_cstr_to_inum( n, 10, 0) : Qnil;
|
|
745
776
|
}
|
|
@@ -756,9 +787,9 @@ pgresult_cmdstatus( VALUE self)
|
|
|
756
787
|
struct pgresult_data *r;
|
|
757
788
|
char *n;
|
|
758
789
|
|
|
759
|
-
|
|
790
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
760
791
|
n = PQcmdStatus( r->res);
|
|
761
|
-
return n ? pgconn_mkstring( r->conn, n) : Qnil;
|
|
792
|
+
return n ? pgconn_mkstring( get_pgconn( r->conn), n) : Qnil;
|
|
762
793
|
}
|
|
763
794
|
|
|
764
795
|
/*
|
|
@@ -773,7 +804,7 @@ pgresult_oid( VALUE self)
|
|
|
773
804
|
struct pgresult_data *r;
|
|
774
805
|
Oid n;
|
|
775
806
|
|
|
776
|
-
|
|
807
|
+
TypedData_Get_Struct( self, struct pgresult_data, &pgresult_data_data_type, r);
|
|
777
808
|
n = PQoidValue( r->res);
|
|
778
809
|
return n == InvalidOid ? Qnil : INT2FIX( n);
|
|
779
810
|
}
|
|
@@ -836,7 +867,7 @@ Init_pgsql_result( void)
|
|
|
836
867
|
|
|
837
868
|
rb_define_singleton_method( rb_cPgResult, "translate_results=", pgresult_s_translate_results_set, 1);
|
|
838
869
|
|
|
839
|
-
|
|
870
|
+
rb_define_alloc_func( rb_cPgResult, pgresult_alloc);
|
|
840
871
|
rb_define_method( rb_cPgResult, "clear", &pgresult_clear, 0);
|
|
841
872
|
rb_define_alias( rb_cPgResult, "close", "clear");
|
|
842
873
|
|
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,43 +1,56 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pgsql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: '1.10'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bertram Scharpf
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: autorake
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
16
|
+
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
18
|
version: '2.0'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
|
-
- - "
|
|
23
|
+
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '2.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rake
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '13.0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '13.0'
|
|
27
40
|
description: |
|
|
28
|
-
This is not the official PostgreSQL library that was originally written by
|
|
29
|
-
Decoux. As the project wasn't maintained a long time after Guy's
|
|
30
|
-
decided to
|
|
41
|
+
This is not the official PostgreSQL library that was originally written by
|
|
42
|
+
Guy Decoux. As the project wasn't maintained a long time after Guy's
|
|
43
|
+
decease, I decided to create my own project.
|
|
31
44
|
email: "<software@bertram-scharpf.de>"
|
|
32
45
|
executables: []
|
|
33
46
|
extensions:
|
|
34
47
|
- lib/mkrf_conf
|
|
35
48
|
extra_rdoc_files:
|
|
36
|
-
- README
|
|
37
49
|
- LICENSE
|
|
50
|
+
- README.md
|
|
38
51
|
files:
|
|
39
52
|
- LICENSE
|
|
40
|
-
- README
|
|
53
|
+
- README.md
|
|
41
54
|
- lib/Rakefile
|
|
42
55
|
- lib/conn.c
|
|
43
56
|
- lib/conn.h
|
|
@@ -51,11 +64,10 @@ files:
|
|
|
51
64
|
- lib/result.c
|
|
52
65
|
- lib/result.h
|
|
53
66
|
- lib/undef.h
|
|
54
|
-
homepage:
|
|
67
|
+
homepage: https://github.com/BertramScharpf/ruby-pgsql.git
|
|
55
68
|
licenses:
|
|
56
69
|
- BSD-2-Clause
|
|
57
70
|
metadata: {}
|
|
58
|
-
post_install_message:
|
|
59
71
|
rdoc_options:
|
|
60
72
|
- "--main"
|
|
61
73
|
- README
|
|
@@ -65,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
65
77
|
requirements:
|
|
66
78
|
- - ">="
|
|
67
79
|
- !ruby/object:Gem::Version
|
|
68
|
-
version:
|
|
80
|
+
version: 3.1.0
|
|
69
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
82
|
requirements:
|
|
71
83
|
- - ">="
|
|
@@ -73,8 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
73
85
|
version: '0'
|
|
74
86
|
requirements:
|
|
75
87
|
- PostgreSQL
|
|
76
|
-
rubygems_version: 3.
|
|
77
|
-
signing_key:
|
|
88
|
+
rubygems_version: 3.7.1
|
|
78
89
|
specification_version: 4
|
|
79
90
|
summary: PostgreSQL-API for Ruby
|
|
80
91
|
test_files: []
|
data/README
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
= pgsql Ruby Gem
|
|
2
|
-
|
|
3
|
-
A PostgreSQL library that was carefully designed.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
== Author
|
|
7
|
-
|
|
8
|
-
Bertram Scharpf <software@bertram-scharpf.de>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
== Features
|
|
12
|
-
|
|
13
|
-
* Connection parameters from hash
|
|
14
|
-
* Query parameters
|
|
15
|
-
* Asynchronous queries
|
|
16
|
-
* Quick query of single lines or values
|
|
17
|
-
* Full PostgreSQL quoting support
|
|
18
|
-
* Built-in transactions and savepoints by Ruby blocks
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
== Example
|
|
22
|
-
|
|
23
|
-
Write something like this:
|
|
24
|
-
|
|
25
|
-
require "pgsql"
|
|
26
|
-
|
|
27
|
-
Pg::Conn.open :dbname => "test1", :user => "jdoe" do |conn|
|
|
28
|
-
conn.exec "SELECT * FROM mytable;" do |result|
|
|
29
|
-
result.each { |row|
|
|
30
|
-
l = row.join ", "
|
|
31
|
-
...
|
|
32
|
-
}
|
|
33
|
-
end
|
|
34
|
-
cmd = <<-ENDSQL
|
|
35
|
-
SELECT * FROM mytable WHERE num=$1::INTEGER;
|
|
36
|
-
ENDSQL
|
|
37
|
-
conn.query cmd, 42 do |row|
|
|
38
|
-
l = row.join ", "
|
|
39
|
-
...
|
|
40
|
-
end
|
|
41
|
-
...
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
== Thanks
|
|
46
|
-
|
|
47
|
-
In the remembrance of Guy Decoux.
|
|
48
|
-
|