postgres 0.7.9.2007.12.12 → 0.7.9.2007.12.22

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.
data/ext/compat.c CHANGED
@@ -14,6 +14,21 @@
14
14
 
15
15
  #include "compat.h"
16
16
 
17
+ #ifndef HAVE_PQDESCRIBEPREPARED
18
+ PGresult *
19
+ PQdescribePrepared(PGconn *conn, const char *stmtName)
20
+ {
21
+ rb_raise(rb_eStandardError, "PQdescribePrepared not supported by this client version.");
22
+ }
23
+ #endif /* HAVE_PQDESCRIBEPREPARED */
24
+
25
+ #ifndef HAVE_PQDESCRIBEPORTAL
26
+ PGresult *
27
+ PQdescribePortal(PGconn *conn, const char *portalName)
28
+ {
29
+ rb_raise(rb_eStandardError, "PQdescribePortal not supported by this client version.");
30
+ }
31
+ #endif /* HAVE_PQDESCRIBEPORTAL */
17
32
 
18
33
  #ifndef HAVE_PQESCAPESTRINGCONN
19
34
  size_t
data/ext/compat.h CHANGED
@@ -6,7 +6,6 @@
6
6
 
7
7
  #include "ruby.h"
8
8
  #include "rubyio.h"
9
- #include "st.h"
10
9
  #include "libpq-fe.h"
11
10
  #include "libpq/libpq-fs.h" /* large-object interface */
12
11
 
@@ -14,6 +13,14 @@
14
13
  #define rb_check_string_type(x) rb_check_convert_type(x, T_STRING, "String", "to_str")
15
14
  #endif /* RUBY_VERSION_CODE < 180 */
16
15
 
16
+ #ifndef RSTRING_LEN
17
+ #define RSTRING_LEN(x) RSTRING((x))->len
18
+ #endif /* RSTRING_LEN */
19
+
20
+ #ifndef RSTRING_PTR
21
+ #define RSTRING_PTR(x) RSTRING((x))->ptr
22
+ #endif /* RSTRING_PTR */
23
+
17
24
  #ifndef StringValuePtr
18
25
  #define StringValuePtr(x) STR2CSTR(x)
19
26
  #endif /* StringValuePtr */
@@ -56,6 +63,14 @@ PGresult *PQprepare(PGconn *conn, const char *stmtName, const char *query,
56
63
  int nParams, const Oid *paramTypes);
57
64
  #endif /* HAVE_PQPREPARE */
58
65
 
66
+ #ifndef HAVE_PQDESCRIBEPREPARED
67
+ PGresult * PQdescribePrepared(PGconn *conn, const char *stmtName);
68
+ #endif /* HAVE_PQDESCRIBEPREPARED */
69
+
70
+ #ifndef HAVE_PQDESCRIBEPORTAL
71
+ PGresult * PQdescribePortal(PGconn *conn, const char *portalName);
72
+ #endif /* HAVE_PQDESCRIBEPORTAL */
73
+
59
74
  #ifndef HAVE_PQCONNECTIONUSEDPASSWORD
60
75
  int PQconnectionUsedPassword(PGconn *conn);
61
76
  #endif /* HAVE_PQCONNECTIONUSEDPASSWORD */
data/ext/extconf.rb CHANGED
@@ -33,6 +33,8 @@ desired_functions = %w(
33
33
  PQsendDescribePrepared
34
34
  PQsendDescribePortal
35
35
  PQencryptPassword
36
+ PQdescribePrepared
37
+ PQdescribePortal
36
38
  lo_create
37
39
  lo_truncate
38
40
  pg_encoding_to_char
data/ext/pg.c CHANGED
@@ -9,7 +9,7 @@
9
9
  modified at: Wed Jan 20 16:41:51 1999
10
10
 
11
11
  $Author: jdavis $
12
- $Date: 2007-12-12 15:46:33 -0800 (Wed, 12 Dec 2007) $
12
+ $Date: 2007-12-13 18:58:32 -0800 (Thu, 13 Dec 2007) $
13
13
  ************************************************/
14
14
 
15
15
  #include "pg.h"
@@ -25,9 +25,9 @@
25
25
 
26
26
  #define rb_define_singleton_alias(klass,new,old) rb_define_alias(rb_singleton_class(klass),new,old)
27
27
 
28
- #define Data_Set_Struct(obj,ptr) do { \
29
- Check_Type(obj, T_DATA); \
30
- DATA_PTR(obj) = ptr; \
28
+ #define Data_Set_Struct(self,ptr) do { \
29
+ Check_Type(self, T_DATA); \
30
+ DATA_PTR(self) = ptr; \
31
31
  } while (0)
32
32
 
33
33
  static VALUE rb_cPGconn;
@@ -38,18 +38,14 @@ static VALUE rb_ePGError;
38
38
  * UTILITY FUNCTIONS
39
39
  **************************************************************************/
40
40
 
41
- static VALUE pgresult_fields _((VALUE));
42
- static VALUE pgresult_clear _((VALUE));
43
- static VALUE pgresult_new _((PGresult*));
44
-
45
41
  static void free_pgconn(PGconn *);
46
42
  static void pgresult_check(VALUE, VALUE);
47
43
 
48
44
  static int build_key_value_string_i(VALUE key, VALUE value, VALUE result);
49
- static PGconn *get_pgconn(VALUE obj);
45
+ static PGconn *get_pgconn(VALUE self);
50
46
  static VALUE pgconn_finish(VALUE self);
51
47
 
52
- static VALUE pg_escape_regex;
48
+ //static VALUE pg_escape_regex;
53
49
  static VALUE pg_escape_str;
54
50
  static ID pg_gsub_bang_id;
55
51
 
@@ -63,8 +59,8 @@ pgconn_s_quote_connstr(string)
63
59
 
64
60
  Check_Type(string, T_STRING);
65
61
 
66
- ptr = RSTRING(string)->ptr;
67
- len = RSTRING(string)->len;
62
+ ptr = RSTRING_PTR(string);
63
+ len = RSTRING_LEN(string);
68
64
  str = ALLOCA_N(char, len * 2 + 2 + 1);
69
65
  str[j++] = '\'';
70
66
  for(i = 0; i < len; i++) {
@@ -78,17 +74,19 @@ pgconn_s_quote_connstr(string)
78
74
  return result;
79
75
  }
80
76
 
77
+ //TODO broken
81
78
  static int
82
79
  build_key_value_string_i(key, value, result)
83
80
  VALUE key, value, result;
84
81
  {
85
82
  VALUE key_value;
86
- if (key == Qundef) return ST_CONTINUE;
83
+ //if (key == Qundef) return ST_CONTINUE;
87
84
  key_value = (TYPE(key) == T_STRING ? rb_str_dup(key) : rb_obj_as_string(key));
88
85
  rb_str_cat(key_value, "=", 1);
89
86
  rb_str_concat(key_value, pgconn_s_quote_connstr(value));
90
87
  rb_ary_push(result, key_value);
91
- return ST_CONTINUE;
88
+ //return ST_CONTINUE;
89
+ return 0;
92
90
  }
93
91
 
94
92
  static void
@@ -105,6 +103,7 @@ pgconn_alloc(klass)
105
103
  return Data_Wrap_Struct(klass, 0, free_pgconn, NULL);
106
104
  }
107
105
 
106
+ //TODO broken on 1.9
108
107
  static PGconn *
109
108
  try_connectdb(arg)
110
109
  VALUE arg;
@@ -114,11 +113,11 @@ try_connectdb(arg)
114
113
  if (!NIL_P(conninfo = rb_check_string_type(arg))) {
115
114
  /* do nothing */
116
115
  }
117
- else if (!NIL_P(conninfo = rb_check_hash_type(arg))) {
118
- VALUE key_values = rb_ary_new2(RHASH(conninfo)->tbl->num_entries);
119
- rb_hash_foreach(conninfo, build_key_value_string_i, key_values);
120
- conninfo = rb_ary_join(key_values, rb_str_new2(" "));
121
- }
116
+ //else if (!NIL_P(conninfo = rb_check_hash_type(arg))) {
117
+ // VALUE key_values = rb_ary_new2(RHASH(conninfo)->tbl->num_entries);
118
+ // rb_hash_foreach(conninfo, build_key_value_string_i, key_values);
119
+ // conninfo = rb_ary_join(key_values, rb_str_new2(" "));
120
+ //}
122
121
  else {
123
122
  return NULL;
124
123
  }
@@ -151,22 +150,22 @@ try_setdbLogin(args)
151
150
  }
152
151
 
153
152
  static PGconn*
154
- get_pgconn(obj)
155
- VALUE obj;
153
+ get_pgconn(self)
154
+ VALUE self;
156
155
  {
157
156
  PGconn *conn;
158
157
 
159
- Data_Get_Struct(obj, PGconn, conn);
158
+ Data_Get_Struct(self, PGconn, conn);
160
159
  if (conn == NULL) rb_raise(rb_ePGError, "closed connection");
161
160
  return conn;
162
161
  }
163
162
 
164
163
  static PGresult*
165
- get_pgresult(obj)
166
- VALUE obj;
164
+ get_pgresult(self)
165
+ VALUE self;
167
166
  {
168
167
  PGresult *result;
169
- Data_Get_Struct(obj, PGresult, result);
168
+ Data_Get_Struct(self, PGresult, result);
170
169
  if (result == NULL) rb_raise(rb_ePGError, "query not performed");
171
170
  return result;
172
171
  }
@@ -269,8 +268,6 @@ pgresult_check(VALUE rb_pgconn, VALUE rb_pgresult)
269
268
  * #exec
270
269
  * #query
271
270
  *
272
- * #async_exec
273
- * #async_query
274
271
  *
275
272
  * #get_notify
276
273
  * #on_notice
@@ -316,9 +313,9 @@ pgconn_s_new(argc, argv, klass)
316
313
  VALUE *argv;
317
314
  VALUE klass;
318
315
  {
319
- VALUE obj = rb_obj_alloc(klass);
320
- rb_obj_call_init(obj, argc, argv);
321
- return obj;
316
+ VALUE self = rb_obj_alloc(klass);
317
+ rb_obj_call_init(self, argc, argv);
318
+ return self;
322
319
  }
323
320
  #endif
324
321
 
@@ -376,8 +373,8 @@ pgconn_init(argc, argv, self)
376
373
  * Return value is the encrypted password.
377
374
  */
378
375
  static VALUE
379
- pgconn_s_encrypt_password(obj, password, username)
380
- VALUE obj, password, username;
376
+ pgconn_s_encrypt_password(self, password, username)
377
+ VALUE self, password, username;
381
378
  {
382
379
  Check_Type(password, T_STRING);
383
380
  Check_Type(username, T_STRING);
@@ -393,8 +390,8 @@ pgconn_s_encrypt_password(obj, password, username)
393
390
  * Returns +true+ if libpq is thread safe, +false+ otherwise.
394
391
  */
395
392
  static VALUE
396
- pgconn_s_isthreadsafe(obj)
397
- VALUE obj;
393
+ pgconn_s_isthreadsafe(self)
394
+ VALUE self;
398
395
  {
399
396
  return PQisthreadsafe() ? Qtrue : Qfalse;
400
397
  }
@@ -425,11 +422,11 @@ pgconn_finish(self)
425
422
  * Resets the backend connection. This method closes the backend connection and tries to re-connect.
426
423
  */
427
424
  static VALUE
428
- pgconn_reset(obj)
429
- VALUE obj;
425
+ pgconn_reset(self)
426
+ VALUE self;
430
427
  {
431
- PQreset(get_pgconn(obj));
432
- return obj;
428
+ PQreset(get_pgconn(self));
429
+ return self;
433
430
  }
434
431
 
435
432
  //TODO conn.reset_start
@@ -443,10 +440,10 @@ pgconn_reset(obj)
443
440
  * Returns the connected database name.
444
441
  */
445
442
  static VALUE
446
- pgconn_db(obj)
447
- VALUE obj;
443
+ pgconn_db(self)
444
+ VALUE self;
448
445
  {
449
- char *db = PQdb(get_pgconn(obj));
446
+ char *db = PQdb(get_pgconn(self));
450
447
  if (!db) return Qnil;
451
448
  return rb_tainted_str_new2(db);
452
449
  }
@@ -458,10 +455,10 @@ pgconn_db(obj)
458
455
  * Returns the authenticated user name.
459
456
  */
460
457
  static VALUE
461
- pgconn_user(obj)
462
- VALUE obj;
458
+ pgconn_user(self)
459
+ VALUE self;
463
460
  {
464
- char *user = PQuser(get_pgconn(obj));
461
+ char *user = PQuser(get_pgconn(self));
465
462
  if (!user) return Qnil;
466
463
  return rb_tainted_str_new2(user);
467
464
  }
@@ -473,10 +470,10 @@ pgconn_user(obj)
473
470
  * Returns the authenticated user name.
474
471
  */
475
472
  static VALUE
476
- pgconn_pass(obj)
477
- VALUE obj;
473
+ pgconn_pass(self)
474
+ VALUE self;
478
475
  {
479
- char *user = PQpass(get_pgconn(obj));
476
+ char *user = PQpass(get_pgconn(self));
480
477
  if (!user) return Qnil;
481
478
  return rb_tainted_str_new2(user);
482
479
  }
@@ -488,10 +485,10 @@ pgconn_pass(obj)
488
485
  * Returns the connected server name.
489
486
  */
490
487
  static VALUE
491
- pgconn_host(obj)
492
- VALUE obj;
488
+ pgconn_host(self)
489
+ VALUE self;
493
490
  {
494
- char *host = PQhost(get_pgconn(obj));
491
+ char *host = PQhost(get_pgconn(self));
495
492
  if (!host) return Qnil;
496
493
  return rb_tainted_str_new2(host);
497
494
  }
@@ -503,10 +500,10 @@ pgconn_host(obj)
503
500
  * Returns the connected server port number.
504
501
  */
505
502
  static VALUE
506
- pgconn_port(obj)
507
- VALUE obj;
503
+ pgconn_port(self)
504
+ VALUE self;
508
505
  {
509
- char* port = PQport(get_pgconn(obj));
506
+ char* port = PQport(get_pgconn(self));
510
507
  return INT2NUM(atol(port));
511
508
  }
512
509
 
@@ -517,10 +514,10 @@ pgconn_port(obj)
517
514
  * Returns the connected pgtty.
518
515
  */
519
516
  static VALUE
520
- pgconn_tty(obj)
521
- VALUE obj;
517
+ pgconn_tty(self)
518
+ VALUE self;
522
519
  {
523
- char *tty = PQtty(get_pgconn(obj));
520
+ char *tty = PQtty(get_pgconn(self));
524
521
  if (!tty) return Qnil;
525
522
  return rb_tainted_str_new2(tty);
526
523
  }
@@ -532,10 +529,10 @@ pgconn_tty(obj)
532
529
  * Returns backend option string.
533
530
  */
534
531
  static VALUE
535
- pgconn_options(obj)
536
- VALUE obj;
532
+ pgconn_options(self)
533
+ VALUE self;
537
534
  {
538
- char *options = PQoptions(get_pgconn(obj));
535
+ char *options = PQoptions(get_pgconn(self));
539
536
  if (!options) return Qnil;
540
537
  return rb_tainted_str_new2(options);
541
538
  }
@@ -547,10 +544,10 @@ pgconn_options(obj)
547
544
  * Returns status of connection : CONNECTION_OK or CONNECTION_BAD
548
545
  */
549
546
  static VALUE
550
- pgconn_status(obj)
551
- VALUE obj;
547
+ pgconn_status(self)
548
+ VALUE self;
552
549
  {
553
- return INT2NUM(PQstatus(get_pgconn(obj)));
550
+ return INT2NUM(PQstatus(get_pgconn(self)));
554
551
  }
555
552
 
556
553
  /*
@@ -565,10 +562,10 @@ pgconn_status(obj)
565
562
  * PQTRANS_UNKNOWN = 4 (cannot determine status)
566
563
  */
567
564
  static VALUE
568
- pgconn_transaction_status(obj)
569
- VALUE obj;
565
+ pgconn_transaction_status(self)
566
+ VALUE self;
570
567
  {
571
- return INT2NUM(PQtransactionStatus(get_pgconn(obj)));
568
+ return INT2NUM(PQtransactionStatus(get_pgconn(self)));
572
569
  }
573
570
 
574
571
  /*
@@ -590,10 +587,10 @@ pgconn_transaction_status(obj)
590
587
  * Returns nil if the value of the parameter is not known.
591
588
  */
592
589
  static VALUE
593
- pgconn_parameter_status(obj, param_name)
594
- VALUE obj, param_name;
590
+ pgconn_parameter_status(self, param_name)
591
+ VALUE self, param_name;
595
592
  {
596
- const char *ret = PQparameterStatus(get_pgconn(obj),
593
+ const char *ret = PQparameterStatus(get_pgconn(self),
597
594
  StringValuePtr(param_name));
598
595
  if(ret == NULL)
599
596
  return Qnil;
@@ -610,10 +607,10 @@ pgconn_parameter_status(obj, param_name)
610
607
  * obsolete and not supported by libpq.)
611
608
  */
612
609
  static VALUE
613
- pgconn_protocol_version(obj)
614
- VALUE obj;
610
+ pgconn_protocol_version(self)
611
+ VALUE self;
615
612
  {
616
- return INT2NUM(PQprotocolVersion(get_pgconn(obj)));
613
+ return INT2NUM(PQprotocolVersion(get_pgconn(self)));
617
614
  }
618
615
 
619
616
  /*
@@ -623,10 +620,10 @@ pgconn_protocol_version(obj)
623
620
  * The number is formed by converting the major, minor, and revision numbers into two-decimal-digit numbers and appending them together. For example, version 7.4.2 will be returned as 70402, and version 8.1 will be returned as 80100 (leading zeroes are not shown). Zero is returned if the connection is bad.
624
621
  */
625
622
  static VALUE
626
- pgconn_server_version(obj)
627
- VALUE obj;
623
+ pgconn_server_version(self)
624
+ VALUE self;
628
625
  {
629
- return INT2NUM(PQserverVersion(get_pgconn(obj)));
626
+ return INT2NUM(PQserverVersion(get_pgconn(self)));
630
627
  }
631
628
 
632
629
  /*
@@ -636,10 +633,10 @@ pgconn_server_version(obj)
636
633
  * Returns the error message about connection.
637
634
  */
638
635
  static VALUE
639
- pgconn_error_message(obj)
640
- VALUE obj;
636
+ pgconn_error_message(self)
637
+ VALUE self;
641
638
  {
642
- char *error = PQerrorMessage(get_pgconn(obj));
639
+ char *error = PQerrorMessage(get_pgconn(self));
643
640
  if (!error) return Qnil;
644
641
  return rb_tainted_str_new2(error);
645
642
  }
@@ -663,10 +660,10 @@ pgconn_error_message(obj)
663
660
  * Note that this is a PID on database server host.
664
661
  */
665
662
  static VALUE
666
- pgconn_backend_pid(obj)
667
- VALUE obj;
663
+ pgconn_backend_pid(self)
664
+ VALUE self;
668
665
  {
669
- return INT2NUM(PQbackendPID(get_pgconn(obj)));
666
+ return INT2NUM(PQbackendPID(get_pgconn(self)));
670
667
  }
671
668
 
672
669
  /*
@@ -677,10 +674,10 @@ pgconn_backend_pid(obj)
677
674
  * +false+ otherwise.
678
675
  */
679
676
  static VALUE
680
- pgconn_connection_used_password(obj)
681
- VALUE obj;
677
+ pgconn_connection_used_password(self)
678
+ VALUE self;
682
679
  {
683
- return PQconnectionUsedPassword(get_pgconn(obj)) ? Qtrue : Qfalse;
680
+ return PQconnectionUsedPassword(get_pgconn(self)) ? Qtrue : Qfalse;
684
681
  }
685
682
 
686
683
 
@@ -697,10 +694,10 @@ pgconn_connection_used_password(obj)
697
694
  *
698
695
  */
699
696
  static VALUE
700
- pgconn_exec(obj, in_command)
701
- VALUE obj, in_command;
697
+ pgconn_exec(self, in_command)
698
+ VALUE self, in_command;
702
699
  {
703
- PGconn *conn = get_pgconn(obj);
700
+ PGconn *conn = get_pgconn(self);
704
701
  PGresult *result = NULL;
705
702
  VALUE rb_pgresult;
706
703
  VALUE command;
@@ -714,7 +711,7 @@ pgconn_exec(obj, in_command)
714
711
  result = PQexec(conn, StringValuePtr(command));
715
712
 
716
713
  rb_pgresult = pgresult_new(result);
717
- pgresult_check(obj, rb_pgresult);
714
+ pgresult_check(self, rb_pgresult);
718
715
 
719
716
  return rb_pgresult;
720
717
  }
@@ -751,18 +748,18 @@ pgconn_exec(obj, in_command)
751
748
  * for binary.
752
749
  */
753
750
  static VALUE
754
- pgconn_exec_params(argc, argv, obj)
751
+ pgconn_exec_params(argc, argv, self)
755
752
  int argc;
756
753
  VALUE *argv;
757
- VALUE obj;
754
+ VALUE self;
758
755
  {
759
- PGconn *conn = get_pgconn(obj);
756
+ PGconn *conn = get_pgconn(self);
760
757
  PGresult *result = NULL;
761
758
  VALUE rb_pgresult;
762
759
  VALUE command, params, in_res_fmt;
763
760
  VALUE param, param_type, param_value, param_format;
764
761
  VALUE param_value_tmp;
765
- ID sym_type, sym_value, sym_format;
762
+ VALUE sym_type, sym_value, sym_format;
766
763
  int i=0;
767
764
 
768
765
  int nParams;
@@ -792,9 +789,9 @@ pgconn_exec_params(argc, argv, obj)
792
789
  resultFormat = NUM2INT(in_res_fmt);
793
790
  }
794
791
 
795
- sym_type = rb_to_id(rb_str_new2("type"));
796
- sym_value = rb_to_id(rb_str_new2("value"));
797
- sym_format = rb_to_id(rb_str_new2("format"));
792
+ sym_type = ID2SYM(rb_intern("type"));
793
+ sym_value = ID2SYM(rb_intern("value"));
794
+ sym_format = ID2SYM(rb_intern("format"));
798
795
 
799
796
  nParams = RARRAY(params)->len;
800
797
  paramTypes = ALLOC_N(Oid, nParams);
@@ -804,13 +801,13 @@ pgconn_exec_params(argc, argv, obj)
804
801
  for(i = 0; i < nParams; i++) {
805
802
  param = rb_ary_entry(params, i);
806
803
  if (TYPE(param) == T_HASH) {
807
- param_type = rb_hash_aref(param, ID2SYM(sym_type));
808
- param_value_tmp = rb_hash_aref(param, ID2SYM(sym_value));
804
+ param_type = rb_hash_aref(param, sym_type);
805
+ param_value_tmp = rb_hash_aref(param, sym_value);
809
806
  if(TYPE(param_value_tmp) == T_STRING)
810
807
  param_value = param_value_tmp;
811
808
  else
812
809
  param_value = rb_funcall(param_value_tmp, rb_intern("to_s"), 0);
813
- param_format = rb_hash_aref(param, ID2SYM(sym_format));
810
+ param_format = rb_hash_aref(param, sym_format);
814
811
  }
815
812
  else {
816
813
  param_type = INT2NUM(0);
@@ -822,8 +819,8 @@ pgconn_exec_params(argc, argv, obj)
822
819
  }
823
820
  Check_Type(param_value, T_STRING);
824
821
  paramTypes[i] = NUM2INT(param_type);
825
- paramValues[i] = RSTRING(param_value)->ptr;
826
- paramLengths[i] = RSTRING(param_value)->len + 1;
822
+ paramValues[i] = RSTRING_PTR(param_value);
823
+ paramLengths[i] = RSTRING_LEN(param_value) + 1;
827
824
  paramFormats[i] = NUM2INT(param_format);
828
825
  }
829
826
 
@@ -836,7 +833,7 @@ pgconn_exec_params(argc, argv, obj)
836
833
  free(paramFormats);
837
834
 
838
835
  rb_pgresult = pgresult_new(result);
839
- pgresult_check(obj, rb_pgresult);
836
+ pgresult_check(self, rb_pgresult);
840
837
 
841
838
  return rb_pgresult;
842
839
 
@@ -863,12 +860,12 @@ pgconn_exec_params(argc, argv, obj)
863
860
  * inside the SQL query.
864
861
  */
865
862
  static VALUE
866
- pgconn_prepare(argc, argv, obj)
863
+ pgconn_prepare(argc, argv, self)
867
864
  int argc;
868
865
  VALUE *argv;
869
- VALUE obj;
866
+ VALUE self;
870
867
  {
871
- PGconn *conn = get_pgconn(obj);
868
+ PGconn *conn = get_pgconn(self);
872
869
  PGresult *result = NULL;
873
870
  VALUE rb_pgresult;
874
871
  VALUE name, command, in_paramtypes;
@@ -899,7 +896,7 @@ pgconn_prepare(argc, argv, obj)
899
896
  free(paramTypes);
900
897
 
901
898
  rb_pgresult = pgresult_new(result);
902
- pgresult_check(obj, rb_pgresult);
899
+ pgresult_check(self, rb_pgresult);
903
900
 
904
901
  return rb_pgresult;
905
902
 
@@ -930,18 +927,18 @@ pgconn_prepare(argc, argv, obj)
930
927
  * for binary.
931
928
  */
932
929
  static VALUE
933
- pgconn_exec_prepared(argc, argv, obj)
930
+ pgconn_exec_prepared(argc, argv, self)
934
931
  int argc;
935
932
  VALUE *argv;
936
- VALUE obj;
933
+ VALUE self;
937
934
  {
938
- PGconn *conn = get_pgconn(obj);
935
+ PGconn *conn = get_pgconn(self);
939
936
  PGresult *result = NULL;
940
937
  VALUE rb_pgresult;
941
938
  VALUE name, params, in_res_fmt;
942
939
  VALUE param, param_value, param_format;
943
940
  VALUE param_value_tmp;
944
- ID sym_value, sym_format;
941
+ VALUE sym_value, sym_format;
945
942
  int i = 0;
946
943
 
947
944
  int nParams;
@@ -970,8 +967,8 @@ pgconn_exec_prepared(argc, argv, obj)
970
967
  resultFormat = NUM2INT(in_res_fmt);
971
968
  }
972
969
 
973
- sym_value = rb_to_id(rb_str_new2("value"));
974
- sym_format = rb_to_id(rb_str_new2("format"));
970
+ sym_value = ID2SYM(rb_intern("value"));
971
+ sym_format = ID2SYM(rb_intern("format"));
975
972
 
976
973
  nParams = RARRAY(params)->len;
977
974
  paramValues = ALLOC_N(char *, nParams);
@@ -980,12 +977,12 @@ pgconn_exec_prepared(argc, argv, obj)
980
977
  for(i = 0; i < nParams; i++) {
981
978
  param = rb_ary_entry(params, i);
982
979
  if (TYPE(param) == T_HASH) {
983
- param_value_tmp = rb_hash_aref(param, ID2SYM(sym_value));
980
+ param_value_tmp = rb_hash_aref(param, sym_value);
984
981
  if(TYPE(param_value_tmp) == T_STRING)
985
982
  param_value = param_value_tmp;
986
983
  else
987
984
  param_value = rb_funcall(param_value_tmp, rb_intern("to_s"), 0);
988
- param_format = rb_hash_aref(param, ID2SYM(sym_format));
985
+ param_format = rb_hash_aref(param, sym_format);
989
986
  }
990
987
  else {
991
988
  if(TYPE(param) == T_STRING)
@@ -995,8 +992,8 @@ pgconn_exec_prepared(argc, argv, obj)
995
992
  param_format = INT2NUM(0);
996
993
  }
997
994
  Check_Type(param_value, T_STRING);
998
- paramValues[i] = RSTRING(param_value)->ptr;
999
- paramLengths[i] = RSTRING(param_value)->len + 1;
995
+ paramValues[i] = RSTRING_PTR(param_value);
996
+ paramLengths[i] = RSTRING_LEN(param_value) + 1;
1000
997
  paramFormats[i] = NUM2INT(param_format);
1001
998
  }
1002
999
 
@@ -1009,15 +1006,66 @@ pgconn_exec_prepared(argc, argv, obj)
1009
1006
  free(paramFormats);
1010
1007
 
1011
1008
  rb_pgresult = pgresult_new(result);
1012
- pgresult_check(obj, rb_pgresult);
1009
+ pgresult_check(self, rb_pgresult);
1013
1010
 
1014
1011
  return rb_pgresult;
1015
1012
  }
1016
1013
 
1017
- // TODO describe_prepared
1014
+ /*
1015
+ * call-seq:
1016
+ * conn.describe_prepared( statement_name ) -> PGresult
1017
+ *
1018
+ * Retrieve information about the prepared statement
1019
+ * _statement_name_.
1020
+ */
1021
+ static VALUE
1022
+ pgconn_describe_prepared(self, stmt_name)
1023
+ VALUE self, stmt_name;
1024
+ {
1025
+ PGconn *conn = get_pgconn(self);
1026
+ PGresult *result;
1027
+ VALUE rb_pgresult;
1028
+ char *stmt;
1029
+ if(stmt_name == Qnil) {
1030
+ stmt = NULL;
1031
+ }
1032
+ else {
1033
+ Check_Type(stmt_name, T_STRING);
1034
+ stmt = StringValuePtr(stmt_name);
1035
+ }
1036
+ result = PQdescribePrepared(conn, stmt);
1037
+ rb_pgresult = pgresult_new(result);
1038
+ pgresult_check(self, rb_pgresult);
1039
+ return rb_pgresult;
1040
+ }
1018
1041
 
1019
1042
 
1020
- // TODO describe_portal
1043
+ /*
1044
+ * call-seq:
1045
+ * conn.describe_portal( portal_name ) -> PGresult
1046
+ *
1047
+ * Retrieve information about the portal _portal_name_.
1048
+ */
1049
+ static VALUE
1050
+ pgconn_describe_portal(self, stmt_name)
1051
+ VALUE self, stmt_name;
1052
+ {
1053
+ PGconn *conn = get_pgconn(self);
1054
+ PGresult *result;
1055
+ VALUE rb_pgresult;
1056
+ char *stmt;
1057
+ if(stmt_name == Qnil) {
1058
+ stmt = NULL;
1059
+ }
1060
+ else {
1061
+ Check_Type(stmt_name, T_STRING);
1062
+ stmt = StringValuePtr(stmt_name);
1063
+ }
1064
+ result = PQdescribePortal(conn, stmt);
1065
+ rb_pgresult = pgresult_new(result);
1066
+ pgresult_check(self, rb_pgresult);
1067
+ return rb_pgresult;
1068
+ }
1021
1069
 
1022
1070
 
1023
1071
  // TODO make_empty_pgresult
@@ -1049,16 +1097,16 @@ pgconn_s_escape(self, string)
1049
1097
 
1050
1098
  Check_Type(string, T_STRING);
1051
1099
 
1052
- escaped = ALLOCA_N(char, RSTRING(string)->len * 2 + 1);
1100
+ escaped = ALLOCA_N(char, RSTRING_LEN(string) * 2 + 1);
1053
1101
  if(CLASS_OF(self) == rb_cPGconn) {
1054
- size = PQescapeStringConn(get_pgconn(self),escaped, RSTRING(string)->ptr,
1055
- RSTRING(string)->len, &error);
1102
+ size = PQescapeStringConn(get_pgconn(self),escaped, RSTRING_PTR(string),
1103
+ RSTRING_LEN(string), &error);
1056
1104
  if(error) {
1057
1105
  rb_raise(rb_ePGError, PQerrorMessage(get_pgconn(self)));
1058
1106
  }
1059
1107
  } else {
1060
- size = PQescapeString(escaped, RSTRING(string)->ptr,
1061
- RSTRING(string)->len);
1108
+ size = PQescapeString(escaped, RSTRING_PTR(string),
1109
+ RSTRING_LEN(string));
1062
1110
  }
1063
1111
  result = rb_str_new(escaped, size);
1064
1112
  OBJ_INFECT(result, string);
@@ -1067,8 +1115,8 @@ pgconn_s_escape(self, string)
1067
1115
 
1068
1116
  /*
1069
1117
  * call-seq:
1070
- * conn.escape_bytea( obj ) -> String
1071
- * PGconn.escape_bytea( obj ) -> String # DEPRECATED
1118
+ * conn.escape_bytea( self ) -> String
1119
+ * PGconn.escape_bytea( self ) -> String # DEPRECATED
1072
1120
  *
1073
1121
  * Connection instance method for versions of 8.1 and higher of libpq
1074
1122
  * uses PQescapeByteaConn, which is safer. Avoid calling as a class method,
@@ -1090,17 +1138,17 @@ pgconn_s_escape(self, string)
1090
1138
  * SQL commands.
1091
1139
  */
1092
1140
  static VALUE
1093
- pgconn_s_escape_bytea(self, obj)
1141
+ pgconn_s_escape_bytea(self, str)
1094
1142
  VALUE self;
1095
- VALUE obj;
1143
+ VALUE str;
1096
1144
  {
1097
1145
  char *from, *to;
1098
1146
  size_t from_len, to_len;
1099
1147
  VALUE ret;
1100
1148
 
1101
- Check_Type(obj, T_STRING);
1102
- from = RSTRING(obj)->ptr;
1103
- from_len = RSTRING(obj)->len;
1149
+ Check_Type(str, T_STRING);
1150
+ from = RSTRING_PTR(str);
1151
+ from_len = RSTRING_LEN(str);
1104
1152
 
1105
1153
  if(CLASS_OF(self) == rb_cPGconn) {
1106
1154
  to = (char *)PQescapeByteaConn(get_pgconn(self),(unsigned char*)from, from_len, &to_len);
@@ -1109,7 +1157,7 @@ pgconn_s_escape_bytea(self, obj)
1109
1157
  }
1110
1158
 
1111
1159
  ret = rb_str_new(to, to_len - 1);
1112
- OBJ_INFECT(ret, obj);
1160
+ OBJ_INFECT(ret, str);
1113
1161
 
1114
1162
  PQfreemem(to);
1115
1163
 
@@ -1119,7 +1167,7 @@ pgconn_s_escape_bytea(self, obj)
1119
1167
 
1120
1168
  /*
1121
1169
  * call-seq:
1122
- * PGconn.unescape_bytea( obj )
1170
+ * PGconn.unescape_bytea( self )
1123
1171
  *
1124
1172
  * Converts an escaped string representation of binary data into binary data --- the
1125
1173
  * reverse of #escape_bytea. This is needed when retrieving +bytea+ data in text format,
@@ -1127,20 +1175,20 @@ pgconn_s_escape_bytea(self, obj)
1127
1175
  *
1128
1176
  */
1129
1177
  static VALUE
1130
- pgconn_s_unescape_bytea(self, obj)
1131
- VALUE self, obj;
1178
+ pgconn_s_unescape_bytea(self, str)
1179
+ VALUE self, str;
1132
1180
  {
1133
1181
  char *from, *to;
1134
1182
  size_t to_len;
1135
1183
  VALUE ret;
1136
1184
 
1137
- Check_Type(obj, T_STRING);
1138
- from = StringValuePtr(obj);
1185
+ Check_Type(str, T_STRING);
1186
+ from = StringValuePtr(str);
1139
1187
 
1140
1188
  to = (char *) PQunescapeBytea( (unsigned char*) from, &to_len);
1141
1189
 
1142
1190
  ret = rb_str_new(to, to_len);
1143
- OBJ_INFECT(ret, obj);
1191
+ OBJ_INFECT(ret, str);
1144
1192
  PQfreemem(to);
1145
1193
 
1146
1194
  return ret;
@@ -1154,15 +1202,15 @@ pgconn_s_unescape_bytea(self, obj)
1154
1202
  * Use in combination with +conn.get_result+.
1155
1203
  */
1156
1204
  static VALUE
1157
- pgconn_send_query(obj, command)
1158
- VALUE obj, command;
1205
+ pgconn_send_query(self, command)
1206
+ VALUE self, command;
1159
1207
  {
1160
1208
  VALUE error;
1161
- PGconn *conn = get_pgconn(obj);
1209
+ PGconn *conn = get_pgconn(self);
1162
1210
  /* returns 0 on failure */
1163
1211
  if(PQsendQuery(conn,StringValuePtr(command)) == 0) {
1164
1212
  error = rb_exc_new2(rb_ePGError, PQerrorMessage(conn));
1165
- rb_iv_set(error, "@connection", obj);
1213
+ rb_iv_set(error, "@connection", self);
1166
1214
  rb_raise(error, PQerrorMessage(conn));
1167
1215
  }
1168
1216
  return Qnil;
@@ -1179,15 +1227,15 @@ pgconn_send_query(obj, command)
1179
1227
  * Use in combination with +conn.get_result+.
1180
1228
  */
1181
1229
  static VALUE
1182
- pgconn_send_prepare(obj, command)
1183
- VALUE obj, command;
1230
+ pgconn_send_prepare(self, command)
1231
+ VALUE self, command;
1184
1232
  {
1185
1233
  VALUE error;
1186
- PGconn *conn = get_pgconn(obj);
1234
+ PGconn *conn = get_pgconn(self);
1187
1235
  /* returns 0 on failure */
1188
1236
  if(PQsendQuery(conn,StringValuePtr(command)) == 0) {
1189
1237
  error = rb_exc_new2(rb_ePGError, PQerrorMessage(conn));
1190
- rb_iv_set(error, "@connection", obj);
1238
+ rb_iv_set(error, "@connection", self);
1191
1239
  rb_raise(error, PQerrorMessage(conn));
1192
1240
  }
1193
1241
  return Qnil;
@@ -1204,15 +1252,15 @@ pgconn_send_prepare(obj, command)
1204
1252
  * Use in combination with +conn.get_result+.
1205
1253
  */
1206
1254
  static VALUE
1207
- pgconn_send_describe_prepared(obj, stmt_name)
1208
- VALUE obj, stmt_name;
1255
+ pgconn_send_describe_prepared(self, stmt_name)
1256
+ VALUE self, stmt_name;
1209
1257
  {
1210
1258
  VALUE error;
1211
- PGconn *conn = get_pgconn(obj);
1259
+ PGconn *conn = get_pgconn(self);
1212
1260
  /* returns 0 on failure */
1213
1261
  if(PQsendDescribePrepared(conn,StringValuePtr(stmt_name)) == 0) {
1214
1262
  error = rb_exc_new2(rb_ePGError, PQerrorMessage(conn));
1215
- rb_iv_set(error, "@connection", obj);
1263
+ rb_iv_set(error, "@connection", self);
1216
1264
  rb_raise(error, PQerrorMessage(conn));
1217
1265
  }
1218
1266
  return Qnil;
@@ -1227,15 +1275,15 @@ pgconn_send_describe_prepared(obj, stmt_name)
1227
1275
  * Use in combination with +conn.get_result+.
1228
1276
  */
1229
1277
  static VALUE
1230
- pgconn_send_describe_portal(obj, portal)
1231
- VALUE obj, portal;
1278
+ pgconn_send_describe_portal(self, portal)
1279
+ VALUE self, portal;
1232
1280
  {
1233
1281
  VALUE error;
1234
- PGconn *conn = get_pgconn(obj);
1282
+ PGconn *conn = get_pgconn(self);
1235
1283
  /* returns 0 on failure */
1236
1284
  if(PQsendDescribePortal(conn,StringValuePtr(portal)) == 0) {
1237
1285
  error = rb_exc_new2(rb_ePGError, PQerrorMessage(conn));
1238
- rb_iv_set(error, "@connection", obj);
1286
+ rb_iv_set(error, "@connection", self);
1239
1287
  rb_raise(error, PQerrorMessage(conn));
1240
1288
  }
1241
1289
  return Qnil;
@@ -1250,18 +1298,18 @@ pgconn_send_describe_portal(obj, portal)
1250
1298
  * Use in combination with +conn.get_result+.
1251
1299
  */
1252
1300
  static VALUE
1253
- pgconn_get_result(obj)
1254
- VALUE obj;
1301
+ pgconn_get_result(self)
1302
+ VALUE self;
1255
1303
  {
1256
1304
  PGresult *result;
1257
1305
  VALUE rb_pgresult;
1258
1306
 
1259
- result = PQgetResult(get_pgconn(obj));
1307
+ result = PQgetResult(get_pgconn(self));
1260
1308
  if(result == NULL)
1261
1309
  return Qnil;
1262
1310
 
1263
1311
  rb_pgresult = pgresult_new(result);
1264
- pgresult_check(obj, rb_pgresult);
1312
+ pgresult_check(self, rb_pgresult);
1265
1313
 
1266
1314
  return rb_pgresult;
1267
1315
  }
@@ -1275,15 +1323,15 @@ pgconn_get_result(obj)
1275
1323
  * or *notifies* to see if the state has changed.
1276
1324
  */
1277
1325
  static VALUE
1278
- pgconn_consume_input(obj)
1279
- VALUE obj;
1326
+ pgconn_consume_input(self)
1327
+ VALUE self;
1280
1328
  {
1281
1329
  VALUE error;
1282
- PGconn *conn = get_pgconn(obj);
1330
+ PGconn *conn = get_pgconn(self);
1283
1331
  /* returns 0 on error */
1284
1332
  if(PQconsumeInput(conn) == 0) {
1285
1333
  error = rb_exc_new2(rb_ePGError, PQerrorMessage(conn));
1286
- rb_iv_set(error, "@connection", obj);
1334
+ rb_iv_set(error, "@connection", self);
1287
1335
  rb_raise(error, PQerrorMessage(conn));
1288
1336
  }
1289
1337
  return Qnil;
@@ -1297,10 +1345,10 @@ pgconn_consume_input(obj)
1297
1345
  * PQgetResult would block. Otherwise returns +false+.
1298
1346
  */
1299
1347
  static VALUE
1300
- pgconn_is_busy(obj)
1301
- VALUE obj;
1348
+ pgconn_is_busy(self)
1349
+ VALUE self;
1302
1350
  {
1303
- return PQisBusy(get_pgconn(obj)) ? Qtrue : Qfalse;
1351
+ return PQisBusy(get_pgconn(self)) ? Qtrue : Qfalse;
1304
1352
  }
1305
1353
 
1306
1354
  /*
@@ -1311,12 +1359,12 @@ pgconn_is_busy(obj)
1311
1359
  * PQgetResult would block. Otherwise returns +false+.
1312
1360
  */
1313
1361
  static VALUE
1314
- pgconn_setnonblocking(obj, state)
1315
- VALUE obj, state;
1362
+ pgconn_setnonblocking(self, state)
1363
+ VALUE self, state;
1316
1364
  {
1317
1365
  int arg;
1318
1366
  VALUE error;
1319
- PGconn *conn = get_pgconn(obj);
1367
+ PGconn *conn = get_pgconn(self);
1320
1368
  if(state == Qtrue)
1321
1369
  arg = 1;
1322
1370
  else if (state == Qfalse)
@@ -1326,7 +1374,7 @@ pgconn_setnonblocking(obj, state)
1326
1374
 
1327
1375
  if(PQsetnonblocking(conn, arg) == -1) {
1328
1376
  error = rb_exc_new2(rb_ePGError, PQerrorMessage(conn));
1329
- rb_iv_set(error, "@connection", obj);
1377
+ rb_iv_set(error, "@connection", self);
1330
1378
  rb_raise(error, PQerrorMessage(conn));
1331
1379
  }
1332
1380
  return Qnil;
@@ -1341,10 +1389,10 @@ pgconn_setnonblocking(obj, state)
1341
1389
  * PQgetResult would block. Otherwise returns +false+.
1342
1390
  */
1343
1391
  static VALUE
1344
- pgconn_isnonblocking(obj)
1345
- VALUE obj;
1392
+ pgconn_isnonblocking(self)
1393
+ VALUE self;
1346
1394
  {
1347
- return PQisnonblocking(get_pgconn(obj)) ? Qtrue : Qfalse;
1395
+ return PQisnonblocking(get_pgconn(self)) ? Qtrue : Qfalse;
1348
1396
  }
1349
1397
 
1350
1398
  /*TODO
@@ -1355,10 +1403,10 @@ pgconn_isnonblocking(obj)
1355
1403
  * PQgetResult would block. Otherwise returns +false+.
1356
1404
  */
1357
1405
  static VALUE
1358
- pgconn_flush(obj)
1359
- VALUE obj;
1406
+ pgconn_flush(self)
1407
+ VALUE self;
1360
1408
  {
1361
- //if(PQflush(get_pgconn(obj)))
1409
+ //if(PQflush(get_pgconn(self)))
1362
1410
  return Qnil;
1363
1411
  }
1364
1412
 
@@ -1370,7 +1418,49 @@ pgconn_flush(obj)
1370
1418
 
1371
1419
  //TODO fn
1372
1420
 
1373
- //TODO notifies
1421
+ /*
1422
+ * call-seq:
1423
+ * conn.notifies()
1424
+ *
1425
+ * Returns an array of the unprocessed notifiers.
1426
+ * If there is no unprocessed notifier, it returns +nil+.
1427
+ */
1428
+ static VALUE
1429
+ pgconn_notifies(self)
1430
+ VALUE self;
1431
+ {
1432
+ PGconn* conn = get_pgconn(self);
1433
+ PGnotify *notify;
1434
+ VALUE hash;
1435
+ VALUE sym_relname, sym_be_pid, sym_extra;
1436
+ VALUE relname, be_pid, extra;
1437
+
1438
+ sym_relname = ID2SYM(rb_intern("relname"));
1439
+ sym_be_pid = ID2SYM(rb_intern("be_pid"));
1440
+ sym_extra = ID2SYM(rb_intern("extra"));
1441
+
1442
+ /* gets notify and builds result */
1443
+ notify = PQnotifies(conn);
1444
+ if (notify == NULL) {
1445
+ /* there are no unhandled notifications */
1446
+ return Qnil;
1447
+ }
1448
+
1449
+ hash = rb_hash_new();
1450
+ relname = rb_tainted_str_new2(notify->relname);
1451
+ be_pid = INT2NUM(notify->be_pid);
1452
+ extra = rb_tainted_str_new2(notify->extra);
1453
+
1454
+ rb_hash_aset(hash, sym_relname, relname);
1455
+ rb_hash_aset(hash, sym_be_pid, be_pid);
1456
+ rb_hash_aset(hash, sym_extra, extra);
1457
+
1458
+ PQfreemem(notify);
1459
+
1460
+ /* returns result */
1461
+ return hash;
1462
+ }
1463
+
1374
1464
 
1375
1465
  /*
1376
1466
  * call-seq:
@@ -1384,27 +1474,105 @@ pgconn_flush(obj)
1384
1474
  * Raises an exception if an error occurs.
1385
1475
  */
1386
1476
  static VALUE
1387
- pgconn_put_copy_data(obj, buffer)
1388
- VALUE obj, buffer;
1477
+ pgconn_put_copy_data(self, buffer)
1478
+ VALUE self, buffer;
1389
1479
  {
1390
1480
  int ret;
1391
1481
  VALUE error;
1392
- PGconn *conn = get_pgconn(obj);
1482
+ PGconn *conn = get_pgconn(self);
1393
1483
  Check_Type(buffer, T_STRING);
1394
1484
 
1395
- ret = PQputCopyData(conn, RSTRING(buffer)->ptr,
1396
- RSTRING(buffer)->len);
1485
+ ret = PQputCopyData(conn, RSTRING_PTR(buffer),
1486
+ RSTRING_LEN(buffer));
1397
1487
  if(ret == -1) {
1398
1488
  error = rb_exc_new2(rb_ePGError, PQerrorMessage(conn));
1399
- rb_iv_set(error, "@connection", obj);
1489
+ rb_iv_set(error, "@connection", self);
1400
1490
  rb_raise(error, PQerrorMessage(conn));
1401
1491
  }
1402
1492
  return (ret) ? Qtrue : Qfalse;
1403
1493
  }
1404
1494
 
1405
- //TODO put_copy_end
1495
+ /*
1496
+ * call-seq:
1497
+ * conn.put_copy_end( [ error_message ] ) -> Boolean
1498
+ *
1499
+ * Sends end-of-data indication to the server.
1500
+ *
1501
+ * _error_message_ is an optional parameter, and if set,
1502
+ * forces the COPY command to fail with the string
1503
+ * _error_message_.
1504
+ *
1505
+ * Returns true if the end-of-data was sent, false if it was
1506
+ * not sent (false is only possible if the connection
1507
+ * is in nonblocking mode, and this command would block).
1508
+ */
1509
+ static VALUE
1510
+ pgconn_put_copy_end(argc, argv, self)
1511
+ int argc;
1512
+ VALUE *argv;
1513
+ VALUE self;
1514
+ {
1515
+ VALUE str;
1516
+ VALUE error;
1517
+ int ret;
1518
+ char *error_message = NULL;
1519
+ PGconn *conn = get_pgconn(self);
1520
+
1521
+ if (rb_scan_args(argc, argv, "01", &str) == 0)
1522
+ error_message = NULL;
1523
+ else
1524
+ error_message = StringValuePtr(str);
1525
+
1526
+ ret = PQputCopyEnd(conn, error_message);
1527
+ if(ret == -1) {
1528
+ error = rb_exc_new2(rb_ePGError, PQerrorMessage(conn));
1529
+ rb_iv_set(error, "@connection", self);
1530
+ rb_raise(error, PQerrorMessage(conn));
1531
+ }
1532
+ return (ret) ? Qtrue : Qfalse;
1533
+ }
1406
1534
 
1407
- //TODO get_copy_data
1535
+ /*
1536
+ * call-seq:
1537
+ * conn.get_copy_data( [ async = false ] ) -> String
1538
+ *
1539
+ * Return a string containing one row of data, +nil+
1540
+ * if the copy is done, or +false+ if the call would
1541
+ * block (only possible if _async_ is true).
1542
+ *
1543
+ */
1544
+ static VALUE
1545
+ pgconn_get_copy_data( argc, argv, self )
1546
+ int argc;
1547
+ VALUE *argv;
1548
+ VALUE self;
1549
+ {
1550
+ VALUE async_in;
1551
+ VALUE error;
1552
+ int ret;
1553
+ int async;
1554
+ char *buffer;
1555
+ PGconn *conn = get_pgconn(self);
1556
+
1557
+ if (rb_scan_args(argc, argv, "01", &async_in) == 0)
1558
+ async = 0;
1559
+ else
1560
+ async = (async_in == Qfalse || async_in == Qnil) ? 0 : 1;
1561
+
1562
+ ret = PQgetCopyData(conn, &buffer, async);
1563
+ if(ret == -2) { // error
1564
+ error = rb_exc_new2(rb_ePGError, PQerrorMessage(conn));
1565
+ rb_iv_set(error, "@connection", self);
1566
+ rb_raise(error, PQerrorMessage(conn));
1567
+ }
1568
+ if(ret == -1) { // No data left
1569
+ return Qnil;
1570
+ }
1571
+ if(ret == 0) { // would block
1572
+ return Qfalse;
1573
+ }
1574
+ return rb_str_new(buffer, ret);
1575
+ }
1408
1576
 
1409
1577
  //TODO set_error_verbosity
1410
1578
 
@@ -1413,21 +1581,21 @@ pgconn_put_copy_data(obj, buffer)
1413
1581
  * conn.trace( port )
1414
1582
  *
1415
1583
  * Enables tracing message passing between backend.
1416
- * The trace message will be written to the _port_ object,
1584
+ * The trace message will be written to the _port_ selfect,
1417
1585
  * which is an instance of the class +File+.
1418
1586
  */
1419
1587
  static VALUE
1420
- pgconn_trace(obj, port)
1421
- VALUE obj, port;
1588
+ pgconn_trace(self, port)
1589
+ VALUE self, port;
1422
1590
  {
1423
- OpenFile* fp;
1591
+ //OpenFile* fp;
1424
1592
 
1425
1593
  Check_Type(port, T_FILE);
1426
- GetOpenFile(port, fp);
1594
+ //GetOpenFile(port, fp);
1427
1595
 
1428
- PQtrace(get_pgconn(obj), fp->f2?fp->f2:fp->f);
1596
+ //PQtrace(get_pgconn(self), fp->f2?fp->f2:fp->f);
1429
1597
 
1430
- return obj;
1598
+ return self;
1431
1599
  }
1432
1600
 
1433
1601
  /*
@@ -1437,11 +1605,11 @@ pgconn_trace(obj, port)
1437
1605
  * Disables the message tracing.
1438
1606
  */
1439
1607
  static VALUE
1440
- pgconn_untrace(obj)
1441
- VALUE obj;
1608
+ pgconn_untrace(self)
1609
+ VALUE self;
1442
1610
  {
1443
- PQuntrace(get_pgconn(obj));
1444
- return obj;
1611
+ PQuntrace(get_pgconn(self));
1612
+ return self;
1445
1613
  }
1446
1614
 
1447
1615
  //TODO set_notice_receiver
@@ -1455,10 +1623,10 @@ pgconn_untrace(obj)
1455
1623
  * Returns the client encoding as a String.
1456
1624
  */
1457
1625
  static VALUE
1458
- pgconn_client_encoding(obj)
1459
- VALUE obj;
1626
+ pgconn_client_encoding(self)
1627
+ VALUE self;
1460
1628
  {
1461
- char *encoding = (char *)pg_encoding_to_char(PQclientEncoding(get_pgconn(obj)));
1629
+ char *encoding = (char *)pg_encoding_to_char(PQclientEncoding(get_pgconn(self)));
1462
1630
  return rb_tainted_str_new2(encoding);
1463
1631
  }
1464
1632
 
@@ -1469,12 +1637,12 @@ pgconn_client_encoding(obj)
1469
1637
  * Sets the client encoding to the _encoding_ String.
1470
1638
  */
1471
1639
  static VALUE
1472
- pgconn_set_client_encoding(obj, str)
1473
- VALUE obj, str;
1640
+ pgconn_set_client_encoding(self, str)
1641
+ VALUE self, str;
1474
1642
  {
1475
1643
  Check_Type(str, T_STRING);
1476
- if ((PQsetClientEncoding(get_pgconn(obj), StringValuePtr(str))) == -1){
1477
- rb_raise(rb_ePGError, "invalid encoding name %s",str);
1644
+ if ((PQsetClientEncoding(get_pgconn(self), StringValuePtr(str))) == -1){
1645
+ rb_raise(rb_ePGError, "invalid encoding name %s",StringValuePtr(str));
1478
1646
  }
1479
1647
  return Qnil;
1480
1648
  }
@@ -1482,107 +1650,6 @@ pgconn_set_client_encoding(obj, str)
1482
1650
  /**** TODO ?????????? ******/
1483
1651
 
1484
1652
 
1485
- /*
1486
- * call-seq:
1487
- * conn.get_notify()
1488
- *
1489
- * Returns an array of the unprocessed notifiers.
1490
- * If there is no unprocessed notifier, it returns +nil+.
1491
- */
1492
- static VALUE
1493
- pgconn_get_notify(obj)
1494
- VALUE obj;
1495
- {
1496
- PGconn* conn = get_pgconn(obj);
1497
- PGnotify *notify;
1498
- VALUE ary;
1499
-
1500
- if (PQconsumeInput(conn) == 0) {
1501
- rb_raise(rb_ePGError, PQerrorMessage(conn));
1502
- }
1503
- /* gets notify and builds result */
1504
- notify = PQnotifies(conn);
1505
- if (notify == NULL) {
1506
- /* there are no unhandled notifications */
1507
- return Qnil;
1508
- }
1509
- ary = rb_ary_new3(2, rb_tainted_str_new2(notify->relname), INT2NUM(notify->be_pid));
1510
- PQfreemem(notify);
1511
-
1512
- /* returns result */
1513
- return ary;
1514
- }
1515
-
1516
- /*
1517
- * call-seq:
1518
- * conn.putline()
1519
- *
1520
- * Sends the string to the backend server.
1521
- * Users must send a single "." to denote the end of data transmission.
1522
- */
1523
- static VALUE
1524
- pgconn_putline(obj, str)
1525
- VALUE obj, str;
1526
- {
1527
- Check_Type(str, T_STRING);
1528
- PQputline(get_pgconn(obj), StringValuePtr(str));
1529
- return obj;
1530
- }
1531
-
1532
- /*
1533
- * call-seq:
1534
- * conn.getline()
1535
- *
1536
- * Reads a line from the backend server into internal buffer.
1537
- * Returns +nil+ for EOF, +0+ for success, +1+ for buffer overflowed.
1538
- * You need to ensure single "." from backend to confirm transmission completion.
1539
- * The sample program <tt>psql.rb</tt> (see source for postgres) treats this copy protocol right.
1540
- */
1541
- static VALUE
1542
- pgconn_getline(obj)
1543
- VALUE obj;
1544
- {
1545
- PGconn *conn = get_pgconn(obj);
1546
- VALUE str;
1547
- long size = BUFSIZ;
1548
- long bytes = 0;
1549
- int ret;
1550
-
1551
- str = rb_tainted_str_new(0, size);
1552
-
1553
- for (;;) {
1554
- ret = PQgetline(conn, RSTRING(str)->ptr + bytes, size - bytes);
1555
- switch (ret) {
1556
- case EOF:
1557
- return Qnil;
1558
- case 0:
1559
- rb_str_resize(str, strlen(StringValuePtr(str)));
1560
- return str;
1561
- }
1562
- bytes += BUFSIZ;
1563
- size += BUFSIZ;
1564
- rb_str_resize(str, size);
1565
- }
1566
- return Qnil;
1567
- }
1568
-
1569
- /*
1570
- * call-seq:
1571
- * conn.endcopy()
1572
- *
1573
- * Waits until the backend completes the copying.
1574
- * You should call this method after #putline or #getline.
1575
- * Returns +nil+ on success; raises an exception otherwise.
1576
- */
1577
- static VALUE
1578
- pgconn_endcopy(obj)
1579
- VALUE obj;
1580
- {
1581
- if (PQendcopy(get_pgconn(obj)) == 1) {
1582
- rb_raise(rb_ePGError, "cannot complete copying");
1583
- }
1584
- return Qnil;
1585
- }
1586
1653
 
1587
1654
  static void
1588
1655
  notice_proxy(self, message)
@@ -1630,19 +1697,19 @@ pgconn_set_notice_processor(self)
1630
1697
  * call-seq:
1631
1698
  * conn.lo_creat( [mode] ) -> Fixnum
1632
1699
  *
1633
- * Creates a large object with mode _mode_. Returns a large object Oid.
1700
+ * Creates a large selfect with mode _mode_. Returns a large selfect Oid.
1634
1701
  * On failure, it raises PGError exception.
1635
1702
  */
1636
1703
  static VALUE
1637
- pgconn_locreat(argc, argv, obj)
1704
+ pgconn_locreat(argc, argv, self)
1638
1705
  int argc;
1639
1706
  VALUE *argv;
1640
- VALUE obj;
1707
+ VALUE self;
1641
1708
  {
1642
1709
  Oid lo_oid;
1643
1710
  int mode;
1644
1711
  VALUE nmode;
1645
- PGconn *conn = get_pgconn(obj);
1712
+ PGconn *conn = get_pgconn(self);
1646
1713
 
1647
1714
  if (rb_scan_args(argc, argv, "01", &nmode) == 0)
1648
1715
  mode = INV_READ;
@@ -1660,15 +1727,15 @@ pgconn_locreat(argc, argv, obj)
1660
1727
  * call-seq:
1661
1728
  * conn.lo_create( oid ) -> Fixnum
1662
1729
  *
1663
- * Creates a large object with oid _oid_. Returns the large object Oid.
1730
+ * Creates a large selfect with oid _oid_. Returns the large selfect Oid.
1664
1731
  * On failure, it raises PGError exception.
1665
1732
  */
1666
1733
  static VALUE
1667
- pgconn_locreate(obj, in_lo_oid)
1668
- VALUE obj, in_lo_oid;
1734
+ pgconn_locreate(self, in_lo_oid)
1735
+ VALUE self, in_lo_oid;
1669
1736
  {
1670
1737
  Oid ret, lo_oid;
1671
- PGconn *conn = get_pgconn(obj);
1738
+ PGconn *conn = get_pgconn(self);
1672
1739
  lo_oid = NUM2INT(in_lo_oid);
1673
1740
 
1674
1741
  ret = lo_create(conn, in_lo_oid);
@@ -1682,17 +1749,17 @@ pgconn_locreate(obj, in_lo_oid)
1682
1749
  * call-seq:
1683
1750
  * conn.lo_import(file) -> Fixnum
1684
1751
  *
1685
- * Import a file to a large object. Returns a large object Oid.
1752
+ * Import a file to a large selfect. Returns a large selfect Oid.
1686
1753
  *
1687
1754
  * On failure, it raises a PGError exception.
1688
1755
  */
1689
1756
  static VALUE
1690
- pgconn_loimport(obj, filename)
1691
- VALUE obj, filename;
1757
+ pgconn_loimport(self, filename)
1758
+ VALUE self, filename;
1692
1759
  {
1693
1760
  Oid lo_oid;
1694
1761
 
1695
- PGconn *conn = get_pgconn(obj);
1762
+ PGconn *conn = get_pgconn(self);
1696
1763
 
1697
1764
  Check_Type(filename, T_STRING);
1698
1765
 
@@ -1707,19 +1774,19 @@ pgconn_loimport(obj, filename)
1707
1774
  * call-seq:
1708
1775
  * conn.lo_export( oid, file ) -> nil
1709
1776
  *
1710
- * Saves a large object of _oid_ to a _file_.
1777
+ * Saves a large selfect of _oid_ to a _file_.
1711
1778
  */
1712
1779
  static VALUE
1713
- pgconn_loexport(obj, lo_oid,filename)
1714
- VALUE obj, lo_oid, filename;
1780
+ pgconn_loexport(self, lo_oid,filename)
1781
+ VALUE self, lo_oid, filename;
1715
1782
  {
1716
- PGconn *conn = get_pgconn(obj);
1783
+ PGconn *conn = get_pgconn(self);
1717
1784
  int oid;
1718
1785
  Check_Type(filename, T_STRING);
1719
1786
 
1720
1787
  oid = NUM2INT(lo_oid);
1721
1788
  if (oid < 0) {
1722
- rb_raise(rb_ePGError, "invalid large object oid %d",oid);
1789
+ rb_raise(rb_ePGError, "invalid large selfect oid %d",oid);
1723
1790
  }
1724
1791
 
1725
1792
  if (lo_export(conn, oid, StringValuePtr(filename)) < 0) {
@@ -1732,32 +1799,32 @@ pgconn_loexport(obj, lo_oid,filename)
1732
1799
  * call-seq:
1733
1800
  * conn.lo_open( oid, [mode] ) -> Fixnum
1734
1801
  *
1735
- * Open a large object of _oid_. Returns a large object descriptor
1802
+ * Open a large selfect of _oid_. Returns a large selfect descriptor
1736
1803
  * instance on success. The _mode_ argument specifies the mode for
1737
- * the opened large object,which is either +INV_READ+, or +INV_WRITE+.
1804
+ * the opened large selfect,which is either +INV_READ+, or +INV_WRITE+.
1738
1805
  *
1739
1806
  * If _mode_ is omitted, the default is +INV_READ+.
1740
1807
  */
1741
1808
  static VALUE
1742
- pgconn_loopen(argc, argv, obj)
1809
+ pgconn_loopen(argc, argv, self)
1743
1810
  int argc;
1744
1811
  VALUE *argv;
1745
- VALUE obj;
1812
+ VALUE self;
1746
1813
  {
1747
1814
  Oid lo_oid;
1748
1815
  int fd, mode;
1749
- VALUE nmode, objid;
1750
- PGconn *conn = get_pgconn(obj);
1816
+ VALUE nmode, selfid;
1817
+ PGconn *conn = get_pgconn(self);
1751
1818
 
1752
- rb_scan_args(argc, argv, "11", &objid, &nmode);
1753
- lo_oid = NUM2INT(objid);
1819
+ rb_scan_args(argc, argv, "11", &selfid, &nmode);
1820
+ lo_oid = NUM2INT(selfid);
1754
1821
  if(NIL_P(nmode))
1755
1822
  mode = INV_READ;
1756
1823
  else
1757
1824
  mode = NUM2INT(nmode);
1758
1825
 
1759
1826
  if((fd = lo_open(conn, lo_oid, mode)) < 0) {
1760
- rb_raise(rb_ePGError, "can't open large object");
1827
+ rb_raise(rb_ePGError, "can't open large selfect");
1761
1828
  }
1762
1829
  return INT2FIX(fd);
1763
1830
  }
@@ -1766,42 +1833,43 @@ pgconn_loopen(argc, argv, obj)
1766
1833
  * call-seq:
1767
1834
  * conn.lo_write( lo_desc, buffer ) -> Fixnum
1768
1835
  *
1769
- * Writes the string _buffer_ to the large object _lo_desc_.
1836
+ * Writes the string _buffer_ to the large selfect _lo_desc_.
1770
1837
  * Returns the number of bytes written.
1771
1838
  */
1772
1839
  static VALUE
1773
- pgconn_lowrite(obj, in_lo_desc, buffer)
1774
- VALUE obj, buffer;
1840
+ pgconn_lowrite(self, in_lo_desc, buffer)
1841
+ VALUE self, buffer;
1775
1842
  {
1776
1843
  int n;
1777
- PGconn *conn = get_pgconn(obj);
1844
+ PGconn *conn = get_pgconn(self);
1778
1845
  int fd = NUM2INT(in_lo_desc);
1779
1846
 
1780
1847
  Check_Type(buffer, T_STRING);
1781
1848
 
1782
- if( RSTRING(buffer)->len < 0) {
1849
+ if( RSTRING_LEN(buffer) < 0) {
1783
1850
  rb_raise(rb_ePGError, "write buffer zero string");
1784
1851
  }
1785
- if((n = lo_write(conn, fd, StringValuePtr(buffer), RSTRING(buffer)->len)) < 0) {
1852
+ if((n = lo_write(conn, fd, StringValuePtr(buffer),
1853
+ RSTRING_LEN(buffer))) < 0) {
1786
1854
  rb_raise(rb_ePGError, "lo_write failed");
1787
1855
  }
1788
1856
 
1789
1857
  return INT2FIX(n);
1790
1858
  }
1791
1859
 
1792
- /*
1860
+ /*TODO broken
1793
1861
  * call-seq:
1794
1862
  * conn.lo_read( lo_desc, len ) -> String
1795
1863
  *
1796
- * Attempts to read _len_ bytes from large object _lo_desc_,
1864
+ * Attempts to read _len_ bytes from large selfect _lo_desc_,
1797
1865
  * returns resulting data.
1798
1866
  */
1799
1867
  static VALUE
1800
- pgconn_loread(obj, in_lo_desc, in_len)
1801
- VALUE obj, in_lo_desc, in_len;
1868
+ pgconn_loread(self, in_lo_desc, in_len)
1869
+ VALUE self, in_lo_desc, in_len;
1802
1870
  {
1803
1871
  int ret;
1804
- PGconn *conn = get_pgconn(obj);
1872
+ PGconn *conn = get_pgconn(self);
1805
1873
  int len = NUM2INT(in_len);
1806
1874
  int lo_desc = NUM2INT(in_lo_desc);
1807
1875
  VALUE str = rb_tainted_str_new(0,len);
@@ -1816,7 +1884,7 @@ pgconn_loread(obj, in_lo_desc, in_len)
1816
1884
  if (ret == 0)
1817
1885
  return Qnil;
1818
1886
 
1819
- RSTRING(str)->len = ret;
1887
+ //RSTRING_LEN(str) = ret;
1820
1888
  return str;
1821
1889
  }
1822
1890
 
@@ -1825,15 +1893,15 @@ pgconn_loread(obj, in_lo_desc, in_len)
1825
1893
  * call-seq:
1826
1894
  * conn.lo_lseek( lo_desc, offset, whence ) -> Fixnum
1827
1895
  *
1828
- * Move the large object pointer _lo_desc_ to offset _offset_.
1896
+ * Move the large selfect pointer _lo_desc_ to offset _offset_.
1829
1897
  * Valid values for _whence_ are +SEEK_SET+, +SEEK_CUR+, and +SEEK_END+.
1830
1898
  * (Or 0, 1, or 2.)
1831
1899
  */
1832
1900
  static VALUE
1833
- pgconn_lolseek(obj, in_lo_desc, offset, whence)
1834
- VALUE obj, in_lo_desc, offset, whence;
1901
+ pgconn_lolseek(self, in_lo_desc, offset, whence)
1902
+ VALUE self, in_lo_desc, offset, whence;
1835
1903
  {
1836
- PGconn *conn = get_pgconn(obj);
1904
+ PGconn *conn = get_pgconn(self);
1837
1905
  int lo_desc = NUM2INT(in_lo_desc);
1838
1906
  int ret;
1839
1907
 
@@ -1848,14 +1916,14 @@ pgconn_lolseek(obj, in_lo_desc, offset, whence)
1848
1916
  * call-seq:
1849
1917
  * conn.lo_tell( lo_desc ) -> Fixnum
1850
1918
  *
1851
- * Returns the current position of the large object _lo_desc_.
1919
+ * Returns the current position of the large selfect _lo_desc_.
1852
1920
  */
1853
1921
  static VALUE
1854
- pgconn_lotell(obj,in_lo_desc)
1855
- VALUE obj, in_lo_desc;
1922
+ pgconn_lotell(self,in_lo_desc)
1923
+ VALUE self, in_lo_desc;
1856
1924
  {
1857
1925
  int position;
1858
- PGconn *conn = get_pgconn(obj);
1926
+ PGconn *conn = get_pgconn(self);
1859
1927
  int lo_desc = NUM2INT(in_lo_desc);
1860
1928
 
1861
1929
  if((position = lo_tell(conn, lo_desc)) < 0)
@@ -1868,13 +1936,13 @@ pgconn_lotell(obj,in_lo_desc)
1868
1936
  * call-seq:
1869
1937
  * conn.lo_truncate( lo_desc, len ) -> nil
1870
1938
  *
1871
- * Truncates the large object _lo_desc_ to size _len_.
1939
+ * Truncates the large selfect _lo_desc_ to size _len_.
1872
1940
  */
1873
1941
  static VALUE
1874
- pgconn_lotruncate(obj, in_lo_desc, in_len)
1875
- VALUE obj, in_lo_desc, in_len;
1942
+ pgconn_lotruncate(self, in_lo_desc, in_len)
1943
+ VALUE self, in_lo_desc, in_len;
1876
1944
  {
1877
- PGconn *conn = get_pgconn(obj);
1945
+ PGconn *conn = get_pgconn(self);
1878
1946
  int lo_desc = NUM2INT(in_lo_desc);
1879
1947
  size_t len = NUM2INT(in_len);
1880
1948
 
@@ -1888,13 +1956,13 @@ pgconn_lotruncate(obj, in_lo_desc, in_len)
1888
1956
  * call-seq:
1889
1957
  * conn.lo_close( lo_desc ) -> nil
1890
1958
  *
1891
- * Closes the postgres large object of _lo_desc_.
1959
+ * Closes the postgres large selfect of _lo_desc_.
1892
1960
  */
1893
1961
  static VALUE
1894
- pgconn_loclose(obj, in_lo_desc)
1895
- VALUE obj, in_lo_desc;
1962
+ pgconn_loclose(self, in_lo_desc)
1963
+ VALUE self, in_lo_desc;
1896
1964
  {
1897
- PGconn *conn = get_pgconn(obj);
1965
+ PGconn *conn = get_pgconn(self);
1898
1966
  int lo_desc = NUM2INT(in_lo_desc);
1899
1967
 
1900
1968
  if(lo_unlink(conn,lo_desc) < 0)
@@ -1907,13 +1975,13 @@ pgconn_loclose(obj, in_lo_desc)
1907
1975
  * call-seq:
1908
1976
  * conn.lo_unlink( oid ) -> nil
1909
1977
  *
1910
- * Unlinks (deletes) the postgres large object of _oid_.
1978
+ * Unlinks (deletes) the postgres large selfect of _oid_.
1911
1979
  */
1912
1980
  static VALUE
1913
- pgconn_lounlink(obj, in_oid)
1914
- VALUE obj, in_oid;
1981
+ pgconn_lounlink(self, in_oid)
1982
+ VALUE self, in_oid;
1915
1983
  {
1916
- PGconn *conn = get_pgconn(obj);
1984
+ PGconn *conn = get_pgconn(self);
1917
1985
  int oid = NUM2INT(in_oid);
1918
1986
 
1919
1987
  if (oid < 0)
@@ -1954,10 +2022,10 @@ pgconn_lounlink(obj, in_oid)
1954
2022
  * * +PGRES_FATAL_ERROR+
1955
2023
  */
1956
2024
  static VALUE
1957
- pgresult_result_status(obj)
1958
- VALUE obj;
2025
+ pgresult_result_status(self)
2026
+ VALUE self;
1959
2027
  {
1960
- return INT2FIX(PQresultStatus(get_pgresult(obj)));
2028
+ return INT2FIX(PQresultStatus(get_pgresult(self)));
1961
2029
  }
1962
2030
 
1963
2031
  /*
@@ -1968,8 +2036,8 @@ pgresult_result_status(obj)
1968
2036
  *
1969
2037
  */
1970
2038
  static VALUE
1971
- pgresult_res_status(obj,status)
1972
- VALUE obj,status;
2039
+ pgresult_res_status(self,status)
2040
+ VALUE self,status;
1973
2041
  {
1974
2042
  return rb_str_new2(PQresStatus(NUM2INT(status)));
1975
2043
  }
@@ -1981,10 +2049,10 @@ pgresult_res_status(obj,status)
1981
2049
  * Returns the error message of the command as a string.
1982
2050
  */
1983
2051
  static VALUE
1984
- pgresult_result_error_message(obj)
1985
- VALUE obj;
2052
+ pgresult_result_error_message(self)
2053
+ VALUE self;
1986
2054
  {
1987
- return rb_str_new2(PQresultErrorMessage(get_pgresult(obj)));
2055
+ return rb_str_new2(PQresultErrorMessage(get_pgresult(self)));
1988
2056
  }
1989
2057
 
1990
2058
  /*
@@ -2008,24 +2076,24 @@ pgresult_result_error_message(obj)
2008
2076
  * * +PG_DIAG_SOURCE_FUNCTION+
2009
2077
  */
2010
2078
  static VALUE
2011
- pgresult_result_error_field(obj)
2012
- VALUE obj;
2079
+ pgresult_result_error_field(self)
2080
+ VALUE self;
2013
2081
  {
2014
- return rb_str_new2(PQresultErrorMessage(get_pgresult(obj)));
2082
+ return rb_str_new2(PQresultErrorMessage(get_pgresult(self)));
2015
2083
  }
2016
2084
 
2017
2085
  /*
2018
2086
  * call-seq:
2019
2087
  * res.clear() -> nil
2020
2088
  *
2021
- * Clears the PGresult object as the result of the query.
2089
+ * Clears the PGresult selfect as the result of the query.
2022
2090
  */
2023
2091
  static VALUE
2024
- pgresult_clear(obj)
2025
- VALUE obj;
2092
+ pgresult_clear(self)
2093
+ VALUE self;
2026
2094
  {
2027
- PQclear(get_pgresult(obj));
2028
- DATA_PTR(obj) = 0;
2095
+ PQclear(get_pgresult(self));
2096
+ DATA_PTR(self) = 0;
2029
2097
 
2030
2098
  return Qnil;
2031
2099
  }
@@ -2037,10 +2105,10 @@ pgresult_clear(obj)
2037
2105
  * Returns the number of tuples in the query result.
2038
2106
  */
2039
2107
  static VALUE
2040
- pgresult_ntuples(obj)
2041
- VALUE obj;
2108
+ pgresult_ntuples(self)
2109
+ VALUE self;
2042
2110
  {
2043
- return INT2FIX(PQntuples(get_pgresult(obj)));
2111
+ return INT2FIX(PQntuples(get_pgresult(self)));
2044
2112
  }
2045
2113
 
2046
2114
  /*
@@ -2050,10 +2118,10 @@ pgresult_ntuples(obj)
2050
2118
  * Returns the number of columns in the query result.
2051
2119
  */
2052
2120
  static VALUE
2053
- pgresult_nfields(obj)
2054
- VALUE obj;
2121
+ pgresult_nfields(self)
2122
+ VALUE self;
2055
2123
  {
2056
- return INT2NUM(PQnfields(get_pgresult(obj)));
2124
+ return INT2NUM(PQnfields(get_pgresult(self)));
2057
2125
  }
2058
2126
 
2059
2127
  /*
@@ -2063,13 +2131,13 @@ pgresult_nfields(obj)
2063
2131
  * Returns the name of the column corresponding to _index_.
2064
2132
  */
2065
2133
  static VALUE
2066
- pgresult_fname(obj, index)
2067
- VALUE obj, index;
2134
+ pgresult_fname(self, index)
2135
+ VALUE self, index;
2068
2136
  {
2069
2137
  PGresult *result;
2070
2138
  int i = NUM2INT(index);
2071
2139
 
2072
- result = get_pgresult(obj);
2140
+ result = get_pgresult(self);
2073
2141
  if (i < 0 || i >= PQnfields(result)) {
2074
2142
  rb_raise(rb_eArgError,"invalid field number %d", i);
2075
2143
  }
@@ -2086,14 +2154,14 @@ pgresult_fname(obj, index)
2086
2154
  * raises a TypeError if _name_ is not a String.
2087
2155
  */
2088
2156
  static VALUE
2089
- pgresult_fnumber(obj, name)
2090
- VALUE obj, name;
2157
+ pgresult_fnumber(self, name)
2158
+ VALUE self, name;
2091
2159
  {
2092
2160
  int n;
2093
2161
 
2094
2162
  Check_Type(name, T_STRING);
2095
2163
 
2096
- n = PQfnumber(get_pgresult(obj), StringValuePtr(name));
2164
+ n = PQfnumber(get_pgresult(self), StringValuePtr(name));
2097
2165
  if (n == -1) {
2098
2166
  rb_raise(rb_eArgError,"Unknown field: %s", StringValuePtr(name));
2099
2167
  }
@@ -2111,10 +2179,10 @@ pgresult_fnumber(obj, name)
2111
2179
  * the Oid is undefined for that column.
2112
2180
  */
2113
2181
  static VALUE
2114
- pgresult_ftable(obj, column_number)
2115
- VALUE obj, column_number;
2182
+ pgresult_ftable(self, column_number)
2183
+ VALUE self, column_number;
2116
2184
  {
2117
- Oid n = PQftable(get_pgresult(obj), NUM2INT(column_number));
2185
+ Oid n = PQftable(get_pgresult(self), NUM2INT(column_number));
2118
2186
  if (n == InvalidOid) {
2119
2187
  rb_raise(rb_eArgError,"Oid is undefined for column: %d",
2120
2188
  NUM2INT(column_number));
@@ -2133,10 +2201,10 @@ pgresult_ftable(obj, column_number)
2133
2201
  * the column number from its table is undefined for that column.
2134
2202
  */
2135
2203
  static VALUE
2136
- pgresult_ftablecol(obj, column_number)
2137
- VALUE obj, column_number;
2204
+ pgresult_ftablecol(self, column_number)
2205
+ VALUE self, column_number;
2138
2206
  {
2139
- int n = PQftablecol(get_pgresult(obj), NUM2INT(column_number));
2207
+ int n = PQftablecol(get_pgresult(self), NUM2INT(column_number));
2140
2208
  if (n == 0) {
2141
2209
  rb_raise(rb_eArgError,
2142
2210
  "Column number from table is undefined for column: %d",
@@ -2155,10 +2223,10 @@ pgresult_ftablecol(obj, column_number)
2155
2223
  * Raises ArgumentError if _column_number_ is out of range.
2156
2224
  */
2157
2225
  static VALUE
2158
- pgresult_fformat(obj, column_number)
2159
- VALUE obj, column_number;
2226
+ pgresult_fformat(self, column_number)
2227
+ VALUE self, column_number;
2160
2228
  {
2161
- PGresult *result = get_pgresult(obj);
2229
+ PGresult *result = get_pgresult(self);
2162
2230
  int fnumber = NUM2INT(column_number);
2163
2231
  if (fnumber >= PQnfields(result)) {
2164
2232
  rb_raise(rb_eArgError, "Column number is out of range: %d",
@@ -2176,10 +2244,10 @@ pgresult_fformat(obj, column_number)
2176
2244
  * The integer returned is the internal +OID+ number (in PostgreSQL) of the type.
2177
2245
  */
2178
2246
  static VALUE
2179
- pgresult_ftype(obj, index)
2180
- VALUE obj, index;
2247
+ pgresult_ftype(self, index)
2248
+ VALUE self, index;
2181
2249
  {
2182
- PGresult* result = get_pgresult(obj);
2250
+ PGresult* result = get_pgresult(self);
2183
2251
  int i = NUM2INT(index);
2184
2252
  if (i < 0 || i >= PQnfields(result)) {
2185
2253
  rb_raise(rb_eArgError, "invalid field number %d", i);
@@ -2196,10 +2264,10 @@ pgresult_ftype(obj, index)
2196
2264
  * Raises ArgumentError if _column_number_ is out of range.
2197
2265
  */
2198
2266
  static VALUE
2199
- pgresult_fmod(obj, column_number)
2200
- VALUE obj, column_number;
2267
+ pgresult_fmod(self, column_number)
2268
+ VALUE self, column_number;
2201
2269
  {
2202
- PGresult *result = get_pgresult(obj);
2270
+ PGresult *result = get_pgresult(self);
2203
2271
  int fnumber = NUM2INT(column_number);
2204
2272
  int modifier;
2205
2273
  if (fnumber >= PQnfields(result)) {
@@ -2224,13 +2292,13 @@ pgresult_fmod(obj, column_number)
2224
2292
  * res.size(1) => -1
2225
2293
  */
2226
2294
  static VALUE
2227
- pgresult_fsize(obj, index)
2228
- VALUE obj, index;
2295
+ pgresult_fsize(self, index)
2296
+ VALUE self, index;
2229
2297
  {
2230
2298
  PGresult *result;
2231
2299
  int i = NUM2INT(index);
2232
2300
 
2233
- result = get_pgresult(obj);
2301
+ result = get_pgresult(self);
2234
2302
  if (i < 0 || i >= PQnfields(result)) {
2235
2303
  rb_raise(rb_eArgError,"invalid field number %d", i);
2236
2304
  }
@@ -2244,14 +2312,14 @@ pgresult_fsize(obj, index)
2244
2312
  * Returns the value in tuple number _tup_num_, field _field_num_.
2245
2313
  */
2246
2314
  static VALUE
2247
- pgresult_getvalue(obj, tup_num, field_num)
2248
- VALUE obj, tup_num, field_num;
2315
+ pgresult_getvalue(self, tup_num, field_num)
2316
+ VALUE self, tup_num, field_num;
2249
2317
  {
2250
2318
  PGresult *result;
2251
2319
  int i = NUM2INT(tup_num);
2252
2320
  int j = NUM2INT(field_num);
2253
2321
 
2254
- result = get_pgresult(obj);
2322
+ result = get_pgresult(self);
2255
2323
  if(i < 0 || i >= PQntuples(result)) {
2256
2324
  rb_raise(rb_eArgError,"invalid tuple number %d", i);
2257
2325
  }
@@ -2268,14 +2336,14 @@ pgresult_getvalue(obj, tup_num, field_num)
2268
2336
  * Returns +true+ if the specified value is +nil+; +false+ otherwise.
2269
2337
  */
2270
2338
  static VALUE
2271
- pgresult_getisnull(obj, tup_num, field_num)
2272
- VALUE obj, tup_num, field_num;
2339
+ pgresult_getisnull(self, tup_num, field_num)
2340
+ VALUE self, tup_num, field_num;
2273
2341
  {
2274
2342
  PGresult *result;
2275
2343
  int i = NUM2INT(tup_num);
2276
2344
  int j = NUM2INT(field_num);
2277
2345
 
2278
- result = get_pgresult(obj);
2346
+ result = get_pgresult(self);
2279
2347
  if (i < 0 || i >= PQntuples(result)) {
2280
2348
  rb_raise(rb_eArgError,"invalid tuple number %d", i);
2281
2349
  }
@@ -2294,14 +2362,14 @@ pgresult_getisnull(obj, tup_num, field_num)
2294
2362
  * Equivalent to <tt>res.value(<i>tup_num</i>,<i>field_num</i>).length</tt>.
2295
2363
  */
2296
2364
  static VALUE
2297
- pgresult_getlength(obj, tup_num, field_num)
2298
- VALUE obj, tup_num, field_num;
2365
+ pgresult_getlength(self, tup_num, field_num)
2366
+ VALUE self, tup_num, field_num;
2299
2367
  {
2300
2368
  PGresult *result;
2301
2369
  int i = NUM2INT(tup_num);
2302
2370
  int j = NUM2INT(field_num);
2303
2371
 
2304
- result = get_pgresult(obj);
2372
+ result = get_pgresult(self);
2305
2373
  if (i < 0 || i >= PQntuples(result)) {
2306
2374
  rb_raise(rb_eArgError,"invalid tuple number %d", i);
2307
2375
  }
@@ -2319,12 +2387,12 @@ pgresult_getlength(obj, tup_num, field_num)
2319
2387
  * Only useful for the result returned by conn.describePrepared
2320
2388
  */
2321
2389
  static VALUE
2322
- pgresult_nparams(obj)
2323
- VALUE obj;
2390
+ pgresult_nparams(self)
2391
+ VALUE self;
2324
2392
  {
2325
2393
  PGresult *result;
2326
2394
 
2327
- result = get_pgresult(obj);
2395
+ result = get_pgresult(self);
2328
2396
  return INT2FIX(PQnparams(result));
2329
2397
  }
2330
2398
 
@@ -2336,12 +2404,12 @@ pgresult_nparams(obj)
2336
2404
  * Only useful for the result returned by conn.describePrepared
2337
2405
  */
2338
2406
  static VALUE
2339
- pgresult_paramtype(obj, param_number)
2340
- VALUE obj, param_number;
2407
+ pgresult_paramtype(self, param_number)
2408
+ VALUE self, param_number;
2341
2409
  {
2342
2410
  PGresult *result;
2343
2411
 
2344
- result = get_pgresult(obj);
2412
+ result = get_pgresult(self);
2345
2413
  return INT2FIX(PQparamtype(result,NUM2INT(param_number)));
2346
2414
  }
2347
2415
 
@@ -2352,10 +2420,10 @@ pgresult_paramtype(obj, param_number)
2352
2420
  * Returns the status string of the last query command.
2353
2421
  */
2354
2422
  static VALUE
2355
- pgresult_cmd_status(obj)
2356
- VALUE obj;
2423
+ pgresult_cmd_status(self)
2424
+ VALUE self;
2357
2425
  {
2358
- return rb_tainted_str_new2(PQcmdStatus(get_pgresult(obj)));
2426
+ return rb_tainted_str_new2(PQcmdStatus(get_pgresult(self)));
2359
2427
  }
2360
2428
 
2361
2429
  /*
@@ -2373,11 +2441,11 @@ pgresult_cmd_status(obj)
2373
2441
  * or if no tuples were affected, <tt>0</tt> is returned.
2374
2442
  */
2375
2443
  static VALUE
2376
- pgresult_cmd_tuples(obj)
2377
- VALUE obj;
2444
+ pgresult_cmd_tuples(self)
2445
+ VALUE self;
2378
2446
  {
2379
2447
  long n;
2380
- n = strtol(PQcmdTuples(get_pgresult(obj)),NULL, 10);
2448
+ n = strtol(PQcmdTuples(get_pgresult(self)),NULL, 10);
2381
2449
  return INT2NUM(n);
2382
2450
  }
2383
2451
 
@@ -2389,10 +2457,10 @@ pgresult_cmd_tuples(obj)
2389
2457
  * otherwise +nil+.
2390
2458
  */
2391
2459
  static VALUE
2392
- pgresult_oid_value(obj)
2393
- VALUE obj;
2460
+ pgresult_oid_value(self)
2461
+ VALUE self;
2394
2462
  {
2395
- Oid n = PQoidValue(get_pgresult(obj));
2463
+ Oid n = PQoidValue(get_pgresult(self));
2396
2464
  if (n == InvalidOid)
2397
2465
  return Qnil;
2398
2466
  else
@@ -2408,10 +2476,10 @@ pgresult_oid_value(obj)
2408
2476
  * Returns tuple _n_ as a hash.
2409
2477
  */
2410
2478
  static VALUE
2411
- pgresult_aref(obj, index)
2412
- VALUE obj, index;
2479
+ pgresult_aref(self, index)
2480
+ VALUE self, index;
2413
2481
  {
2414
- PGresult *result = get_pgresult(obj);
2482
+ PGresult *result = get_pgresult(self);
2415
2483
  int tuple_num = NUM2INT(index);
2416
2484
  int field_num;
2417
2485
  VALUE fname,val;
@@ -2438,16 +2506,16 @@ pgresult_aref(obj, index)
2438
2506
  * Invokes block for each tuple in the result set.
2439
2507
  */
2440
2508
  static VALUE
2441
- pgresult_each(obj)
2442
- VALUE obj;
2509
+ pgresult_each(self)
2510
+ VALUE self;
2443
2511
  {
2444
- PGresult *result = get_pgresult(obj);
2512
+ PGresult *result = get_pgresult(self);
2445
2513
  int tuple_num;
2446
2514
 
2447
2515
  for(tuple_num = 0; tuple_num < PQntuples(result); tuple_num++) {
2448
- rb_yield(pgresult_aref(obj, INT2NUM(tuple_num)));
2516
+ rb_yield(pgresult_aref(self, INT2NUM(tuple_num)));
2449
2517
  }
2450
- return obj;
2518
+ return self;
2451
2519
  }
2452
2520
 
2453
2521
  /*
@@ -2457,14 +2525,14 @@ pgresult_each(obj)
2457
2525
  * Returns an array of Strings representing the names of the fields in the result.
2458
2526
  */
2459
2527
  static VALUE
2460
- pgresult_fields(obj)
2461
- VALUE obj;
2528
+ pgresult_fields(self)
2529
+ VALUE self;
2462
2530
  {
2463
2531
  PGresult *result;
2464
2532
  VALUE ary;
2465
2533
  int n, i;
2466
2534
 
2467
- result = get_pgresult(obj);
2535
+ result = get_pgresult(self);
2468
2536
  n = PQnfields(result);
2469
2537
  ary = rb_ary_new2(n);
2470
2538
  for (i=0;i<n;i++) {
@@ -2482,8 +2550,8 @@ void
2482
2550
  Init_pg()
2483
2551
  {
2484
2552
  pg_gsub_bang_id = rb_intern("gsub!");
2485
- pg_escape_regex = rb_reg_new("([\\t\\n\\\\])", 10, 0);
2486
- rb_global_variable(&pg_escape_regex);
2553
+ //TODO pg_escape_regex = rb_reg_new("([\\t\\n\\\\])", 10, 0);
2554
+ //rb_global_variable(&pg_escape_regex);
2487
2555
  pg_escape_str = rb_str_new("\\\\\\1", 4);
2488
2556
  rb_global_variable(&pg_escape_str);
2489
2557
 
@@ -2586,8 +2654,8 @@ Init_pg()
2586
2654
  rb_define_method(rb_cPGconn, "exec_params", pgconn_exec_params, -1);
2587
2655
  rb_define_method(rb_cPGconn, "prepare", pgconn_prepare, -1);
2588
2656
  rb_define_method(rb_cPGconn, "exec_prepared", pgconn_exec_prepared, -1);
2589
- rb_define_method(rb_cPGconn, "describe_prepared", pgconn_prepare, -1);
2590
- rb_define_method(rb_cPGconn, "describe_portal", pgconn_exec_prepared, -1);
2657
+ rb_define_method(rb_cPGconn, "describe_prepared", pgconn_describe_prepared, 1);
2658
+ rb_define_method(rb_cPGconn, "describe_portal", pgconn_describe_portal, 1);
2591
2659
  rb_define_method(rb_cPGconn, "escape_string", pgconn_s_escape, 1);
2592
2660
  rb_define_alias(rb_cPGconn, "escape", "escape_string");
2593
2661
  rb_define_method(rb_cPGconn, "escape_bytea", pgconn_s_escape_bytea, 1);
@@ -2616,12 +2684,12 @@ Init_pg()
2616
2684
  //rb_define_method(rb_cPGconn, "fn", pgconn_fn, 0);
2617
2685
 
2618
2686
  /* NOTIFY */
2619
- //rb_define_method(rb_cPGconn, "notifies", pgconn_notifies, 0);
2687
+ rb_define_method(rb_cPGconn, "notifies", pgconn_notifies, 0);
2620
2688
 
2621
2689
  /* COPY */
2622
2690
  rb_define_method(rb_cPGconn, "put_copy_data", pgconn_put_copy_data, 1);
2623
- //rb_define_method(rb_cPGconn, "put_copy_end", pgconn_put_copy_end, 1);
2624
- //rb_define_method(rb_cPGconn, "get_copy_data", pgconn_get_copy_data, 2);
2691
+ rb_define_method(rb_cPGconn, "put_copy_end", pgconn_put_copy_end, -1);
2692
+ rb_define_method(rb_cPGconn, "get_copy_data", pgconn_get_copy_data, -1);
2625
2693
 
2626
2694
  /* Control Functions */
2627
2695
  //rb_define_method(rb_cPGconn, "set_error_verbosity", pgconn_set_error_verbosity, 0);