ruby-postgres 0.7.1.2005.11.24-mswin32 → 0.7.1.2005.11.27-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/Contributors CHANGED
@@ -23,4 +23,4 @@ shibata <kshibata@vesta.ocn.ne.jp>
23
23
  <greentea@fa2.so-net.ne.jp>
24
24
  ts <decoux@moulon.inra.fr>
25
25
  Yuta TSUBOI <yuuta-t@is.aist-nara.ac.jp>
26
- meadow.nnick@gmail.com
26
+ Lugovoi Nikolai <meadow.nnick@gmail.com>
data/Makefile CHANGED
@@ -4,13 +4,13 @@ SHELL = /bin/sh
4
4
  #### Start of system configuration section. ####
5
5
 
6
6
  srcdir = .
7
- topdir = c:/mingwruby/lib/ruby/1.8/i386-mingw32
7
+ topdir = c:/mingw/ruby/lib/ruby/1.8/i386-mingw32
8
8
  hdrdir = $(topdir)
9
9
  VPATH = $(srcdir);$(topdir);$(hdrdir)
10
10
 
11
11
  DESTDIR = c:
12
- prefix = $(DESTDIR)/mingwruby
13
- exec_prefix = $(DESTDIR)/mingwruby
12
+ prefix = $(DESTDIR)/mingw/ruby
13
+ exec_prefix = $(DESTDIR)/mingw/ruby
14
14
  sitedir = $(prefix)/lib/ruby/site_ruby
15
15
  rubylibdir = $(libdir)/ruby/$(ruby_version)
16
16
  archdir = $(rubylibdir)/$(arch)
@@ -20,7 +20,7 @@ includedir = $(prefix)/include
20
20
  infodir = $(prefix)/info
21
21
  sysconfdir = $(prefix)/etc
22
22
  mandir = $(prefix)/man
23
- libdir = $(DESTDIR)/mingwruby/lib
23
+ libdir = $(DESTDIR)/mingw/ruby/lib
24
24
  sharedstatedir = $(prefix)/com
25
25
  oldincludedir = $(DESTDIR)/usr/include
26
26
  sitearchdir = $(sitelibdir)/$(sitearch)
@@ -48,7 +48,7 @@ RUBY_SO_NAME = msvcrt-ruby18
48
48
  arch = i386-mingw32
49
49
  sitearch = i386-msvcrt
50
50
  ruby_version = 1.8
51
- ruby = c:/mingwruby/bin/ruby
51
+ ruby = c:/mingw/ruby/bin/ruby
52
52
  RUBY = $(ruby)
53
53
  RM = rm -f
54
54
  MAKEDIRS = mkdir -p
data/mkmf.log CHANGED
@@ -1,6 +1,6 @@
1
1
  have_library: checking for main() in -lpq... -------------------- yes
2
2
 
3
- "gcc -o conftest -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingwruby/lib" -lmsvcrt-ruby18-static -lpq -lwsock32 "
3
+ "gcc -o conftest -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingw/ruby/lib" -lmsvcrt-ruby18-static -lpq -lwsock32 "
4
4
  checked program was:
5
5
  /* begin */
6
6
 
@@ -13,7 +13,7 @@ int t() { main(); return 0; }
13
13
 
14
14
  have_header: checking for libpq-fe.h... -------------------- yes
15
15
 
16
- "gcc -E -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -o conftest.i"
16
+ "gcc -E -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -o conftest.i"
17
17
  checked program was:
18
18
  /* begin */
19
19
  #include <libpq-fe.h>
@@ -23,7 +23,7 @@ checked program was:
23
23
 
24
24
  have_header: checking for libpq/libpq-fs.h... -------------------- yes
25
25
 
26
- "gcc -E -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -o conftest.i"
26
+ "gcc -E -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -o conftest.i"
27
27
  checked program was:
28
28
  /* begin */
29
29
  #include <libpq/libpq-fs.h>
@@ -33,7 +33,7 @@ checked program was:
33
33
 
34
34
  have_library: checking for main() in -lcrypto... -------------------- no
35
35
 
36
- "gcc -o conftest -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingwruby/lib" -lpq -lmsvcrt-ruby18-static -lcrypto -lpq -lwsock32 "
36
+ "gcc -o conftest -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingw/ruby/lib" -lpq -lmsvcrt-ruby18-static -lcrypto -lpq -lwsock32 "
37
37
  c:\mingw\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lcrypto
38
38
  collect2: ld returned 1 exit status
39
39
  checked program was:
@@ -44,7 +44,7 @@ int main() { return 0; }
44
44
  int t() { main(); return 0; }
45
45
  /* end */
46
46
 
47
- "gcc -o conftest -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingwruby/lib" -lpq -lmsvcrt-ruby18-static -lcrypto -lpq -lwsock32 "
47
+ "gcc -o conftest -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingw/ruby/lib" -lpq -lmsvcrt-ruby18-static -lcrypto -lpq -lwsock32 "
48
48
  c:\mingw\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lcrypto
49
49
  collect2: ld returned 1 exit status
50
50
  checked program was:
@@ -61,7 +61,7 @@ int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
61
61
 
62
62
  have_library: checking for main() in -lssl... -------------------- no
63
63
 
64
- "gcc -o conftest -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingwruby/lib" -lpq -lmsvcrt-ruby18-static -lssl -lpq -lwsock32 "
64
+ "gcc -o conftest -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingw/ruby/lib" -lpq -lmsvcrt-ruby18-static -lssl -lpq -lwsock32 "
65
65
  c:\mingw\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lssl
66
66
  collect2: ld returned 1 exit status
67
67
  checked program was:
@@ -72,7 +72,7 @@ int main() { return 0; }
72
72
  int t() { main(); return 0; }
73
73
  /* end */
74
74
 
75
- "gcc -o conftest -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingwruby/lib" -lpq -lmsvcrt-ruby18-static -lssl -lpq -lwsock32 "
75
+ "gcc -o conftest -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingw/ruby/lib" -lpq -lmsvcrt-ruby18-static -lssl -lpq -lwsock32 "
76
76
  c:\mingw\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lssl
77
77
  collect2: ld returned 1 exit status
78
78
  checked program was:
@@ -89,7 +89,7 @@ int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
89
89
 
90
90
  have_func: checking for PQsetClientEncoding()... -------------------- yes
91
91
 
92
- "gcc -o conftest -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingwruby/lib" -lpq -lmsvcrt-ruby18-static -lpq -lwsock32 "
92
+ "gcc -o conftest -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingw/ruby/lib" -lpq -lmsvcrt-ruby18-static -lpq -lwsock32 "
93
93
  checked program was:
94
94
  /* begin */
95
95
 
@@ -102,7 +102,7 @@ int t() { PQsetClientEncoding(); return 0; }
102
102
 
103
103
  have_func: checking for pg_encoding_to_char()... -------------------- yes
104
104
 
105
- "gcc -o conftest -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingwruby/lib" -lpq -lmsvcrt-ruby18-static -lpq -lwsock32 "
105
+ "gcc -o conftest -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingw/ruby/lib" -lpq -lmsvcrt-ruby18-static -lpq -lwsock32 "
106
106
  checked program was:
107
107
  /* begin */
108
108
 
@@ -115,7 +115,7 @@ int t() { pg_encoding_to_char(); return 0; }
115
115
 
116
116
  have_func: checking for PQfreemem()... -------------------- yes
117
117
 
118
- "gcc -o conftest -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingwruby/lib" -lpq -lmsvcrt-ruby18-static -lpq -lwsock32 "
118
+ "gcc -o conftest -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingw/ruby/lib" -lpq -lmsvcrt-ruby18-static -lpq -lwsock32 "
119
119
  checked program was:
120
120
  /* begin */
121
121
 
@@ -128,7 +128,7 @@ int t() { PQfreemem(); return 0; }
128
128
 
129
129
  have_func: checking for PQescapeString()... -------------------- yes
130
130
 
131
- "gcc -o conftest -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingwruby/lib" -lpq -lmsvcrt-ruby18-static -lpq -lwsock32 "
131
+ "gcc -o conftest -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingw/ruby/lib" -lpq -lmsvcrt-ruby18-static -lpq -lwsock32 "
132
132
  checked program was:
133
133
  /* begin */
134
134
 
@@ -141,7 +141,7 @@ int t() { PQescapeString(); return 0; }
141
141
 
142
142
  have_func: checking for PQexecParams()... -------------------- yes
143
143
 
144
- "gcc -o conftest -I. -Ic:/mingwruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingwruby/lib" -lpq -lmsvcrt-ruby18-static -lpq -lwsock32 "
144
+ "gcc -o conftest -I. -Ic:/mingw/ruby/lib/ruby/1.8/i386-mingw32 -Ic:/apps/POSTGR~1/8.1/include -g -O2 conftest.c -L"c:/apps/POSTGR~1/8.1/lib" -L"c:/mingw/ruby/lib" -lpq -lmsvcrt-ruby18-static -lpq -lwsock32 "
145
145
  checked program was:
146
146
  /* begin */
147
147
 
data/postgres.c CHANGED
@@ -52,6 +52,8 @@ extern char* pg_encoding_to_char(int);
52
52
 
53
53
  #define rb_check_hash_type(x) rb_check_convert_type(x, T_HASH, "Hash", "to_hash")
54
54
 
55
+ #define rb_define_singleton_alias(klass,new,old) rb_define_alias(rb_singleton_class(klass),new,old)
56
+
55
57
  #define Data_Set_Struct(obj,ptr) do { \
56
58
  Check_Type(obj, T_DATA); \
57
59
  DATA_PTR(obj) = ptr; \
@@ -75,9 +77,13 @@ static VALUE rb_ePGError;
75
77
  static VALUE rb_cPGlarge;
76
78
  static VALUE rb_cPGrow;
77
79
 
80
+ static VALUE pgconn_lastval _((VALUE));
81
+
78
82
  static VALUE pgresult_result_with_clear _((VALUE));
79
83
  static VALUE pgresult_new _((PGresult*));
80
84
 
85
+ static int translate_results = 1;
86
+
81
87
  /* Large Object support */
82
88
  typedef struct pglarge_object
83
89
  {
@@ -168,20 +174,27 @@ pgconn_connect(argc, argv, self)
168
174
  rb_raise(rb_ePGError, StringValuePtr(message));
169
175
  }
170
176
 
177
+ if (PQserverVersion(conn) >= 80100) {
178
+ rb_define_singleton_method(self, "lastval", pgconn_lastval, 0);
179
+ }
180
+
171
181
  Data_Set_Struct(self, conn);
172
182
  return self;
173
183
  }
174
184
 
175
185
  /*
176
- * See #new.
186
+ * call-seq:
187
+ * PGconn.translate_results = boolean
188
+ *
189
+ * When true (default), results are translated to appropriate ruby class.
190
+ * When false, results are returned as +Strings+.
177
191
  */
178
192
  static VALUE
179
- pgconn_s_connect(argc, argv, klass)
180
- int argc;
181
- VALUE *argv;
182
- VALUE klass;
193
+ pgconn_s_translate_results_set(self, fact)
194
+ VALUE self, fact;
183
195
  {
184
- return rb_class_new_instance(argc, argv, klass);
196
+ translate_results = (fact == Qfalse || fact == Qnil) ? 0 : 1;
197
+ return Qnil;
185
198
  }
186
199
 
187
200
  static VALUE format_array_element(VALUE obj);
@@ -223,7 +236,7 @@ pgconn_s_format(self, obj)
223
236
  return result;
224
237
 
225
238
  default:
226
- if (rb_class_of(obj) == rb_cBigDecimal) {
239
+ if (CLASS_OF(obj) == rb_cBigDecimal) {
227
240
  return rb_funcall(obj, rb_intern("to_s"), 1, rb_str_new2("F"));
228
241
  }
229
242
  else if (rb_block_given_p()) {
@@ -266,15 +279,16 @@ format_array_element(obj)
266
279
  */
267
280
  static VALUE
268
281
  pgconn_s_quote(self, obj)
269
- VALUE self;
270
- VALUE obj;
282
+ VALUE self, obj;
271
283
  {
272
284
  char* quoted;
273
285
  int size;
274
286
  VALUE result;
275
287
 
276
288
  if (TYPE(obj) == T_STRING) {
277
- quoted = ALLOCA_N(char, RSTRING(obj)->len * 2 + 1 + 2);
289
+ /* length * 2 because every char could require escaping */
290
+ /* + 2 for the quotes, + 1 for the null terminator */
291
+ quoted = ALLOCA_N(char, RSTRING(obj)->len * 2 + 2 + 1);
278
292
  size = PQescapeString(quoted + 1, RSTRING(obj)->ptr, RSTRING(obj)->len);
279
293
  *quoted = *(quoted + size + 1) = SINGLE_QUOTE;
280
294
  result = rb_str_new(quoted, size + 2);
@@ -373,43 +387,43 @@ pgconn_s_escape_bytea(self, obj)
373
387
  */
374
388
  static VALUE
375
389
  pgconn_s_unescape_bytea(self, obj)
376
- VALUE self;
377
- VALUE obj;
390
+ VALUE self, obj;
378
391
  {
379
392
  char *from, *to;
380
393
  size_t to_len;
381
394
  VALUE ret;
382
-
395
+
383
396
  Check_Type(obj, T_STRING);
384
397
  from = StringValuePtr(obj);
385
-
386
- to = (char *)PQunescapeBytea(from, &to_len);
387
-
398
+
399
+ to = (char *) PQunescapeBytea(from, &to_len);
400
+
388
401
  ret = rb_str_new(to, to_len);
389
402
  OBJ_INFECT(ret, obj);
390
-
391
403
  PQfreemem(to);
392
-
404
+
393
405
  return ret;
394
406
  }
395
407
 
396
- #ifndef HAVE_RB_DEFINE_ALLOC_FUNC
397
408
  /*
409
+ * Document-method: new
410
+ *
398
411
  * call-seq:
399
- * PGconn.connect(host, port, options, tty, dbname, login, passwd) => conn
400
- * PGconn.open( host, port, options, tty, dbname, login, passwd) => conn
401
- * PGconn.new( host, port, options, tty, dbname, login, passwd) => conn
402
- *
403
- * _host_:: server hostname (String)
404
- * _port_:: server port number (Integer)
412
+ * PGconn.open(connection_hash) -> PGconn
413
+ * PGconn.open(connection_string) -> PGconn
414
+ * PGconn.open(host, port, options, tty, dbname, login, passwd) -> PGconn
415
+ *
416
+ * _host_:: server hostname
417
+ * _port_:: server port number
405
418
  * _options_:: backend options (String)
406
419
  * _tty_:: tty to print backend debug message <i>(ignored in newer versions of PostgreSQL)</i> (String)
407
- * _dbname_:: connecting database name (String)
408
- * _login_:: login user name (String)
409
- * _passwd_:: login password (String)
420
+ * _dbname_:: connecting database name
421
+ * _login_:: login user name
422
+ * _passwd_:: login password
410
423
  *
411
424
  * On failure, it raises a PGError exception.
412
425
  */
426
+ #ifndef HAVE_RB_DEFINE_ALLOC_FUNC
413
427
  static VALUE
414
428
  pgconn_s_new(argc, argv, klass)
415
429
  int argc;
@@ -422,9 +436,6 @@ pgconn_s_new(argc, argv, klass)
422
436
  }
423
437
  #endif
424
438
 
425
- /*
426
- * See #new.
427
- */
428
439
  static VALUE
429
440
  pgconn_init(argc, argv, self)
430
441
  int argc;
@@ -441,13 +452,13 @@ get_pgconn(obj)
441
452
  PGconn *conn;
442
453
 
443
454
  Data_Get_Struct(obj, PGconn, conn);
444
- if (conn == 0) rb_raise(rb_ePGError, "closed connection");
455
+ if (conn == NULL) rb_raise(rb_ePGError, "closed connection");
445
456
  return conn;
446
457
  }
447
458
 
448
459
  /*
449
460
  * call-seq:
450
- * conn.close()
461
+ * conn.close
451
462
  *
452
463
  * Closes the backend connection.
453
464
  */
@@ -490,11 +501,13 @@ PGresult *PQexecParams_compat(PGconn *conn, VALUE command, VALUE values);
490
501
 
491
502
  /*
492
503
  * call-seq:
493
- * conn.exec( sql )
504
+ * conn.exec(sql, *bind_values)
494
505
  *
495
506
  * Sends SQL query request specified by _sql_ to the PostgreSQL.
496
507
  * Returns a PGresult instance on success.
497
508
  * On failure, it raises a PGError exception.
509
+ *
510
+ * +bind_values+ represents values for the PostgreSQL bind parameters found in the +sql+. PostgreSQL bind parameters are presented as $1, $1, $2, etc.
498
511
  */
499
512
  static VALUE
500
513
  pgconn_exec(argc, argv, obj)
@@ -645,11 +658,13 @@ pgconn_async_exec(obj, str)
645
658
 
646
659
  /*
647
660
  * call-seq:
648
- * conn.query( sql )
661
+ * conn.query(sql, *bind_values)
649
662
  *
650
663
  * Sends SQL query request specified by _sql_ to the PostgreSQL.
651
664
  * Returns an Array as the resulting tuple on success.
652
665
  * On failure, it returns +nil+, and the error details can be obtained by #error.
666
+ *
667
+ * +bind_values+ represents values for the PostgreSQL bind parameters found in the +sql+. PostgreSQL bind parameters are presented as $1, $1, $2, etc.
653
668
  */
654
669
  static VALUE
655
670
  pgconn_query(argc, argv, obj)
@@ -662,7 +677,7 @@ pgconn_query(argc, argv, obj)
662
677
 
663
678
  /*
664
679
  * call-seq:
665
- * conn.async_query( sql )
680
+ * conn.async_query(sql)
666
681
  *
667
682
  * Sends an asynchronous SQL query request specified by _sql_ to the PostgreSQL.
668
683
  * Returns an Array as the resulting tuple on success.
@@ -1057,6 +1072,12 @@ pgconn_transaction_status(obj)
1057
1072
 
1058
1073
  #ifdef HAVE_PQSETCLIENTENCODING
1059
1074
 
1075
+ /*
1076
+ * call-seq:
1077
+ * conn.protocol_version -> Integer
1078
+ *
1079
+ * The 3.0 protocol will normally be used when communicating with PostgreSQL 7.4 or later servers; pre-7.4 servers support only protocol 2.0. (Protocol 1.0 is obsolete and not supported by libpq.)
1080
+ */
1060
1081
  static VALUE
1061
1082
  pgconn_protocol_version(obj)
1062
1083
  VALUE obj;
@@ -1064,6 +1085,12 @@ pgconn_protocol_version(obj)
1064
1085
  return INT2NUM(PQprotocolVersion(get_pgconn(obj)));
1065
1086
  }
1066
1087
 
1088
+ /*
1089
+ * call-seq:
1090
+ * conn.server_version -> Integer
1091
+ *
1092
+ * 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.
1093
+ */
1067
1094
  static VALUE
1068
1095
  pgconn_server_version(obj)
1069
1096
  VALUE obj;
@@ -1071,6 +1098,15 @@ pgconn_server_version(obj)
1071
1098
  return INT2NUM(PQserverVersion(get_pgconn(obj)));
1072
1099
  }
1073
1100
 
1101
+ /*
1102
+ * call-seq:
1103
+ * conn.lastval -> Integer
1104
+ *
1105
+ * Returns the sequence value returned by the last call to the PostgreSQL function <tt>nextval(sequence_name)</tt>. Equivalent to <tt>conn.query('select lastval()').first.first</tt>.
1106
+ *
1107
+ * This functionality is only available with PostgreSQL 8.1 and newer.
1108
+ * See the PostgreSQL documentation on lastval[http://www.postgresql.org/docs/current/interactive/functions-sequence.html] for more information.
1109
+ */
1074
1110
  static VALUE
1075
1111
  pgconn_lastval(obj)
1076
1112
  VALUE obj;
@@ -1079,8 +1115,6 @@ pgconn_lastval(obj)
1079
1115
  PGresult *result;
1080
1116
  VALUE lastval, error;
1081
1117
 
1082
- if (PQserverVersion(conn) < 80100) return Qnil;
1083
-
1084
1118
  result = PQexec(conn, "select lastval()");
1085
1119
  if (!result) rb_raise(rb_ePGError, PQerrorMessage(conn));
1086
1120
 
@@ -1105,7 +1139,7 @@ pgconn_lastval(obj)
1105
1139
 
1106
1140
  /*
1107
1141
  * call-seq:
1108
- * conn.client_encoding() => String
1142
+ * conn.client_encoding() -> String
1109
1143
  *
1110
1144
  * Returns the client encoding as a String.
1111
1145
  */
@@ -1146,11 +1180,11 @@ free_pgresult(ptr)
1146
1180
  #define SCALE_MASK 0xffff
1147
1181
 
1148
1182
  static int
1149
- numeric_scale(typmod)
1183
+ has_numeric_scale(typmod)
1150
1184
  int typmod;
1151
1185
  {
1152
- if ((typmod -= VARHDRSZ) >= 0) return -1;
1153
- return typmod & SCALE_MASK;
1186
+ if (typmod == -1) return 1;
1187
+ return (typmod - VARHDRSZ) & SCALE_MASK;
1154
1188
  }
1155
1189
 
1156
1190
  #define PARSE(klass, string) rb_funcall(klass, rb_intern("parse"), 1, rb_tainted_str_new2(string));
@@ -1161,11 +1195,18 @@ fetch_pgresult(result, row, column)
1161
1195
  int row;
1162
1196
  int column;
1163
1197
  {
1198
+ char* string;
1199
+
1164
1200
  if (PQgetisnull(result, row, column)) {
1165
1201
  return Qnil;
1166
1202
  }
1167
1203
 
1168
- char* string = PQgetvalue(result, row, column);
1204
+ string = PQgetvalue(result, row, column);
1205
+
1206
+ if (!translate_results) {
1207
+ return rb_tainted_str_new2(string);
1208
+ }
1209
+
1169
1210
  switch (PQftype(result, column)) {
1170
1211
 
1171
1212
  case BOOLOID:
@@ -1175,7 +1216,7 @@ fetch_pgresult(result, row, column)
1175
1216
  return pgconn_s_unescape_bytea(NULL, rb_tainted_str_new2(string));
1176
1217
 
1177
1218
  case NUMERICOID:
1178
- if (numeric_scale(PQfmod(result, column)) > 0) {
1219
+ if (has_numeric_scale(PQfmod(result, column))) {
1179
1220
  return rb_funcall(rb_cBigDecimal, rb_intern("new"), 1, rb_tainted_str_new2(string));
1180
1221
  }
1181
1222
  /* when scale == 0 return inum */
@@ -1320,7 +1361,7 @@ pgresult_aref(argc, argv, obj)
1320
1361
  *
1321
1362
  * Returns an array of Strings representing the names of the fields in the result.
1322
1363
  *
1323
- * res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable;")
1364
+ * res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable")
1324
1365
  * res.fields => [ 'foo' , 'biggles' , 'jim' , 'jam' ]
1325
1366
  */
1326
1367
  static VALUE
@@ -1382,7 +1423,7 @@ pgresult_num_fields(obj)
1382
1423
  *
1383
1424
  * Returns the name of the field (column) corresponding to the index.
1384
1425
  *
1385
- * res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable;")
1426
+ * res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable")
1386
1427
  * puts res.fieldname(2) => 'jim'
1387
1428
  * puts res.fieldname(1) => 'biggles'
1388
1429
  *
@@ -1410,7 +1451,7 @@ pgresult_fieldname(obj, index)
1410
1451
  *
1411
1452
  * Returns the index of the field specified by the string _name_.
1412
1453
  *
1413
- * res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable;")
1454
+ * res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable")
1414
1455
  * puts res.fieldnum('foo') => 0
1415
1456
  *
1416
1457
  * Raises an ArgumentError if the specified _name_ isn't one of the field names;
@@ -1458,7 +1499,7 @@ pgresult_type(obj, index)
1458
1499
  *
1459
1500
  * Returns the size of the field type in bytes. Returns <tt>-1</tt> if the field is variable sized.
1460
1501
  *
1461
- * res = conn.exec("SELECT myInt, myVarChar50 FROM foo;")
1502
+ * res = conn.exec("SELECT myInt, myVarChar50 FROM foo")
1462
1503
  * res.size(0) => 4
1463
1504
  * res.size(1) => -1
1464
1505
  */
@@ -1554,7 +1595,7 @@ pgresult_getlength(obj, tup_num, field_num)
1554
1595
 
1555
1596
  /*
1556
1597
  * call-seq:
1557
- * res.getisnull( tup_num, field_num ) => true or false
1598
+ * res.getisnull(tuple_position, field_position) -> boolean
1558
1599
  *
1559
1600
  * Returns +true+ if the specified value is +nil+; +false+ otherwise.
1560
1601
  *
@@ -1654,7 +1695,7 @@ pgresult_print(obj, file, opt)
1654
1695
  *
1655
1696
  * Returns the number of tuples (rows) affected by the SQL command.
1656
1697
  *
1657
- * If the SQL command that generated the PGresult was not one of +INSERT+, +UPDATE+, +DELETE+, +MOVE+, or +FETCH+, or if no tuples (rows) were affected, +0+ is returned.
1698
+ * If the SQL command that generated the PGresult was not one of +INSERT+, +UPDATE+, +DELETE+, +MOVE+, or +FETCH+, or if no tuples (rows) were affected, <tt>0</tt> is returned.
1658
1699
  */
1659
1700
  static VALUE
1660
1701
  pgresult_cmdtuples(obj)
@@ -1726,13 +1767,13 @@ get_pglarge(obj)
1726
1767
  {
1727
1768
  PGlarge *pglarge;
1728
1769
  Data_Get_Struct(obj, PGlarge, pglarge);
1729
- if (pglarge == 0) rb_raise(rb_ePGError, "invalid large object");
1770
+ if (pglarge == NULL) rb_raise(rb_ePGError, "invalid large object");
1730
1771
  return pglarge;
1731
1772
  }
1732
1773
 
1733
1774
  /*
1734
1775
  * call-seq:
1735
- * conn.lo_import( file ) => pglarge
1776
+ * conn.lo_import(file) -> PGlarge
1736
1777
  *
1737
1778
  * Import a file to a large object. Returns a PGlarge instance on success. On failure, it raises a PGError exception.
1738
1779
  */
@@ -1780,7 +1821,7 @@ pgconn_loexport(obj, lo_oid,filename)
1780
1821
 
1781
1822
  /*
1782
1823
  * call-seq:
1783
- * conn.lo_create( [mode] ) => pglarge
1824
+ * conn.lo_create( [mode] ) -> PGlarge
1784
1825
  *
1785
1826
  * Returns a PGlarge instance on success. On failure, it raises PGError exception.
1786
1827
  * <i>(See #lo_open for information on _mode_.)</i>
@@ -1814,7 +1855,7 @@ pgconn_locreate(argc, argv, obj)
1814
1855
 
1815
1856
  /*
1816
1857
  * call-seq:
1817
- * conn.lo_open( oid, [mode] ) => pglarge
1858
+ * conn.lo_open( oid, [mode] ) -> PGlarge
1818
1859
  *
1819
1860
  * Open a large object of _oid_. Returns a PGlarge instance on success.
1820
1861
  * The _mode_ argument specifies the mode for the opened large object,
@@ -2181,6 +2222,12 @@ pgrow_init(self, keys)
2181
2222
  return self;
2182
2223
  }
2183
2224
 
2225
+ /*
2226
+ * call-seq:
2227
+ * row.keys -> Array
2228
+ *
2229
+ * Column names.
2230
+ */
2184
2231
  static VALUE
2185
2232
  pgrow_keys(self)
2186
2233
  VALUE self;
@@ -2188,6 +2235,10 @@ pgrow_keys(self)
2188
2235
  return rb_iv_get(self, "@keys");
2189
2236
  }
2190
2237
 
2238
+ /*
2239
+ * call-seq:
2240
+ * row.values -> row
2241
+ */
2191
2242
  static VALUE
2192
2243
  pgrow_values(self)
2193
2244
  VALUE self;
@@ -2195,6 +2246,13 @@ pgrow_values(self)
2195
2246
  return self;
2196
2247
  }
2197
2248
 
2249
+ /*
2250
+ * call-seq:
2251
+ * row[position] -> value
2252
+ * row[name] -> value
2253
+ *
2254
+ * Access elements of this row by column position or name.
2255
+ */
2198
2256
  static VALUE
2199
2257
  pgrow_aref(argc, argv, self)
2200
2258
  int argc;
@@ -2211,6 +2269,12 @@ pgrow_aref(argc, argv, self)
2211
2269
  }
2212
2270
  }
2213
2271
 
2272
+ /*
2273
+ * call-seq:
2274
+ * row.each_value { |value| block } -> row
2275
+ *
2276
+ * Iterate with values.
2277
+ */
2214
2278
  static VALUE
2215
2279
  pgrow_each_value(self)
2216
2280
  VALUE self;
@@ -2219,6 +2283,12 @@ pgrow_each_value(self)
2219
2283
  return self;
2220
2284
  }
2221
2285
 
2286
+ /*
2287
+ * call-seq:
2288
+ * row.each_pair { |column_value_array| block } -> row
2289
+ *
2290
+ * Iterate with column,value pairs.
2291
+ */
2222
2292
  static VALUE
2223
2293
  pgrow_each_pair(self)
2224
2294
  VALUE self;
@@ -2231,6 +2301,13 @@ pgrow_each_pair(self)
2231
2301
  return self;
2232
2302
  }
2233
2303
 
2304
+ /*
2305
+ * call-seq:
2306
+ * row.each { |column, value| block } -> row
2307
+ * row.each { |value| block } -> row
2308
+ *
2309
+ * Iterate with values or column,value pairs.
2310
+ */
2234
2311
  static VALUE
2235
2312
  pgrow_each(self)
2236
2313
  VALUE self;
@@ -2245,6 +2322,12 @@ pgrow_each(self)
2245
2322
  return self;
2246
2323
  }
2247
2324
 
2325
+ /*
2326
+ * call-seq:
2327
+ * row.each_key { |column| block } -> row
2328
+ *
2329
+ * Iterate with column names.
2330
+ */
2248
2331
  static VALUE
2249
2332
  pgrow_each_key(self)
2250
2333
  VALUE self;
@@ -2253,6 +2336,13 @@ pgrow_each_key(self)
2253
2336
  return self;
2254
2337
  }
2255
2338
 
2339
+ /*
2340
+ * call-seq:
2341
+ * row.to_hash -> Hash
2342
+ *
2343
+ * Returns a +Hash+ of the row's values indexed by column name.
2344
+ * Equivalent to <tt>Hash [*row.keys.zip(row).flatten]</tt>
2345
+ */
2256
2346
  static VALUE
2257
2347
  pgrow_to_hash(self)
2258
2348
  VALUE self;
@@ -2273,12 +2363,11 @@ pgrow_to_hash(self)
2273
2363
  * Document-class: PGconn
2274
2364
  *
2275
2365
  * The class to access PostgreSQL database.
2276
- * All other functionality of libpq save the large object to a file.
2277
2366
  *
2278
2367
  * For example, to send query to the database on the localhost:
2279
- * require "postgres"
2280
- * conn = PGconn.connect("localhost", 5432, "", "", "test1")
2281
- * res = conn.exec("select * from a;")
2368
+ * require 'postgres'
2369
+ * conn = PGconn.open('dbname' => 'test1')
2370
+ * res = conn.exec('select * from a')
2282
2371
  *
2283
2372
  * See the PGresult class for information on working with the results of a query.
2284
2373
  */
@@ -2295,6 +2384,13 @@ pgrow_to_hash(self)
2295
2384
  */
2296
2385
 
2297
2386
 
2387
+ /********************************************************************
2388
+ *
2389
+ * Document-class: PGrow
2390
+ *
2391
+ * Array subclass that provides hash-like behavior.
2392
+ */
2393
+
2298
2394
 
2299
2395
  /********************************************************************
2300
2396
  *
@@ -2329,14 +2425,17 @@ Init_postgres()
2329
2425
  #else
2330
2426
  rb_define_singleton_method(rb_cPGconn, "new", pgconn_s_new, -1);
2331
2427
  #endif
2332
- rb_define_singleton_method(rb_cPGconn, "connect", pgconn_s_connect, -1);
2333
- rb_define_singleton_method(rb_cPGconn, "open", pgconn_s_connect, -1);
2334
- rb_define_singleton_method(rb_cPGconn, "setdb", pgconn_s_connect, -1);
2335
- rb_define_singleton_method(rb_cPGconn, "setdblogin", pgconn_s_connect, -1);
2428
+ rb_define_singleton_alias(rb_cPGconn, "connect", "new");
2429
+ rb_define_singleton_alias(rb_cPGconn, "open", "connect");
2430
+ rb_define_singleton_alias(rb_cPGconn, "setdb", "connect");
2431
+ rb_define_singleton_alias(rb_cPGconn, "setdblogin", "connect");
2432
+ rb_define_singleton_alias(rb_cPGconn, "open", "connect");
2336
2433
  rb_define_singleton_method(rb_cPGconn, "escape", pgconn_s_escape, 1);
2337
2434
  rb_define_singleton_method(rb_cPGconn, "quote", pgconn_s_quote, 1);
2435
+ rb_define_singleton_alias(rb_cPGconn, "format", "quote");
2338
2436
  rb_define_singleton_method(rb_cPGconn, "escape_bytea", pgconn_s_escape_bytea, 1);
2339
2437
  rb_define_singleton_method(rb_cPGconn, "unescape_bytea", pgconn_s_unescape_bytea, 1);
2438
+ rb_define_singleton_method(rb_cPGconn, "translate_results=", pgconn_s_translate_results_set, 1);
2340
2439
 
2341
2440
  rb_define_const(rb_cPGconn, "CONNECTION_OK", INT2FIX(CONNECTION_OK));
2342
2441
  rb_define_const(rb_cPGconn, "CONNECTION_BAD", INT2FIX(CONNECTION_BAD));
@@ -2368,7 +2467,8 @@ Init_postgres()
2368
2467
  rb_define_method(rb_cPGconn, "transaction_status", pgconn_transaction_status, 0);
2369
2468
  rb_define_method(rb_cPGconn, "protocol_version", pgconn_protocol_version, 0);
2370
2469
  rb_define_method(rb_cPGconn, "server_version", pgconn_server_version, 0);
2371
- rb_define_method(rb_cPGconn, "lastval", pgconn_lastval, 0);
2470
+ /* following line is for rdoc */
2471
+ /* rb_define_method(rb_cPGconn, "lastval", pgconn_lastval, 0); */
2372
2472
 
2373
2473
  #ifdef HAVE_PQSETCLIENTENCODING
2374
2474
  rb_define_method(rb_cPGconn, "client_encoding", pgconn_client_encoding, 0);
data/postgres.o CHANGED
Binary file
data/postgres.so CHANGED
Binary file
@@ -1,35 +1,35 @@
1
- require 'rubygems'
2
- require 'date'
3
-
4
- SPEC = Gem::Specification.new do |s|
5
- s.name = 'ruby-postgres'
6
- s.rubyforge_project = 'ruby-postgres'
7
- s.version = "0.7.1.#{Date.today}".tr('-', '.')
8
- s.summary = 'Ruby extension for PostgreSQL database coordination'
9
- s.author = 'Yukihiro Matsumoto, Eiji Matsumoto, Noboru Saitou, Dave Lee'
10
- s.email = 'davelee.com@gmail.com'
11
- s.homepage = 'http://ruby.scripting.ca/postgres/'
12
- s.requirements = 'PostgreSQL libpq library and headers'
13
- s.has_rdoc = true
14
- s.require_path = '.'
15
- s.autorequire = 'postgres'
16
-
17
- if File.exists? 'postgres.so' and PLATFORM =~ /mingw|mswin/
18
- s.platform = Gem::Platform::WIN32
19
- else
20
- s.platform = Gem::Platform::RUBY
21
- s.extensions = 'extconf.rb'
22
- end
23
-
24
- if File.exists? '_darcs'
25
- s.files = Dir.chdir('_darcs/current') { Dir['**/*'] }
26
- else
27
- s.files = Dir['**/*']
28
- end
29
-
30
- end
31
-
32
- if $0 == __FILE__
33
- Gem::manage_gems
34
- Gem::Builder.new(SPEC).build
35
- end
1
+ require 'rubygems'
2
+ require 'date'
3
+
4
+ SPEC = Gem::Specification.new do |s|
5
+ s.name = 'ruby-postgres'
6
+ s.rubyforge_project = 'ruby-postgres'
7
+ s.version = "0.7.1.#{Date.today}".tr('-', '.')
8
+ s.summary = 'Ruby extension for PostgreSQL database coordination'
9
+ s.author = 'Yukihiro Matsumoto, Eiji Matsumoto, Noboru Saitou, Dave Lee'
10
+ s.email = 'davelee.com@gmail.com'
11
+ s.homepage = 'http://ruby.scripting.ca/postgres/'
12
+ s.requirements = 'PostgreSQL libpq library and headers'
13
+ s.has_rdoc = true
14
+ s.require_path = '.'
15
+ s.autorequire = 'postgres'
16
+
17
+ if File.exists? 'postgres.so' and PLATFORM =~ /mingw|mswin/
18
+ s.platform = Gem::Platform::WIN32
19
+ else
20
+ s.platform = Gem::Platform::RUBY
21
+ s.extensions = 'extconf.rb'
22
+ end
23
+
24
+ if File.exists? '_darcs'
25
+ s.files = Dir.chdir('_darcs/current') { Dir['**/*'] }
26
+ else
27
+ s.files = Dir['**/*']
28
+ end
29
+
30
+ end
31
+
32
+ if $0 == __FILE__
33
+ Gem::manage_gems
34
+ Gem::Builder.new(SPEC).build
35
+ end
@@ -0,0 +1,52 @@
1
+ require 'postgres'
2
+ require 'date'
3
+ require 'test/unit'
4
+
5
+ class PostgresTestCase < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @conn = PGconn.new('dbname' => 'template1')
9
+ end
10
+
11
+ def teardown
12
+ @conn.close
13
+ end
14
+
15
+ def test_conversion
16
+ query = <<-EOT
17
+ select true as true_value,
18
+ false as false_value,
19
+ '12345\\\\111\\\\000\\\\111TEST'::bytea as bytea_value,
20
+ '2005-11-30'::date as date_value,
21
+ '12:00:00'::time as time_value,
22
+ now() as date_time_value,
23
+ 1.5::float as float_value,
24
+ 12345.5678::numeric as numeric_value,
25
+ 1234.56::numeric(10) as numeric_10_value,
26
+ 12345.12345::numeric(10,5) as numeric_10_5_value
27
+ EOT
28
+ res = @conn.exec(query)
29
+ assert_equal(res.num_tuples, 1)
30
+ assert_equal(res.num_fields, 10)
31
+ tuple = res.result[0]
32
+ puts tuple
33
+ assert_equal(true, tuple['true_value'])
34
+ assert_equal(false, tuple['false_value'])
35
+ assert_equal("12345\111\000\111TEST", tuple['bytea_value'])
36
+ puts PGconn.escape_bytea(tuple['bytea_value'])
37
+ assert_equal("12345I\\\\000ITEST", PGconn.escape_bytea(tuple['bytea_value']))
38
+ assert_equal(Date.parse('2005-11-30'), tuple['date_value'])
39
+ puts tuple['date_value']
40
+ assert_kind_of(Time, tuple['time_value'])
41
+ puts tuple['time_value']
42
+ assert_kind_of(DateTime, tuple['date_time_value'])
43
+ puts tuple['date_time_value']
44
+ assert_equal(1.5, tuple['float_value'])
45
+ puts PGconn.quote(tuple['numeric_value'])
46
+ assert_equal(BigDecimal("12345.5678"), tuple['numeric_value'])
47
+ assert_equal(1235, tuple['numeric_10_value'])
48
+ assert_kind_of(Integer, tuple['numeric_10_value'])
49
+ assert_equal(BigDecimal("12345.12345"), tuple['numeric_10_5_value'])
50
+ end
51
+
52
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: ruby-postgres
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.1.2005.11.24
7
- date: 2005-11-24
6
+ version: 0.7.1.2005.11.27
7
+ date: 2005-11-27
8
8
  summary: Ruby extension for PostgreSQL database coordination
9
9
  require_paths:
10
10
  - "."
@@ -42,6 +42,7 @@ files:
42
42
  - README.ja
43
43
  - ruby-postgres.gemspec
44
44
  - sample
45
+ - tests
45
46
  - type-oids.h
46
47
  - doc/postgres.html
47
48
  - doc/postgres.jp.html
@@ -51,6 +52,7 @@ files:
51
52
  - sample/test1.rb
52
53
  - sample/test2.rb
53
54
  - sample/test4.rb
55
+ - tests/tc_postgres.rb
54
56
  test_files: []
55
57
  rdoc_options: []
56
58
  extra_rdoc_files: []