ruby-postgres 0.7.1.2005.11.26 → 0.7.1.2005.11.27

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 ADDED
@@ -0,0 +1,139 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = .
7
+ topdir = c:/mingw/ruby/lib/ruby/1.8/i386-mingw32
8
+ hdrdir = $(topdir)
9
+ VPATH = $(srcdir);$(topdir);$(hdrdir)
10
+
11
+ DESTDIR = c:
12
+ prefix = $(DESTDIR)/mingw/ruby
13
+ exec_prefix = $(DESTDIR)/mingw/ruby
14
+ sitedir = $(prefix)/lib/ruby/site_ruby
15
+ rubylibdir = $(libdir)/ruby/$(ruby_version)
16
+ archdir = $(rubylibdir)/$(arch)
17
+ sbindir = $(exec_prefix)/sbin
18
+ datadir = $(prefix)/share
19
+ includedir = $(prefix)/include
20
+ infodir = $(prefix)/info
21
+ sysconfdir = $(prefix)/etc
22
+ mandir = $(prefix)/man
23
+ libdir = $(DESTDIR)/mingw/ruby/lib
24
+ sharedstatedir = $(prefix)/com
25
+ oldincludedir = $(DESTDIR)/usr/include
26
+ sitearchdir = $(sitelibdir)/$(sitearch)
27
+ bindir = $(exec_prefix)/bin
28
+ localstatedir = $(prefix)/var
29
+ sitelibdir = $(sitedir)/$(ruby_version)
30
+ libexecdir = $(exec_prefix)/libexec
31
+
32
+ CC = gcc
33
+ LIBRUBY = lib$(LIBRUBY_SO).a
34
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
35
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
36
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
37
+
38
+ CFLAGS = -g -O2
39
+ CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) -DHAVE_LIBPQ_FE_H -DHAVE_LIBPQ_LIBPQ_FS_H -DHAVE_PQSETCLIENTENCODING -DHAVE_PG_ENCODING_TO_CHAR -DHAVE_PQFREEMEM -DHAVE_PQESCAPESTRING -DHAVE_PQEXECPARAMS -Ic:/apps/POSTGR~1/8.1/include
40
+ CXXFLAGS = $(CFLAGS)
41
+ DLDFLAGS = -Wl,--enable-auto-import,--export-all
42
+ LDSHARED = gcc -shared -s
43
+ AR = ar
44
+ EXEEXT = .exe
45
+
46
+ RUBY_INSTALL_NAME = ruby
47
+ RUBY_SO_NAME = msvcrt-ruby18
48
+ arch = i386-mingw32
49
+ sitearch = i386-msvcrt
50
+ ruby_version = 1.8
51
+ ruby = c:/mingw/ruby/bin/ruby
52
+ RUBY = $(ruby)
53
+ RM = rm -f
54
+ MAKEDIRS = mkdir -p
55
+ INSTALL = /bin/install -c
56
+ INSTALL_PROG = $(INSTALL) -m 0755
57
+ INSTALL_DATA = $(INSTALL) -m 644
58
+ COPY = cp
59
+
60
+ #### End of system configuration section. ####
61
+
62
+ preload =
63
+
64
+ libpath = c:/apps/POSTGR~1/8.1/lib $(libdir)
65
+ LIBPATH = -L"c:/apps/POSTGR~1/8.1/lib" -L"$(libdir)"
66
+ DEFFILE =
67
+
68
+ CLEANFILES =
69
+ DISTCLEANFILES =
70
+
71
+ extout =
72
+ extout_prefix =
73
+ target_prefix =
74
+ LOCAL_LIBS =
75
+ LIBS = $(LIBRUBYARG_SHARED) -lpq -lwsock32
76
+ SRCS = postgres.c
77
+ OBJS = postgres.o
78
+ TARGET = postgres
79
+ DLLIB = $(TARGET).so
80
+ STATIC_LIB =
81
+
82
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
83
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
84
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
85
+
86
+ TARGET_SO = $(DLLIB)
87
+ CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
88
+ CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
89
+
90
+ all: $(DLLIB)
91
+ static: $(STATIC_LIB)
92
+
93
+ clean:
94
+ @-$(RM) $(CLEANLIBS:/=\) $(CLEANOBJS:/=\) $(CLEANFILES:/=\)
95
+
96
+ distclean: clean
97
+ @-$(RM) Makefile extconf.h conftest.* mkmf.log
98
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES:/=\)
99
+
100
+ realclean: distclean
101
+ install: install-so install-rb
102
+
103
+ install-so: $(RUBYARCHDIR)
104
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
105
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
106
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
107
+ install-rb: pre-install-rb install-rb-default
108
+ install-rb-default: pre-install-rb-default
109
+ pre-install-rb pre-install-rb-default: $(RUBYLIBDIR)
110
+ $(RUBYARCHDIR):
111
+ $(MAKEDIRS) $@
112
+ $(RUBYLIBDIR):
113
+ $(MAKEDIRS) $@
114
+
115
+ site-install: site-install-so site-install-rb
116
+ site-install-so: install-so
117
+ site-install-rb: install-rb
118
+
119
+ .SUFFIXES: .c .m .cc .cxx .cpp .o
120
+
121
+ .cc.o:
122
+ $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
123
+
124
+ .cxx.o:
125
+ $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
126
+
127
+ .cpp.o:
128
+ $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
129
+
130
+ .c.o:
131
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c $<
132
+
133
+ $(DLLIB): $(OBJS)
134
+ @-$(RM) $@
135
+ $(LDSHARED) $(DLDFLAGS) $(LIBPATH) -o $@ $(OBJS) $(LOCAL_LIBS) $(LIBS)
136
+
137
+
138
+
139
+ $(OBJS): ruby.h defines.h
data/mkmf.log ADDED
@@ -0,0 +1,154 @@
1
+ have_library: checking for main() in -lpq... -------------------- yes
2
+
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
+ checked program was:
5
+ /* begin */
6
+
7
+ /*top*/
8
+ int main() { return 0; }
9
+ int t() { main(); return 0; }
10
+ /* end */
11
+
12
+ --------------------
13
+
14
+ have_header: checking for libpq-fe.h... -------------------- yes
15
+
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
+ checked program was:
18
+ /* begin */
19
+ #include <libpq-fe.h>
20
+ /* end */
21
+
22
+ --------------------
23
+
24
+ have_header: checking for libpq/libpq-fs.h... -------------------- yes
25
+
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
+ checked program was:
28
+ /* begin */
29
+ #include <libpq/libpq-fs.h>
30
+ /* end */
31
+
32
+ --------------------
33
+
34
+ have_library: checking for main() in -lcrypto... -------------------- no
35
+
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
+ c:\mingw\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lcrypto
38
+ collect2: ld returned 1 exit status
39
+ checked program was:
40
+ /* begin */
41
+
42
+ /*top*/
43
+ int main() { return 0; }
44
+ int t() { main(); return 0; }
45
+ /* end */
46
+
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
+ c:\mingw\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lcrypto
49
+ collect2: ld returned 1 exit status
50
+ checked program was:
51
+ /* begin */
52
+ #include <windows.h>
53
+ #include <winsock.h>
54
+
55
+ /*top*/
56
+ int main() { return 0; }
57
+ int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
58
+ /* end */
59
+
60
+ --------------------
61
+
62
+ have_library: checking for main() in -lssl... -------------------- no
63
+
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
+ c:\mingw\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lssl
66
+ collect2: ld returned 1 exit status
67
+ checked program was:
68
+ /* begin */
69
+
70
+ /*top*/
71
+ int main() { return 0; }
72
+ int t() { main(); return 0; }
73
+ /* end */
74
+
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
+ c:\mingw\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lssl
77
+ collect2: ld returned 1 exit status
78
+ checked program was:
79
+ /* begin */
80
+ #include <windows.h>
81
+ #include <winsock.h>
82
+
83
+ /*top*/
84
+ int main() { return 0; }
85
+ int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
86
+ /* end */
87
+
88
+ --------------------
89
+
90
+ have_func: checking for PQsetClientEncoding()... -------------------- yes
91
+
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
+ checked program was:
94
+ /* begin */
95
+
96
+ /*top*/
97
+ int main() { return 0; }
98
+ int t() { PQsetClientEncoding(); return 0; }
99
+ /* end */
100
+
101
+ --------------------
102
+
103
+ have_func: checking for pg_encoding_to_char()... -------------------- yes
104
+
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
+ checked program was:
107
+ /* begin */
108
+
109
+ /*top*/
110
+ int main() { return 0; }
111
+ int t() { pg_encoding_to_char(); return 0; }
112
+ /* end */
113
+
114
+ --------------------
115
+
116
+ have_func: checking for PQfreemem()... -------------------- yes
117
+
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
+ checked program was:
120
+ /* begin */
121
+
122
+ /*top*/
123
+ int main() { return 0; }
124
+ int t() { PQfreemem(); return 0; }
125
+ /* end */
126
+
127
+ --------------------
128
+
129
+ have_func: checking for PQescapeString()... -------------------- yes
130
+
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
+ checked program was:
133
+ /* begin */
134
+
135
+ /*top*/
136
+ int main() { return 0; }
137
+ int t() { PQescapeString(); return 0; }
138
+ /* end */
139
+
140
+ --------------------
141
+
142
+ have_func: checking for PQexecParams()... -------------------- yes
143
+
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
+ checked program was:
146
+ /* begin */
147
+
148
+ /*top*/
149
+ int main() { return 0; }
150
+ int t() { PQexecParams(); return 0; }
151
+ /* end */
152
+
153
+ --------------------
154
+
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; \
@@ -180,6 +182,13 @@ pgconn_connect(argc, argv, self)
180
182
  return self;
181
183
  }
182
184
 
185
+ /*
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+.
191
+ */
183
192
  static VALUE
184
193
  pgconn_s_translate_results_set(self, fact)
185
194
  VALUE self, fact;
@@ -188,18 +197,6 @@ pgconn_s_translate_results_set(self, fact)
188
197
  return Qnil;
189
198
  }
190
199
 
191
- /*
192
- * See #new.
193
- */
194
- static VALUE
195
- pgconn_s_connect(argc, argv, klass)
196
- int argc;
197
- VALUE *argv;
198
- VALUE klass;
199
- {
200
- return rb_class_new_instance(argc, argv, klass);
201
- }
202
-
203
200
  static VALUE format_array_element(VALUE obj);
204
201
 
205
202
  static VALUE
@@ -282,15 +279,16 @@ format_array_element(obj)
282
279
  */
283
280
  static VALUE
284
281
  pgconn_s_quote(self, obj)
285
- VALUE self;
286
- VALUE obj;
282
+ VALUE self, obj;
287
283
  {
288
284
  char* quoted;
289
285
  int size;
290
286
  VALUE result;
291
287
 
292
288
  if (TYPE(obj) == T_STRING) {
293
- 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);
294
292
  size = PQescapeString(quoted + 1, RSTRING(obj)->ptr, RSTRING(obj)->len);
295
293
  *quoted = *(quoted + size + 1) = SINGLE_QUOTE;
296
294
  result = rb_str_new(quoted, size + 2);
@@ -389,39 +387,39 @@ pgconn_s_escape_bytea(self, obj)
389
387
  */
390
388
  static VALUE
391
389
  pgconn_s_unescape_bytea(self, obj)
392
- VALUE self;
393
- VALUE obj;
390
+ VALUE self, obj;
394
391
  {
395
392
  char *from, *to;
396
393
  size_t to_len;
397
394
  VALUE ret;
398
-
395
+
399
396
  Check_Type(obj, T_STRING);
400
397
  from = StringValuePtr(obj);
401
-
402
- to = (char *)PQunescapeBytea(from, &to_len);
403
-
398
+
399
+ to = (char *) PQunescapeBytea(from, &to_len);
400
+
404
401
  ret = rb_str_new(to, to_len);
405
402
  OBJ_INFECT(ret, obj);
406
-
407
403
  PQfreemem(to);
408
-
404
+
409
405
  return ret;
410
406
  }
411
407
 
412
408
  /*
409
+ * Document-method: new
410
+ *
413
411
  * call-seq:
414
- * PGconn.connect(host, port, options, tty, dbname, login, passwd) => conn
415
- * PGconn.open( host, port, options, tty, dbname, login, passwd) => conn
416
- * PGconn.new( host, port, options, tty, dbname, login, passwd) => conn
417
- *
418
- * _host_:: server hostname (String)
419
- * _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
420
418
  * _options_:: backend options (String)
421
419
  * _tty_:: tty to print backend debug message <i>(ignored in newer versions of PostgreSQL)</i> (String)
422
- * _dbname_:: connecting database name (String)
423
- * _login_:: login user name (String)
424
- * _passwd_:: login password (String)
420
+ * _dbname_:: connecting database name
421
+ * _login_:: login user name
422
+ * _passwd_:: login password
425
423
  *
426
424
  * On failure, it raises a PGError exception.
427
425
  */
@@ -460,7 +458,7 @@ get_pgconn(obj)
460
458
 
461
459
  /*
462
460
  * call-seq:
463
- * conn.close()
461
+ * conn.close
464
462
  *
465
463
  * Closes the backend connection.
466
464
  */
@@ -503,11 +501,13 @@ PGresult *PQexecParams_compat(PGconn *conn, VALUE command, VALUE values);
503
501
 
504
502
  /*
505
503
  * call-seq:
506
- * conn.exec( sql )
504
+ * conn.exec(sql, *bind_values)
507
505
  *
508
506
  * Sends SQL query request specified by _sql_ to the PostgreSQL.
509
507
  * Returns a PGresult instance on success.
510
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.
511
511
  */
512
512
  static VALUE
513
513
  pgconn_exec(argc, argv, obj)
@@ -658,11 +658,13 @@ pgconn_async_exec(obj, str)
658
658
 
659
659
  /*
660
660
  * call-seq:
661
- * conn.query( sql )
661
+ * conn.query(sql, *bind_values)
662
662
  *
663
663
  * Sends SQL query request specified by _sql_ to the PostgreSQL.
664
664
  * Returns an Array as the resulting tuple on success.
665
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.
666
668
  */
667
669
  static VALUE
668
670
  pgconn_query(argc, argv, obj)
@@ -675,7 +677,7 @@ pgconn_query(argc, argv, obj)
675
677
 
676
678
  /*
677
679
  * call-seq:
678
- * conn.async_query( sql )
680
+ * conn.async_query(sql)
679
681
  *
680
682
  * Sends an asynchronous SQL query request specified by _sql_ to the PostgreSQL.
681
683
  * Returns an Array as the resulting tuple on success.
@@ -1070,6 +1072,12 @@ pgconn_transaction_status(obj)
1070
1072
 
1071
1073
  #ifdef HAVE_PQSETCLIENTENCODING
1072
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
+ */
1073
1081
  static VALUE
1074
1082
  pgconn_protocol_version(obj)
1075
1083
  VALUE obj;
@@ -1077,6 +1085,12 @@ pgconn_protocol_version(obj)
1077
1085
  return INT2NUM(PQprotocolVersion(get_pgconn(obj)));
1078
1086
  }
1079
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
+ */
1080
1094
  static VALUE
1081
1095
  pgconn_server_version(obj)
1082
1096
  VALUE obj;
@@ -1084,6 +1098,15 @@ pgconn_server_version(obj)
1084
1098
  return INT2NUM(PQserverVersion(get_pgconn(obj)));
1085
1099
  }
1086
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
+ */
1087
1110
  static VALUE
1088
1111
  pgconn_lastval(obj)
1089
1112
  VALUE obj;
@@ -1116,7 +1139,7 @@ pgconn_lastval(obj)
1116
1139
 
1117
1140
  /*
1118
1141
  * call-seq:
1119
- * conn.client_encoding() => String
1142
+ * conn.client_encoding() -> String
1120
1143
  *
1121
1144
  * Returns the client encoding as a String.
1122
1145
  */
@@ -1338,7 +1361,7 @@ pgresult_aref(argc, argv, obj)
1338
1361
  *
1339
1362
  * Returns an array of Strings representing the names of the fields in the result.
1340
1363
  *
1341
- * 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")
1342
1365
  * res.fields => [ 'foo' , 'biggles' , 'jim' , 'jam' ]
1343
1366
  */
1344
1367
  static VALUE
@@ -1400,7 +1423,7 @@ pgresult_num_fields(obj)
1400
1423
  *
1401
1424
  * Returns the name of the field (column) corresponding to the index.
1402
1425
  *
1403
- * 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")
1404
1427
  * puts res.fieldname(2) => 'jim'
1405
1428
  * puts res.fieldname(1) => 'biggles'
1406
1429
  *
@@ -1428,7 +1451,7 @@ pgresult_fieldname(obj, index)
1428
1451
  *
1429
1452
  * Returns the index of the field specified by the string _name_.
1430
1453
  *
1431
- * 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")
1432
1455
  * puts res.fieldnum('foo') => 0
1433
1456
  *
1434
1457
  * Raises an ArgumentError if the specified _name_ isn't one of the field names;
@@ -1476,7 +1499,7 @@ pgresult_type(obj, index)
1476
1499
  *
1477
1500
  * Returns the size of the field type in bytes. Returns <tt>-1</tt> if the field is variable sized.
1478
1501
  *
1479
- * res = conn.exec("SELECT myInt, myVarChar50 FROM foo;")
1502
+ * res = conn.exec("SELECT myInt, myVarChar50 FROM foo")
1480
1503
  * res.size(0) => 4
1481
1504
  * res.size(1) => -1
1482
1505
  */
@@ -1572,7 +1595,7 @@ pgresult_getlength(obj, tup_num, field_num)
1572
1595
 
1573
1596
  /*
1574
1597
  * call-seq:
1575
- * res.getisnull( tup_num, field_num ) => true or false
1598
+ * res.getisnull(tuple_position, field_position) -> boolean
1576
1599
  *
1577
1600
  * Returns +true+ if the specified value is +nil+; +false+ otherwise.
1578
1601
  *
@@ -1672,7 +1695,7 @@ pgresult_print(obj, file, opt)
1672
1695
  *
1673
1696
  * Returns the number of tuples (rows) affected by the SQL command.
1674
1697
  *
1675
- * 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.
1676
1699
  */
1677
1700
  static VALUE
1678
1701
  pgresult_cmdtuples(obj)
@@ -1750,7 +1773,7 @@ get_pglarge(obj)
1750
1773
 
1751
1774
  /*
1752
1775
  * call-seq:
1753
- * conn.lo_import( file ) => pglarge
1776
+ * conn.lo_import(file) -> PGlarge
1754
1777
  *
1755
1778
  * Import a file to a large object. Returns a PGlarge instance on success. On failure, it raises a PGError exception.
1756
1779
  */
@@ -1798,7 +1821,7 @@ pgconn_loexport(obj, lo_oid,filename)
1798
1821
 
1799
1822
  /*
1800
1823
  * call-seq:
1801
- * conn.lo_create( [mode] ) => pglarge
1824
+ * conn.lo_create( [mode] ) -> PGlarge
1802
1825
  *
1803
1826
  * Returns a PGlarge instance on success. On failure, it raises PGError exception.
1804
1827
  * <i>(See #lo_open for information on _mode_.)</i>
@@ -1832,7 +1855,7 @@ pgconn_locreate(argc, argv, obj)
1832
1855
 
1833
1856
  /*
1834
1857
  * call-seq:
1835
- * conn.lo_open( oid, [mode] ) => pglarge
1858
+ * conn.lo_open( oid, [mode] ) -> PGlarge
1836
1859
  *
1837
1860
  * Open a large object of _oid_. Returns a PGlarge instance on success.
1838
1861
  * The _mode_ argument specifies the mode for the opened large object,
@@ -2199,6 +2222,12 @@ pgrow_init(self, keys)
2199
2222
  return self;
2200
2223
  }
2201
2224
 
2225
+ /*
2226
+ * call-seq:
2227
+ * row.keys -> Array
2228
+ *
2229
+ * Column names.
2230
+ */
2202
2231
  static VALUE
2203
2232
  pgrow_keys(self)
2204
2233
  VALUE self;
@@ -2206,6 +2235,10 @@ pgrow_keys(self)
2206
2235
  return rb_iv_get(self, "@keys");
2207
2236
  }
2208
2237
 
2238
+ /*
2239
+ * call-seq:
2240
+ * row.values -> row
2241
+ */
2209
2242
  static VALUE
2210
2243
  pgrow_values(self)
2211
2244
  VALUE self;
@@ -2213,6 +2246,13 @@ pgrow_values(self)
2213
2246
  return self;
2214
2247
  }
2215
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
+ */
2216
2256
  static VALUE
2217
2257
  pgrow_aref(argc, argv, self)
2218
2258
  int argc;
@@ -2229,6 +2269,12 @@ pgrow_aref(argc, argv, self)
2229
2269
  }
2230
2270
  }
2231
2271
 
2272
+ /*
2273
+ * call-seq:
2274
+ * row.each_value { |value| block } -> row
2275
+ *
2276
+ * Iterate with values.
2277
+ */
2232
2278
  static VALUE
2233
2279
  pgrow_each_value(self)
2234
2280
  VALUE self;
@@ -2237,6 +2283,12 @@ pgrow_each_value(self)
2237
2283
  return self;
2238
2284
  }
2239
2285
 
2286
+ /*
2287
+ * call-seq:
2288
+ * row.each_pair { |column_value_array| block } -> row
2289
+ *
2290
+ * Iterate with column,value pairs.
2291
+ */
2240
2292
  static VALUE
2241
2293
  pgrow_each_pair(self)
2242
2294
  VALUE self;
@@ -2249,6 +2301,13 @@ pgrow_each_pair(self)
2249
2301
  return self;
2250
2302
  }
2251
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
+ */
2252
2311
  static VALUE
2253
2312
  pgrow_each(self)
2254
2313
  VALUE self;
@@ -2263,6 +2322,12 @@ pgrow_each(self)
2263
2322
  return self;
2264
2323
  }
2265
2324
 
2325
+ /*
2326
+ * call-seq:
2327
+ * row.each_key { |column| block } -> row
2328
+ *
2329
+ * Iterate with column names.
2330
+ */
2266
2331
  static VALUE
2267
2332
  pgrow_each_key(self)
2268
2333
  VALUE self;
@@ -2271,6 +2336,13 @@ pgrow_each_key(self)
2271
2336
  return self;
2272
2337
  }
2273
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
+ */
2274
2346
  static VALUE
2275
2347
  pgrow_to_hash(self)
2276
2348
  VALUE self;
@@ -2291,12 +2363,11 @@ pgrow_to_hash(self)
2291
2363
  * Document-class: PGconn
2292
2364
  *
2293
2365
  * The class to access PostgreSQL database.
2294
- * All other functionality of libpq save the large object to a file.
2295
2366
  *
2296
2367
  * For example, to send query to the database on the localhost:
2297
- * require "postgres"
2298
- * conn = PGconn.connect("localhost", 5432, "", "", "test1")
2299
- * res = conn.exec("select * from a;")
2368
+ * require 'postgres'
2369
+ * conn = PGconn.open('dbname' => 'test1')
2370
+ * res = conn.exec('select * from a')
2300
2371
  *
2301
2372
  * See the PGresult class for information on working with the results of a query.
2302
2373
  */
@@ -2313,6 +2384,13 @@ pgrow_to_hash(self)
2313
2384
  */
2314
2385
 
2315
2386
 
2387
+ /********************************************************************
2388
+ *
2389
+ * Document-class: PGrow
2390
+ *
2391
+ * Array subclass that provides hash-like behavior.
2392
+ */
2393
+
2316
2394
 
2317
2395
  /********************************************************************
2318
2396
  *
@@ -2347,12 +2425,14 @@ Init_postgres()
2347
2425
  #else
2348
2426
  rb_define_singleton_method(rb_cPGconn, "new", pgconn_s_new, -1);
2349
2427
  #endif
2350
- rb_define_singleton_method(rb_cPGconn, "connect", pgconn_s_connect, -1);
2351
- rb_define_singleton_method(rb_cPGconn, "open", pgconn_s_connect, -1);
2352
- rb_define_singleton_method(rb_cPGconn, "setdb", pgconn_s_connect, -1);
2353
- 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");
2354
2433
  rb_define_singleton_method(rb_cPGconn, "escape", pgconn_s_escape, 1);
2355
2434
  rb_define_singleton_method(rb_cPGconn, "quote", pgconn_s_quote, 1);
2435
+ rb_define_singleton_alias(rb_cPGconn, "format", "quote");
2356
2436
  rb_define_singleton_method(rb_cPGconn, "escape_bytea", pgconn_s_escape_bytea, 1);
2357
2437
  rb_define_singleton_method(rb_cPGconn, "unescape_bytea", pgconn_s_unescape_bytea, 1);
2358
2438
  rb_define_singleton_method(rb_cPGconn, "translate_results=", pgconn_s_translate_results_set, 1);
@@ -2387,6 +2467,8 @@ Init_postgres()
2387
2467
  rb_define_method(rb_cPGconn, "transaction_status", pgconn_transaction_status, 0);
2388
2468
  rb_define_method(rb_cPGconn, "protocol_version", pgconn_protocol_version, 0);
2389
2469
  rb_define_method(rb_cPGconn, "server_version", pgconn_server_version, 0);
2470
+ /* following line is for rdoc */
2471
+ /* rb_define_method(rb_cPGconn, "lastval", pgconn_lastval, 0); */
2390
2472
 
2391
2473
  #ifdef HAVE_PQSETCLIENTENCODING
2392
2474
  rb_define_method(rb_cPGconn, "client_encoding", pgconn_client_encoding, 0);
@@ -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-1}".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,11 +1,17 @@
1
1
  require 'postgres'
2
2
  require 'date'
3
3
  require 'test/unit'
4
- class TC_MyTest < Test::Unit::TestCase
4
+
5
+ class PostgresTestCase < Test::Unit::TestCase
6
+
5
7
  def setup
6
8
  @conn = PGconn.new('dbname' => 'template1')
7
9
  end
8
10
 
11
+ def teardown
12
+ @conn.close
13
+ end
14
+
9
15
  def test_conversion
10
16
  query = <<-EOT
11
17
  select true as true_value,
@@ -42,4 +48,5 @@ EOT
42
48
  assert_kind_of(Integer, tuple['numeric_10_value'])
43
49
  assert_equal(BigDecimal("12345.12345"), tuple['numeric_10_5_value'])
44
50
  end
51
+
45
52
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
1
+ --- !ruby/object:Gem::Specification
2
+ 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.26
7
- date: 2005-11-26 00:00:00 -06:00
6
+ version: 0.7.1.2005.11.27
7
+ date: 2005-11-28
8
8
  summary: Ruby extension for PostgreSQL database coordination
9
9
  require_paths:
10
- - .
10
+ - "."
11
11
  email: davelee.com@gmail.com
12
12
  homepage: http://ruby.scripting.ca/postgres/
13
13
  rubyforge_project: ruby-postgres
@@ -18,48 +18,45 @@ bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
21
+ -
22
+ - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
24
25
  version:
25
26
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
27
  authors:
29
- - Yukihiro Matsumoto, Eiji Matsumoto, Noboru Saitou, Dave Lee
28
+ - "Yukihiro Matsumoto, Eiji Matsumoto, Noboru Saitou, Dave Lee"
30
29
  files:
31
- - sample
32
- - Contributors
33
- - test.rb
34
- - ruby-postgres.gemspec
35
- - ChangeLog
36
- - libpq-compat.c
37
- - README
38
- - doc
39
- - MANIFEST
40
- - postgres.c
41
- - extconf.rb
42
- - type-oids.h
43
- - README.ja
44
- - sample/psqlHelp.rb
45
- - sample/losample.rb
46
- - sample/test4.rb
47
- - sample/test2.rb
48
- - sample/test1.rb
49
- - sample/psql.rb
50
- - doc/postgres.jp.html
51
- - doc/postgres.html
30
+ - ChangeLog
31
+ - Contributors
32
+ - doc
33
+ - extconf.rb
34
+ - libpq-compat.c
35
+ - Makefile
36
+ - MANIFEST
37
+ - mkmf.log
38
+ - postgres.c
39
+ - README
40
+ - README.ja
41
+ - ruby-postgres.gemspec
42
+ - sample
43
+ - tests
44
+ - type-oids.h
45
+ - doc/postgres.html
46
+ - doc/postgres.jp.html
47
+ - sample/losample.rb
48
+ - sample/psql.rb
49
+ - sample/psqlHelp.rb
50
+ - sample/test1.rb
51
+ - sample/test2.rb
52
+ - sample/test4.rb
53
+ - tests/tc_postgres.rb
52
54
  test_files: []
53
-
54
55
  rdoc_options: []
55
-
56
56
  extra_rdoc_files: []
57
-
58
57
  executables: []
59
-
60
58
  extensions:
61
- - extconf.rb
59
+ - extconf.rb
62
60
  requirements:
63
- - PostgreSQL libpq library and headers
64
- dependencies: []
65
-
61
+ - PostgreSQL libpq library and headers
62
+ dependencies: []