pg 0.7.9.2008.01.28 → 0.7.9.2008.02.05
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/compat.h +1 -1
- data/ext/pg.c +276 -191
- metadata +2 -2
data/ext/compat.h
CHANGED
data/ext/pg.c
CHANGED
@@ -9,18 +9,11 @@
|
|
9
9
|
modified at: Wed Jan 20 16:41:51 1999
|
10
10
|
|
11
11
|
$Author: jdavis $
|
12
|
-
$Date: 2008-
|
12
|
+
$Date: 2008-02-05 11:23:59 -0800 (Tue, 05 Feb 2008) $
|
13
13
|
************************************************/
|
14
14
|
|
15
15
|
#include "pg.h"
|
16
16
|
|
17
|
-
#define AssignCheckedStringValue(cstring, rstring) do { \
|
18
|
-
if (!NIL_P(temp = rstring)) { \
|
19
|
-
Check_Type(temp, T_STRING); \
|
20
|
-
cstring = StringValuePtr(temp); \
|
21
|
-
} \
|
22
|
-
} while (0)
|
23
|
-
|
24
17
|
#define rb_define_singleton_alias(klass,new,old) rb_define_alias(rb_singleton_class(klass),new,old)
|
25
18
|
|
26
19
|
static VALUE rb_cPGconn;
|
@@ -37,7 +30,6 @@ static VALUE rb_ePGError;
|
|
37
30
|
* * PQbinaryTuples -- better to use PQfformat
|
38
31
|
* * PQprint -- not very useful
|
39
32
|
* * PQsetdb -- not very useful
|
40
|
-
* * PQsetdbLogin -- not very useful
|
41
33
|
* * PQoidStatus -- deprecated, use PQoidValue
|
42
34
|
* * PQrequestCancel -- deprecated, use PQcancel
|
43
35
|
* * PQfn -- use a prepared statement instead
|
@@ -106,6 +98,13 @@ build_key_value_string(hash, conninfo_rstr, key)
|
|
106
98
|
return;
|
107
99
|
}
|
108
100
|
|
101
|
+
static char *
|
102
|
+
value_as_cstring(VALUE in_str)
|
103
|
+
{
|
104
|
+
VALUE rstring = rb_obj_as_string(in_str);
|
105
|
+
return StringValuePtr(rstring);
|
106
|
+
}
|
107
|
+
|
109
108
|
static void
|
110
109
|
free_pgconn(PGconn *conn)
|
111
110
|
{
|
@@ -198,7 +197,9 @@ static VALUE yield_pgresult(VALUE rb_pgresult)
|
|
198
197
|
* For example, to send query to the database on the localhost:
|
199
198
|
* require 'pg'
|
200
199
|
* conn = PGconn.open(:dbname => 'test')
|
201
|
-
* res
|
200
|
+
* res = conn.exec('SELECT $1 AS a, $2 AS b, $3 AS c',[1, 2, nil])
|
201
|
+
* # Equivalent to:
|
202
|
+
* # res = conn.exec('SELECT 1 AS a, 2 AS b, NULL AS c')
|
202
203
|
*
|
203
204
|
* See the PGresult class for information on working with the results of a query.
|
204
205
|
*
|
@@ -301,13 +302,13 @@ pgconn_init(argc, argv, self)
|
|
301
302
|
conn = PQconnectdb(conninfo);
|
302
303
|
}
|
303
304
|
else if (RARRAY_LEN(args) == 7) {
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
305
|
+
host = value_as_cstring(rb_ary_entry(args,0));
|
306
|
+
port = value_as_cstring(rb_ary_entry(args,1));
|
307
|
+
opt = value_as_cstring(rb_ary_entry(args,2));
|
308
|
+
tty = value_as_cstring(rb_ary_entry(args,3));
|
309
|
+
dbname = value_as_cstring(rb_ary_entry(args,4));
|
310
|
+
login = value_as_cstring(rb_ary_entry(args,5));
|
311
|
+
pwd = value_as_cstring(rb_ary_entry(args,6));
|
311
312
|
|
312
313
|
conn = PQsetdbLogin(host, port, opt, tty, dbname, login, pwd);
|
313
314
|
}
|
@@ -331,7 +332,54 @@ pgconn_init(argc, argv, self)
|
|
331
332
|
return self;
|
332
333
|
}
|
333
334
|
|
334
|
-
|
335
|
+
/*
|
336
|
+
* call-seq:
|
337
|
+
* PGconn.conndefaults() -> Array
|
338
|
+
*
|
339
|
+
* Returns an array of hashes. Each hash has the keys:
|
340
|
+
* * +:keyword+ - the name of the option
|
341
|
+
* * +:envvar+ - the environment variable to fall back to
|
342
|
+
* * +:compiled+ - the compiled in option as a secondary fallback
|
343
|
+
* * +:val+ - the option's current value, or +nil+ if not known
|
344
|
+
* * +:label+ - the label for the field
|
345
|
+
* * +:dispchar+ - "" for normal, "D" for debug, and "*" for password
|
346
|
+
* * +:dispsize+ - field size
|
347
|
+
*/
|
348
|
+
static VALUE
|
349
|
+
pgconn_s_conndefaults(VALUE self)
|
350
|
+
{
|
351
|
+
PQconninfoOption *options = PQconndefaults();
|
352
|
+
VALUE ary = rb_ary_new();
|
353
|
+
VALUE hash;
|
354
|
+
int i = 0;
|
355
|
+
|
356
|
+
for(i = 0; options[i].keyword != NULL; i++) {
|
357
|
+
hash = rb_hash_new();
|
358
|
+
if(options[i].keyword)
|
359
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("keyword")),
|
360
|
+
rb_str_new2(options[i].keyword));
|
361
|
+
if(options[i].envvar)
|
362
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("envvar")),
|
363
|
+
rb_str_new2(options[i].envvar));
|
364
|
+
if(options[i].compiled)
|
365
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("compiled")),
|
366
|
+
rb_str_new2(options[i].compiled));
|
367
|
+
if(options[i].val)
|
368
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("val")),
|
369
|
+
rb_str_new2(options[i].val));
|
370
|
+
if(options[i].label)
|
371
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("label")),
|
372
|
+
rb_str_new2(options[i].label));
|
373
|
+
if(options[i].dispchar)
|
374
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("dispchar")),
|
375
|
+
rb_str_new2(options[i].dispchar));
|
376
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("dispsize")),
|
377
|
+
INT2NUM(options[i].dispsize));
|
378
|
+
rb_ary_push(ary, hash);
|
379
|
+
}
|
380
|
+
PQconninfoFree(options);
|
381
|
+
return ary;
|
382
|
+
}
|
335
383
|
|
336
384
|
|
337
385
|
/*
|
@@ -692,7 +740,7 @@ pgconn_connection_used_password(self)
|
|
692
740
|
*
|
693
741
|
* PostgreSQL bind parameters are represented as $1, $1, $2, etc.,
|
694
742
|
* inside the SQL query. The 0th element of the +params+ array is bound
|
695
|
-
* to $1, the 1st element is bound to $2, etc.
|
743
|
+
* to $1, the 1st element is bound to $2, etc. +nil+ is treated as +NULL+.
|
696
744
|
*
|
697
745
|
* If the types are not specified, they will be inferred by PostgreSQL.
|
698
746
|
* Instead of specifying type oids, it's recommended to simply add
|
@@ -765,24 +813,30 @@ pgconn_exec(argc, argv, self)
|
|
765
813
|
if (TYPE(param) == T_HASH) {
|
766
814
|
param_type = rb_hash_aref(param, sym_type);
|
767
815
|
param_value_tmp = rb_hash_aref(param, sym_value);
|
768
|
-
if(
|
816
|
+
if(param_value_tmp == Qnil)
|
769
817
|
param_value = param_value_tmp;
|
770
818
|
else
|
771
|
-
param_value =
|
819
|
+
param_value = rb_obj_as_string(param_value_tmp);
|
772
820
|
param_format = rb_hash_aref(param, sym_format);
|
773
821
|
}
|
774
822
|
else {
|
775
823
|
param_type = INT2NUM(0);
|
776
|
-
if(
|
824
|
+
if(param == Qnil)
|
777
825
|
param_value = param;
|
778
826
|
else
|
779
|
-
param_value =
|
827
|
+
param_value = rb_obj_as_string(param);
|
780
828
|
param_format = INT2NUM(0);
|
781
829
|
}
|
782
|
-
Check_Type(param_value, T_STRING);
|
783
830
|
paramTypes[i] = NUM2INT(param_type);
|
784
|
-
|
785
|
-
|
831
|
+
if(param_value == Qnil) {
|
832
|
+
paramValues[i] = NULL;
|
833
|
+
paramLengths[i] = 0;
|
834
|
+
}
|
835
|
+
else {
|
836
|
+
Check_Type(param_value, T_STRING);
|
837
|
+
paramValues[i] = StringValuePtr(param_value);
|
838
|
+
paramLengths[i] = RSTRING_LEN(param_value) + 1;
|
839
|
+
}
|
786
840
|
paramFormats[i] = NUM2INT(param_format);
|
787
841
|
}
|
788
842
|
|
@@ -881,7 +935,7 @@ pgconn_prepare(argc, argv, self)
|
|
881
935
|
*
|
882
936
|
* PostgreSQL bind parameters are represented as $1, $1, $2, etc.,
|
883
937
|
* inside the SQL query. The 0th element of the +params+ array is bound
|
884
|
-
* to $1, the 1st element is bound to $2, etc.
|
938
|
+
* to $1, the 1st element is bound to $2, etc. +nil+ is treated as +NULL+.
|
885
939
|
*
|
886
940
|
* The optional +result_format+ should be 0 for text results, 1
|
887
941
|
* for binary.
|
@@ -935,22 +989,28 @@ pgconn_exec_prepared(argc, argv, self)
|
|
935
989
|
param = rb_ary_entry(params, i);
|
936
990
|
if (TYPE(param) == T_HASH) {
|
937
991
|
param_value_tmp = rb_hash_aref(param, sym_value);
|
938
|
-
if(
|
992
|
+
if(param_value_tmp == Qnil)
|
939
993
|
param_value = param_value_tmp;
|
940
994
|
else
|
941
|
-
param_value =
|
995
|
+
param_value = rb_obj_as_string(param_value_tmp);
|
942
996
|
param_format = rb_hash_aref(param, sym_format);
|
943
997
|
}
|
944
998
|
else {
|
945
|
-
if(
|
999
|
+
if(param == Qnil)
|
946
1000
|
param_value = param;
|
947
1001
|
else
|
948
|
-
param_value =
|
1002
|
+
param_value = rb_obj_as_string(param);
|
949
1003
|
param_format = INT2NUM(0);
|
950
1004
|
}
|
951
|
-
|
952
|
-
|
953
|
-
|
1005
|
+
if(param_value == Qnil) {
|
1006
|
+
paramValues[i] = NULL;
|
1007
|
+
paramLengths[i] = 0;
|
1008
|
+
}
|
1009
|
+
else {
|
1010
|
+
Check_Type(param_value, T_STRING);
|
1011
|
+
paramValues[i] = StringValuePtr(param_value);
|
1012
|
+
paramLengths[i] = RSTRING_LEN(param_value) + 1;
|
1013
|
+
}
|
954
1014
|
paramFormats[i] = NUM2INT(param_format);
|
955
1015
|
}
|
956
1016
|
|
@@ -1198,7 +1258,7 @@ pgconn_s_unescape_bytea(self, str)
|
|
1198
1258
|
*
|
1199
1259
|
* PostgreSQL bind parameters are represented as $1, $1, $2, etc.,
|
1200
1260
|
* inside the SQL query. The 0th element of the +params+ array is bound
|
1201
|
-
* to $1, the 1st element is bound to $2, etc.
|
1261
|
+
* to $1, the 1st element is bound to $2, etc. +nil+ is treated as +NULL+.
|
1202
1262
|
*
|
1203
1263
|
* If the types are not specified, they will be inferred by PostgreSQL.
|
1204
1264
|
* Instead of specifying type oids, it's recommended to simply add
|
@@ -1268,24 +1328,30 @@ pgconn_send_query(argc, argv, self)
|
|
1268
1328
|
if (TYPE(param) == T_HASH) {
|
1269
1329
|
param_type = rb_hash_aref(param, sym_type);
|
1270
1330
|
param_value_tmp = rb_hash_aref(param, sym_value);
|
1271
|
-
if(
|
1331
|
+
if(param_value_tmp == Qnil)
|
1272
1332
|
param_value = param_value_tmp;
|
1273
1333
|
else
|
1274
|
-
param_value =
|
1334
|
+
param_value = rb_obj_as_string(param_value_tmp);
|
1275
1335
|
param_format = rb_hash_aref(param, sym_format);
|
1276
1336
|
}
|
1277
1337
|
else {
|
1278
1338
|
param_type = INT2NUM(0);
|
1279
|
-
if(
|
1339
|
+
if(param == Qnil)
|
1280
1340
|
param_value = param;
|
1281
1341
|
else
|
1282
|
-
param_value =
|
1342
|
+
param_value = rb_obj_as_string(param);
|
1283
1343
|
param_format = INT2NUM(0);
|
1284
1344
|
}
|
1285
|
-
Check_Type(param_value, T_STRING);
|
1286
1345
|
paramTypes[i] = NUM2INT(param_type);
|
1287
|
-
|
1288
|
-
|
1346
|
+
if(param_value == Qnil) {
|
1347
|
+
paramValues[i] = NULL;
|
1348
|
+
paramLengths[i] = 0;
|
1349
|
+
}
|
1350
|
+
else {
|
1351
|
+
Check_Type(param_value, T_STRING);
|
1352
|
+
paramValues[i] = StringValuePtr(param_value);
|
1353
|
+
paramLengths[i] = RSTRING_LEN(param_value) + 1;
|
1354
|
+
}
|
1289
1355
|
paramFormats[i] = NUM2INT(param_format);
|
1290
1356
|
}
|
1291
1357
|
|
@@ -1387,7 +1453,7 @@ pgconn_send_prepare(argc, argv, self)
|
|
1387
1453
|
*
|
1388
1454
|
* PostgreSQL bind parameters are represented as $1, $1, $2, etc.,
|
1389
1455
|
* inside the SQL query. The 0th element of the +params+ array is bound
|
1390
|
-
* to $1, the 1st element is bound to $2, etc.
|
1456
|
+
* to $1, the 1st element is bound to $2, etc. +nil+ is treated as +NULL+.
|
1391
1457
|
*
|
1392
1458
|
* The optional +result_format+ should be 0 for text results, 1
|
1393
1459
|
* for binary.
|
@@ -1440,22 +1506,28 @@ pgconn_send_query_prepared(argc, argv, self)
|
|
1440
1506
|
param = rb_ary_entry(params, i);
|
1441
1507
|
if (TYPE(param) == T_HASH) {
|
1442
1508
|
param_value_tmp = rb_hash_aref(param, sym_value);
|
1443
|
-
if(
|
1509
|
+
if(param_value_tmp == Qnil)
|
1444
1510
|
param_value = param_value_tmp;
|
1445
1511
|
else
|
1446
|
-
param_value =
|
1512
|
+
param_value = rb_obj_as_string(param_value_tmp);
|
1447
1513
|
param_format = rb_hash_aref(param, sym_format);
|
1448
1514
|
}
|
1449
1515
|
else {
|
1450
|
-
if(
|
1516
|
+
if(param == Qnil)
|
1451
1517
|
param_value = param;
|
1452
1518
|
else
|
1453
|
-
param_value =
|
1519
|
+
param_value = rb_obj_as_string(param);
|
1454
1520
|
param_format = INT2NUM(0);
|
1455
1521
|
}
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1522
|
+
if(param_value == Qnil) {
|
1523
|
+
paramValues[i] = NULL;
|
1524
|
+
paramLengths[i] = 0;
|
1525
|
+
}
|
1526
|
+
else {
|
1527
|
+
Check_Type(param_value, T_STRING);
|
1528
|
+
paramValues[i] = StringValuePtr(param_value);
|
1529
|
+
paramLengths[i] = RSTRING_LEN(param_value) + 1;
|
1530
|
+
}
|
1459
1531
|
paramFormats[i] = NUM2INT(param_format);
|
1460
1532
|
}
|
1461
1533
|
|
@@ -1816,7 +1888,7 @@ pgconn_get_copy_data( argc, argv, self )
|
|
1816
1888
|
if(ret == 0) { // would block
|
1817
1889
|
return Qfalse;
|
1818
1890
|
}
|
1819
|
-
result_str =
|
1891
|
+
result_str = rb_tainted_str_new(buffer, ret);
|
1820
1892
|
PQfreemem(buffer);
|
1821
1893
|
return result_str;
|
1822
1894
|
}
|
@@ -1978,6 +2050,7 @@ pgconn_transaction(VALUE self)
|
|
1978
2050
|
static VALUE
|
1979
2051
|
pgconn_s_quote_ident(VALUE self, VALUE in_str)
|
1980
2052
|
{
|
2053
|
+
VALUE ret;
|
1981
2054
|
char *str = StringValuePtr(in_str);
|
1982
2055
|
/* result size at most NAMEDATALEN*2 plus surrounding
|
1983
2056
|
* double-quotes. */
|
@@ -1996,7 +2069,9 @@ pgconn_s_quote_ident(VALUE self, VALUE in_str)
|
|
1996
2069
|
buffer[j++] = str[i];
|
1997
2070
|
}
|
1998
2071
|
buffer[j++] = '"';
|
1999
|
-
|
2072
|
+
ret = rb_str_new(buffer,j);
|
2073
|
+
OBJ_INFECT(ret, in_str);
|
2074
|
+
return ret;
|
2000
2075
|
}
|
2001
2076
|
|
2002
2077
|
|
@@ -2079,9 +2154,9 @@ pgconn_get_last_result(VALUE self)
|
|
2079
2154
|
* call-seq:
|
2080
2155
|
* conn.async_exec(sql [, params, result_format ] ) -> PGresult
|
2081
2156
|
*
|
2082
|
-
* This function has the same behavior as +PGconn#exec
|
2157
|
+
* This function has the same behavior as +PGconn#exec+,
|
2083
2158
|
* except that it's implemented using asynchronous command
|
2084
|
-
* processing and ruby's +rb_thread_select
|
2159
|
+
* processing and ruby's +rb_thread_select+ in order to
|
2085
2160
|
* allow other threads to process while waiting for the
|
2086
2161
|
* server to complete the request.
|
2087
2162
|
*/
|
@@ -2453,6 +2528,15 @@ pgconn_lounlink(self, in_oid)
|
|
2453
2528
|
* An instance of this class is created as the result of every query.
|
2454
2529
|
* You may need to invoke the #clear method of the instance when finished with
|
2455
2530
|
* the result for better memory performance.
|
2531
|
+
*
|
2532
|
+
* Example:
|
2533
|
+
* require 'pg'
|
2534
|
+
* conn = PGconn.open(:dbname => 'test')
|
2535
|
+
* res = conn.exec('SELECT 1 AS a, 2 AS b, NULL AS c')
|
2536
|
+
* res.getvalue(0,0) # '1'
|
2537
|
+
* res[0]['b'] # '2'
|
2538
|
+
* res[0]['c'] # nil
|
2539
|
+
*
|
2456
2540
|
*/
|
2457
2541
|
|
2458
2542
|
/**************************************************************************
|
@@ -2491,7 +2575,7 @@ static VALUE
|
|
2491
2575
|
pgresult_res_status(self,status)
|
2492
2576
|
VALUE self,status;
|
2493
2577
|
{
|
2494
|
-
return
|
2578
|
+
return rb_tainted_str_new2(PQresStatus(NUM2INT(status)));
|
2495
2579
|
}
|
2496
2580
|
|
2497
2581
|
/*
|
@@ -2504,7 +2588,7 @@ static VALUE
|
|
2504
2588
|
pgresult_result_error_message(self)
|
2505
2589
|
VALUE self;
|
2506
2590
|
{
|
2507
|
-
return
|
2591
|
+
return rb_tainted_str_new2(PQresultErrorMessage(get_pgresult(self)));
|
2508
2592
|
}
|
2509
2593
|
|
2510
2594
|
/*
|
@@ -2531,7 +2615,7 @@ static VALUE
|
|
2531
2615
|
pgresult_result_error_field(self)
|
2532
2616
|
VALUE self;
|
2533
2617
|
{
|
2534
|
-
return
|
2618
|
+
return rb_tainted_str_new2(PQresultErrorMessage(get_pgresult(self)));
|
2535
2619
|
}
|
2536
2620
|
|
2537
2621
|
/*
|
@@ -2780,7 +2864,7 @@ pgresult_getvalue(self, tup_num, field_num)
|
|
2780
2864
|
}
|
2781
2865
|
if(PQgetisnull(result, i, j))
|
2782
2866
|
return Qnil;
|
2783
|
-
return
|
2867
|
+
return rb_tainted_str_new2(PQgetvalue(result, i, j));
|
2784
2868
|
}
|
2785
2869
|
|
2786
2870
|
/*
|
@@ -2943,7 +3027,7 @@ pgresult_aref(self, index)
|
|
2943
3027
|
rb_raise(rb_eIndexError, "Index %d is out of range", tuple_num);
|
2944
3028
|
tuple = rb_hash_new();
|
2945
3029
|
for(field_num = 0; field_num < PQnfields(result); field_num++) {
|
2946
|
-
fname =
|
3030
|
+
fname = rb_tainted_str_new2(PQfname(result,field_num));
|
2947
3031
|
if(PQgetisnull(result, tuple_num, field_num)) {
|
2948
3032
|
rb_hash_aset(tuple, fname, Qnil);
|
2949
3033
|
}
|
@@ -3002,15 +3086,15 @@ pgresult_fields(self)
|
|
3002
3086
|
void
|
3003
3087
|
Init_pg()
|
3004
3088
|
{
|
3005
|
-
|
3006
|
-
|
3007
|
-
|
3089
|
+
rb_ePGError = rb_define_class("PGError", rb_eStandardError);
|
3090
|
+
rb_cPGconn = rb_define_class("PGconn", rb_cObject);
|
3091
|
+
rb_cPGresult = rb_define_class("PGresult", rb_cObject);
|
3008
3092
|
|
3009
3093
|
|
3010
3094
|
/*************************
|
3011
3095
|
* PGError
|
3012
3096
|
*************************/
|
3013
|
-
|
3097
|
+
rb_define_alias(rb_ePGError, "error", "message");
|
3014
3098
|
rb_define_attr(rb_ePGError, "connection", 1, 0);
|
3015
3099
|
rb_define_attr(rb_ePGError, "result", 1, 0);
|
3016
3100
|
|
@@ -3020,26 +3104,26 @@ Init_pg()
|
|
3020
3104
|
|
3021
3105
|
/****** PGconn CLASS METHODS ******/
|
3022
3106
|
#ifdef HAVE_RB_DEFINE_ALLOC_FUNC
|
3023
|
-
|
3107
|
+
rb_define_alloc_func(rb_cPGconn, pgconn_alloc);
|
3024
3108
|
#else
|
3025
|
-
|
3109
|
+
rb_define_singleton_method(rb_cPGconn, "new", pgconn_s_new, -1);
|
3026
3110
|
#endif
|
3027
|
-
|
3028
|
-
|
3029
|
-
|
3030
|
-
|
3031
|
-
|
3032
|
-
rb_define_singleton_method(rb_cPGconn, "escape_string", pgconn_s_escape, 1);
|
3111
|
+
rb_define_singleton_alias(rb_cPGconn, "connect", "new");
|
3112
|
+
rb_define_singleton_alias(rb_cPGconn, "open", "new");
|
3113
|
+
rb_define_singleton_alias(rb_cPGconn, "setdb", "new");
|
3114
|
+
rb_define_singleton_alias(rb_cPGconn, "setdblogin", "new");
|
3115
|
+
rb_define_singleton_method(rb_cPGconn, "escape_string", pgconn_s_escape, 1);
|
3033
3116
|
rb_define_singleton_alias(rb_cPGconn, "escape", "escape_string");
|
3034
|
-
|
3035
|
-
|
3036
|
-
|
3037
|
-
|
3117
|
+
rb_define_singleton_method(rb_cPGconn, "escape_bytea", pgconn_s_escape_bytea, 1);
|
3118
|
+
rb_define_singleton_method(rb_cPGconn, "unescape_bytea", pgconn_s_unescape_bytea, 1);
|
3119
|
+
rb_define_singleton_method(rb_cPGconn, "isthreadsafe", pgconn_s_isthreadsafe, 0);
|
3120
|
+
rb_define_singleton_method(rb_cPGconn, "encrypt_password", pgconn_s_encrypt_password, 0);
|
3038
3121
|
rb_define_singleton_method(rb_cPGconn, "quote_ident", pgconn_s_quote_ident, 1);
|
3122
|
+
rb_define_singleton_method(rb_cPGconn, "conndefaults", pgconn_s_conndefaults, 0);
|
3039
3123
|
|
3040
3124
|
/****** PGconn CLASS CONSTANTS: Connection Status ******/
|
3041
|
-
|
3042
|
-
|
3125
|
+
rb_define_const(rb_cPGconn, "CONNECTION_OK", INT2FIX(CONNECTION_OK));
|
3126
|
+
rb_define_const(rb_cPGconn, "CONNECTION_BAD", INT2FIX(CONNECTION_BAD));
|
3043
3127
|
|
3044
3128
|
/****** PGconn CLASS CONSTANTS: Nonblocking connection status ******/
|
3045
3129
|
rb_define_const(rb_cPGconn, "CONNECTION_STARTED", INT2FIX(CONNECTION_STARTED));
|
@@ -3048,7 +3132,7 @@ Init_pg()
|
|
3048
3132
|
rb_define_const(rb_cPGconn, "CONNECTION_AUTH_OK", INT2FIX(CONNECTION_AUTH_OK));
|
3049
3133
|
rb_define_const(rb_cPGconn, "CONNECTION_SSL_STARTUP", INT2FIX(CONNECTION_SSL_STARTUP));
|
3050
3134
|
rb_define_const(rb_cPGconn, "CONNECTION_SETENV", INT2FIX(CONNECTION_SETENV));
|
3051
|
-
|
3135
|
+
|
3052
3136
|
/****** PGconn CLASS CONSTANTS: Nonblocking connection polling status ******/
|
3053
3137
|
rb_define_const(rb_cPGconn, "PGRES_POLLING_READING", INT2FIX(PGRES_POLLING_READING));
|
3054
3138
|
rb_define_const(rb_cPGconn, "PGRES_POLLING_WRITING", INT2FIX(PGRES_POLLING_WRITING));
|
@@ -3068,63 +3152,64 @@ Init_pg()
|
|
3068
3152
|
rb_define_const(rb_cPGconn, "PQERRORS_VERBOSE", INT2FIX(PQERRORS_VERBOSE));
|
3069
3153
|
|
3070
3154
|
/****** PGconn CLASS CONSTANTS: Large Objects ******/
|
3071
|
-
|
3072
|
-
|
3073
|
-
|
3074
|
-
|
3075
|
-
|
3076
|
-
|
3155
|
+
rb_define_const(rb_cPGconn, "INV_WRITE", INT2FIX(INV_WRITE));
|
3156
|
+
rb_define_const(rb_cPGconn, "INV_READ", INT2FIX(INV_READ));
|
3157
|
+
rb_define_const(rb_cPGconn, "SEEK_SET", INT2FIX(SEEK_SET));
|
3158
|
+
rb_define_const(rb_cPGconn, "SEEK_CUR", INT2FIX(SEEK_CUR));
|
3159
|
+
rb_define_const(rb_cPGconn, "SEEK_END", INT2FIX(SEEK_END));
|
3160
|
+
|
3077
3161
|
/****** PGconn INSTANCE METHODS: Connection Control ******/
|
3078
|
-
|
3079
|
-
|
3080
|
-
|
3081
|
-
|
3162
|
+
rb_define_method(rb_cPGconn, "initialize", pgconn_init, -1);
|
3163
|
+
rb_define_method(rb_cPGconn, "reset", pgconn_reset, 0);
|
3164
|
+
rb_define_method(rb_cPGconn, "conndefaults", pgconn_s_conndefaults, 0);
|
3165
|
+
rb_define_method(rb_cPGconn, "finish", pgconn_finish, 0);
|
3166
|
+
rb_define_alias(rb_cPGconn, "close", "finish");
|
3082
3167
|
|
3083
3168
|
/****** PGconn INSTANCE METHODS: Connection Status ******/
|
3084
|
-
|
3085
|
-
|
3086
|
-
|
3087
|
-
|
3088
|
-
|
3089
|
-
|
3090
|
-
|
3091
|
-
|
3092
|
-
|
3093
|
-
|
3094
|
-
|
3095
|
-
|
3096
|
-
|
3097
|
-
|
3098
|
-
|
3099
|
-
|
3100
|
-
|
3101
|
-
|
3169
|
+
rb_define_method(rb_cPGconn, "db", pgconn_db, 0);
|
3170
|
+
rb_define_method(rb_cPGconn, "user", pgconn_user, 0);
|
3171
|
+
rb_define_method(rb_cPGconn, "pass", pgconn_pass, 0);
|
3172
|
+
rb_define_method(rb_cPGconn, "host", pgconn_host, 0);
|
3173
|
+
rb_define_method(rb_cPGconn, "port", pgconn_port, 0);
|
3174
|
+
rb_define_method(rb_cPGconn, "tty", pgconn_tty, 0);
|
3175
|
+
rb_define_method(rb_cPGconn, "options", pgconn_options, 0);
|
3176
|
+
rb_define_method(rb_cPGconn, "status", pgconn_status, 0);
|
3177
|
+
rb_define_method(rb_cPGconn, "transaction_status", pgconn_transaction_status, 0);
|
3178
|
+
rb_define_method(rb_cPGconn, "parameter_status", pgconn_parameter_status, 1);
|
3179
|
+
rb_define_method(rb_cPGconn, "protocol_version", pgconn_protocol_version, 0);
|
3180
|
+
rb_define_method(rb_cPGconn, "server_version", pgconn_server_version, 0);
|
3181
|
+
rb_define_method(rb_cPGconn, "error_message", pgconn_error_message, 0);
|
3182
|
+
//rb_define_method(rb_cPGconn, "socket", pgconn_socket, 0);
|
3183
|
+
rb_define_method(rb_cPGconn, "backend_pid", pgconn_backend_pid, 0);
|
3184
|
+
rb_define_method(rb_cPGconn, "connection_needs_password", pgconn_connection_needs_password, 0);
|
3185
|
+
rb_define_method(rb_cPGconn, "connection_used_password", pgconn_connection_used_password, 0);
|
3186
|
+
//rb_define_method(rb_cPGconn, "getssl", pgconn_getssl, 0);
|
3102
3187
|
|
3103
3188
|
/****** PGconn INSTANCE METHODS: Command Execution ******/
|
3104
|
-
|
3189
|
+
rb_define_method(rb_cPGconn, "exec", pgconn_exec, -1);
|
3105
3190
|
rb_define_alias(rb_cPGconn, "query", "exec");
|
3106
|
-
|
3107
|
-
|
3108
|
-
|
3109
|
-
|
3110
|
-
|
3111
|
-
|
3191
|
+
rb_define_method(rb_cPGconn, "prepare", pgconn_prepare, -1);
|
3192
|
+
rb_define_method(rb_cPGconn, "exec_prepared", pgconn_exec_prepared, -1);
|
3193
|
+
rb_define_method(rb_cPGconn, "describe_prepared", pgconn_describe_prepared, 1);
|
3194
|
+
rb_define_method(rb_cPGconn, "describe_portal", pgconn_describe_portal, 1);
|
3195
|
+
rb_define_method(rb_cPGconn, "make_empty_pgresult", pgconn_make_empty_pgresult, 1);
|
3196
|
+
rb_define_method(rb_cPGconn, "escape_string", pgconn_s_escape, 1);
|
3112
3197
|
rb_define_alias(rb_cPGconn, "escape", "escape_string");
|
3113
|
-
|
3114
|
-
|
3115
|
-
|
3198
|
+
rb_define_method(rb_cPGconn, "escape_bytea", pgconn_s_escape_bytea, 1);
|
3199
|
+
rb_define_method(rb_cPGconn, "unescape_bytea", pgconn_s_unescape_bytea, 1);
|
3200
|
+
|
3116
3201
|
/****** PGconn INSTANCE METHODS: Asynchronous Command Processing ******/
|
3117
|
-
|
3118
|
-
|
3119
|
-
|
3120
|
-
|
3121
|
-
|
3122
|
-
|
3123
|
-
|
3124
|
-
|
3125
|
-
|
3126
|
-
|
3127
|
-
|
3202
|
+
rb_define_method(rb_cPGconn, "send_query", pgconn_send_query, -1);
|
3203
|
+
rb_define_method(rb_cPGconn, "send_prepare", pgconn_send_prepare, -1);
|
3204
|
+
rb_define_method(rb_cPGconn, "send_query_prepared", pgconn_send_query_prepared, -1);
|
3205
|
+
rb_define_method(rb_cPGconn, "send_describe_prepared", pgconn_send_describe_prepared, 1);
|
3206
|
+
rb_define_method(rb_cPGconn, "send_describe_portal", pgconn_send_describe_portal, 1);
|
3207
|
+
rb_define_method(rb_cPGconn, "get_result", pgconn_get_result, 0);
|
3208
|
+
rb_define_method(rb_cPGconn, "consume_input", pgconn_consume_input, 0);
|
3209
|
+
rb_define_method(rb_cPGconn, "is_busy", pgconn_is_busy, 0);
|
3210
|
+
rb_define_method(rb_cPGconn, "setnonblocking", pgconn_setnonblocking, 0);
|
3211
|
+
rb_define_method(rb_cPGconn, "isnonblocking", pgconn_isnonblocking, 0);
|
3212
|
+
rb_define_method(rb_cPGconn, "flush", pgconn_flush, 0);
|
3128
3213
|
|
3129
3214
|
/****** PGconn INSTANCE METHODS: Cancelling Queries in Progress ******/
|
3130
3215
|
//rb_define_method(rb_cPGconn, "get_cancel", pgconn_get_result, 0);
|
@@ -3132,25 +3217,25 @@ Init_pg()
|
|
3132
3217
|
//rb_define_method(rb_cPGconn, "cancel", pgconn_get_result, 0);
|
3133
3218
|
|
3134
3219
|
/****** PGconn INSTANCE METHODS: NOTIFY ******/
|
3135
|
-
|
3220
|
+
rb_define_method(rb_cPGconn, "notifies", pgconn_notifies, 0);
|
3136
3221
|
|
3137
3222
|
/****** PGconn INSTANCE METHODS: COPY ******/
|
3138
|
-
|
3139
|
-
|
3140
|
-
|
3223
|
+
rb_define_method(rb_cPGconn, "put_copy_data", pgconn_put_copy_data, 1);
|
3224
|
+
rb_define_method(rb_cPGconn, "put_copy_end", pgconn_put_copy_end, -1);
|
3225
|
+
rb_define_method(rb_cPGconn, "get_copy_data", pgconn_get_copy_data, -1);
|
3141
3226
|
|
3142
3227
|
/****** PGconn INSTANCE METHODS: Control Functions ******/
|
3143
|
-
|
3144
|
-
|
3145
|
-
|
3228
|
+
rb_define_method(rb_cPGconn, "set_error_verbosity", pgconn_set_error_verbosity, 1);
|
3229
|
+
rb_define_method(rb_cPGconn, "trace", pgconn_trace, 1);
|
3230
|
+
rb_define_method(rb_cPGconn, "untrace", pgconn_untrace, 0);
|
3146
3231
|
|
3147
3232
|
/****** PGconn INSTANCE METHODS: Notice Processing ******/
|
3148
|
-
|
3149
|
-
|
3233
|
+
//rb_define_method(rb_cPGconn, "set_notice_receiver", pgconn_set_notice_receiver, 0);
|
3234
|
+
rb_define_method(rb_cPGconn, "set_notice_processor", pgconn_set_notice_processor, 0);
|
3150
3235
|
|
3151
3236
|
/****** PGconn INSTANCE METHODS: Other ******/
|
3152
|
-
|
3153
|
-
|
3237
|
+
rb_define_method(rb_cPGconn, "get_client_encoding", pgconn_get_client_encoding, 0);
|
3238
|
+
rb_define_method(rb_cPGconn, "set_client_encoding", pgconn_set_client_encoding, 1);
|
3154
3239
|
rb_define_method(rb_cPGconn, "transaction", pgconn_transaction, 0);
|
3155
3240
|
rb_define_method(rb_cPGconn, "block", pgconn_block, -1);
|
3156
3241
|
rb_define_method(rb_cPGconn, "quote_ident", pgconn_s_quote_ident, 1);
|
@@ -3159,47 +3244,47 @@ Init_pg()
|
|
3159
3244
|
rb_define_method(rb_cPGconn, "get_last_result", pgconn_get_last_result, 0);
|
3160
3245
|
|
3161
3246
|
/****** PGconn INSTANCE METHODS: Large Object Support ******/
|
3162
|
-
|
3163
|
-
|
3164
|
-
|
3165
|
-
|
3166
|
-
|
3167
|
-
|
3168
|
-
|
3169
|
-
|
3170
|
-
|
3171
|
-
|
3172
|
-
|
3247
|
+
rb_define_method(rb_cPGconn, "lo_creat", pgconn_locreat, -1);
|
3248
|
+
rb_define_alias(rb_cPGconn, "locreat", "lo_creat");
|
3249
|
+
rb_define_method(rb_cPGconn, "lo_create", pgconn_locreate, 1);
|
3250
|
+
rb_define_alias(rb_cPGconn, "locreate", "lo_create");
|
3251
|
+
rb_define_method(rb_cPGconn, "lo_import", pgconn_loimport, 1);
|
3252
|
+
rb_define_alias(rb_cPGconn, "loimport", "lo_import");
|
3253
|
+
rb_define_method(rb_cPGconn, "lo_export", pgconn_loexport, 2);
|
3254
|
+
rb_define_alias(rb_cPGconn, "loexport", "lo_export");
|
3255
|
+
rb_define_method(rb_cPGconn, "lo_open", pgconn_loopen, -1);
|
3256
|
+
rb_define_alias(rb_cPGconn, "loopen", "lo_open");
|
3257
|
+
rb_define_method(rb_cPGconn, "lo_write",pgconn_lowrite, 2);
|
3173
3258
|
rb_define_alias(rb_cPGconn, "lowrite", "lo_write");
|
3174
|
-
|
3259
|
+
rb_define_method(rb_cPGconn, "lo_read",pgconn_loread, 2);
|
3175
3260
|
rb_define_alias(rb_cPGconn, "loread", "lo_read");
|
3176
|
-
|
3261
|
+
rb_define_method(rb_cPGconn, "lo_lseek",pgconn_lolseek, 3);
|
3177
3262
|
rb_define_alias(rb_cPGconn, "lolseek", "lo_lseek");
|
3178
3263
|
rb_define_alias(rb_cPGconn, "lo_seek", "lo_lseek");
|
3179
3264
|
rb_define_alias(rb_cPGconn, "loseek", "lo_lseek");
|
3180
|
-
|
3265
|
+
rb_define_method(rb_cPGconn, "lo_tell",pgconn_lotell, 1);
|
3181
3266
|
rb_define_alias(rb_cPGconn, "lotell", "lo_tell");
|
3182
3267
|
rb_define_method(rb_cPGconn, "lo_truncate", pgconn_lotruncate, 2);
|
3183
|
-
|
3184
|
-
|
3185
|
-
|
3186
|
-
|
3187
|
-
|
3188
|
-
|
3268
|
+
rb_define_alias(rb_cPGconn, "lotruncate", "lo_truncate");
|
3269
|
+
rb_define_method(rb_cPGconn, "lo_close",pgconn_loclose, 1);
|
3270
|
+
rb_define_alias(rb_cPGconn, "loclose", "lo_close");
|
3271
|
+
rb_define_method(rb_cPGconn, "lo_unlink", pgconn_lounlink, 1);
|
3272
|
+
rb_define_alias(rb_cPGconn, "lounlink", "lo_unlink");
|
3273
|
+
|
3189
3274
|
/*************************
|
3190
3275
|
* PGresult
|
3191
3276
|
*************************/
|
3192
|
-
|
3277
|
+
rb_include_module(rb_cPGresult, rb_mEnumerable);
|
3193
3278
|
|
3194
3279
|
/****** PGresult CONSTANTS: result status ******/
|
3195
|
-
|
3196
|
-
|
3197
|
-
|
3198
|
-
|
3199
|
-
|
3200
|
-
|
3201
|
-
|
3202
|
-
|
3280
|
+
rb_define_const(rb_cPGresult, "PGRES_EMPTY_QUERY", INT2FIX(PGRES_EMPTY_QUERY));
|
3281
|
+
rb_define_const(rb_cPGresult, "PGRES_COMMAND_OK", INT2FIX(PGRES_COMMAND_OK));
|
3282
|
+
rb_define_const(rb_cPGresult, "PGRES_TUPLES_OK", INT2FIX(PGRES_TUPLES_OK));
|
3283
|
+
rb_define_const(rb_cPGresult, "PGRES_COPY_OUT", INT2FIX(PGRES_COPY_OUT));
|
3284
|
+
rb_define_const(rb_cPGresult, "PGRES_COPY_IN", INT2FIX(PGRES_COPY_IN));
|
3285
|
+
rb_define_const(rb_cPGresult, "PGRES_BAD_RESPONSE", INT2FIX(PGRES_BAD_RESPONSE));
|
3286
|
+
rb_define_const(rb_cPGresult, "PGRES_NONFATAL_ERROR",INT2FIX(PGRES_NONFATAL_ERROR));
|
3287
|
+
rb_define_const(rb_cPGresult, "PGRES_FATAL_ERROR", INT2FIX(PGRES_FATAL_ERROR));
|
3203
3288
|
|
3204
3289
|
/****** PGresult CONSTANTS: result error field codes ******/
|
3205
3290
|
rb_define_const(rb_cPGresult, "PG_DIAG_SEVERITY", INT2FIX(PG_DIAG_SEVERITY));
|
@@ -3216,36 +3301,36 @@ Init_pg()
|
|
3216
3301
|
rb_define_const(rb_cPGresult, "PG_DIAG_SOURCE_FUNCTION", INT2FIX(PG_DIAG_SOURCE_FUNCTION));
|
3217
3302
|
|
3218
3303
|
/****** PGresult INSTANCE METHODS: libpq ******/
|
3219
|
-
|
3220
|
-
|
3221
|
-
|
3222
|
-
|
3223
|
-
|
3224
|
-
|
3225
|
-
|
3226
|
-
|
3227
|
-
|
3228
|
-
|
3229
|
-
|
3230
|
-
|
3231
|
-
|
3232
|
-
|
3233
|
-
|
3234
|
-
|
3235
|
-
|
3236
|
-
|
3237
|
-
|
3238
|
-
|
3304
|
+
rb_define_method(rb_cPGresult, "result_status", pgresult_result_status, 0);
|
3305
|
+
rb_define_method(rb_cPGresult, "res_status", pgresult_res_status, 1);
|
3306
|
+
rb_define_method(rb_cPGresult, "result_error_message", pgresult_result_error_message, 0);
|
3307
|
+
rb_define_method(rb_cPGresult, "result_error_field", pgresult_result_error_field, 0);
|
3308
|
+
rb_define_method(rb_cPGresult, "clear", pgresult_clear, 0);
|
3309
|
+
rb_define_method(rb_cPGresult, "ntuples", pgresult_ntuples, 0);
|
3310
|
+
rb_define_alias(rb_cPGresult, "num_tuples", "ntuples");
|
3311
|
+
rb_define_method(rb_cPGresult, "nfields", pgresult_nfields, 0);
|
3312
|
+
rb_define_alias(rb_cPGresult, "num_fields", "nfields");
|
3313
|
+
rb_define_method(rb_cPGresult, "fname", pgresult_fname, 1);
|
3314
|
+
rb_define_method(rb_cPGresult, "fnumber", pgresult_fnumber, 1);
|
3315
|
+
rb_define_method(rb_cPGresult, "ftable", pgresult_ftable, 1);
|
3316
|
+
rb_define_method(rb_cPGresult, "ftablecol", pgresult_ftablecol, 1);
|
3317
|
+
rb_define_method(rb_cPGresult, "fformat", pgresult_fformat, 1);
|
3318
|
+
rb_define_method(rb_cPGresult, "ftype", pgresult_ftype, 1);
|
3319
|
+
rb_define_method(rb_cPGresult, "fmod", pgresult_fmod, 1);
|
3320
|
+
rb_define_method(rb_cPGresult, "fsize", pgresult_fsize, 1);
|
3321
|
+
rb_define_method(rb_cPGresult, "getvalue", pgresult_getvalue, 2);
|
3322
|
+
rb_define_method(rb_cPGresult, "getisnull", pgresult_getisnull, 2);
|
3323
|
+
rb_define_method(rb_cPGresult, "getlength", pgresult_getlength, 2);
|
3239
3324
|
rb_define_method(rb_cPGresult, "nparams", pgresult_nparams, 0);
|
3240
3325
|
rb_define_method(rb_cPGresult, "paramtype", pgresult_paramtype, 0);
|
3241
3326
|
rb_define_method(rb_cPGresult, "cmd_status", pgresult_cmd_status, 0);
|
3242
3327
|
rb_define_method(rb_cPGresult, "cmd_tuples", pgresult_cmd_tuples, 0);
|
3243
|
-
|
3328
|
+
rb_define_alias(rb_cPGresult, "cmdtuples", "cmd_tuples");
|
3244
3329
|
rb_define_method(rb_cPGresult, "oid_value", pgresult_oid_value, 0);
|
3245
3330
|
|
3246
3331
|
/****** PGresult INSTANCE METHODS: other ******/
|
3247
|
-
|
3248
|
-
|
3249
|
-
|
3332
|
+
rb_define_method(rb_cPGresult, "[]", pgresult_aref, 1);
|
3333
|
+
rb_define_method(rb_cPGresult, "each", pgresult_each, 0);
|
3334
|
+
rb_define_method(rb_cPGresult, "fields", pgresult_fields, 0);
|
3250
3335
|
|
3251
3336
|
}
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: pg
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.7.9.2008.
|
7
|
-
date: 2008-
|
6
|
+
version: 0.7.9.2008.02.05
|
7
|
+
date: 2008-02-05 00:00:00 -08:00
|
8
8
|
summary: Ruby extension library providing an API to PostgreSQL
|
9
9
|
require_paths:
|
10
10
|
- lib
|