ruby-postgres 0.7.1.2005.11.24-mswin32
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/ChangeLog +261 -0
- data/Contributors +26 -0
- data/MANIFEST +14 -0
- data/Makefile +139 -0
- data/README +171 -0
- data/README.ja +183 -0
- data/doc/postgres.html +278 -0
- data/doc/postgres.jp.html +256 -0
- data/extconf.rb +33 -0
- data/libpq-compat.c +253 -0
- data/mkmf.log +154 -0
- data/postgres.c +2454 -0
- data/postgres.o +0 -0
- data/postgres.so +0 -0
- data/ruby-postgres.gemspec +35 -0
- data/sample/losample.rb +47 -0
- data/sample/psql.rb +1181 -0
- data/sample/psqlHelp.rb +158 -0
- data/sample/test1.rb +63 -0
- data/sample/test2.rb +44 -0
- data/sample/test4.rb +71 -0
- data/type-oids.h +65 -0
- metadata +61 -0
@@ -0,0 +1,256 @@
|
|
1
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
2
|
+
"http://www.w3.org/TR/html4/strict.dtd">
|
3
|
+
<html lang="ja">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-2022-jp">
|
6
|
+
<meta http-equiv="Content-Style-Type" content="text/css">
|
7
|
+
<meta name="Keywords" lang="en" content="Ruby PostgreSQL">
|
8
|
+
<link rev="made" href="mailto:noborus@netlab.jp">
|
9
|
+
<link rel="contents" href="./index.html">
|
10
|
+
<style type="text/css">
|
11
|
+
<!--
|
12
|
+
body {
|
13
|
+
background-color: white;
|
14
|
+
color: black;
|
15
|
+
}
|
16
|
+
address { text-align: right }
|
17
|
+
div.lastmodifed { text-align: right }
|
18
|
+
div.language { text-align: right }
|
19
|
+
pre {
|
20
|
+
white-space: pre;
|
21
|
+
background-color: antiquewhite;
|
22
|
+
border: inset thin;
|
23
|
+
}
|
24
|
+
-->
|
25
|
+
</style>
|
26
|
+
<title>Postgres reference</title>
|
27
|
+
</head>
|
28
|
+
<body>
|
29
|
+
<div class = "language">
|
30
|
+
[<a href="postgres.html">English</a> | Japanese]
|
31
|
+
</div>
|
32
|
+
<h1><a name="reference">Postgres reference</a></h1>
|
33
|
+
<div class = "lastmodifed">
|
34
|
+
Last update: Mon, 5 Mar 2001 00:34:55 +0900
|
35
|
+
</div>
|
36
|
+
<hr>
|
37
|
+
<div>
|
38
|
+
<h2><a name="PGconn">PGconn</a></h2>
|
39
|
+
<p>
|
40
|
+
PostgreSQL$B$K%"%/%;%9$9$k$?$a$N%/%i%9!#$=$NB>$N%a%=%C%I$O(Blibpq$B$H$[$\F1$8%$%s%?%U%'!<%9$GDs6!$5$l$^$9!#(B
|
41
|
+
</p>
|
42
|
+
<p>
|
43
|
+
$BNc$($P!"(Blocalhost $B>e$N(B PostgreSQL $B$K@\B3$7!"(Bquery $B$r=P$9$?$a$K$O0J2<$N$h$&$K$7$F9T$$$^$9!#(B
|
44
|
+
</p>
|
45
|
+
<pre>
|
46
|
+
require "postgres"
|
47
|
+
conn = PGconn.connect("localhost", 5432, "", "", "test1")
|
48
|
+
res = conn.exec("select * from a;")
|
49
|
+
</pre>
|
50
|
+
<h3>$B%9!<%P!<%/%i%9(B:</h3>
|
51
|
+
<code>Object</code>
|
52
|
+
<h3>$B%/%i%9%a%=%C%I(B:</h3>
|
53
|
+
<p>
|
54
|
+
<a name="PGconn.connect"><code>connect(<var>pghost</var>,
|
55
|
+
<var>pgport</var>, <var>pgoptions</var>,
|
56
|
+
<var>pgtty</var>, <var>dbname</var>, <var>login</var>,
|
57
|
+
<var>passwd</var>)</code></a>
|
58
|
+
<a name="PGconn.new"><code>new(<var>pghost</var>,
|
59
|
+
<var>pgport</var>, <var>pgoptions</var>,
|
60
|
+
<var>pgtty</var>, <var>dbname</var>, <var>login</var>,
|
61
|
+
<var>passwd</var>)</code></a>
|
62
|
+
<a name="PGconn.open"><code>open(<var>string</var>)</code></a>
|
63
|
+
</p>
|
64
|
+
<dl>
|
65
|
+
<dt>PostgreSQL$B%5!<%P$H@\B3$7$^$9!#%*%W%7%g%s$N0UL#$O0J2<$NDL$j$G$9!#(B</dt>
|
66
|
+
<dd><var>pghost</var> : $B%5!<%P$N%[%9%HL>(B($BJ8;zNs(B)
|
67
|
+
<dd><var>pgport</var> : $B%5!<%P$,(Blisten$B$7$F$$$k%]!<%HHV9f(B($B@0?t(B)
|
68
|
+
<dd><var>pgoptions</var> : backend$B$r5/F0$9$k:]$N%*%W%7%g%s(B($BJ8;zNs(B)
|
69
|
+
<dd><var>pgtty</var> : backend$B$,%G%P%C%0%a%C%;!<%8$rI=<($9$k(Btty($BJ8;zNs(B)
|
70
|
+
<dd><var>dbname</var> : $B@\B3$9$k%G!<%?%Y!<%9L>(B($BJ8;zNs(B)
|
71
|
+
<dd><var>login</var> : $B%f!<%6L>(B($BJ8;zNs(B)
|
72
|
+
<dd><var>passwd</var> : $B%Q%9%o!<%I(B($BJ8;zNs(B)
|
73
|
+
<dt>$B%*%W%7%g%s$rJ8;zNs$GEO$9>l9g$N%U%)!<%^%C%H$G$9!#(B</dt>
|
74
|
+
<dd><var>host=name</var> : $B%5!<%P$N%[%9%HL>(B($BJ8;zNs(B)
|
75
|
+
<dd><var>hostaddr=addr</var> : $B%5!<%P$N(BIP$B%"%I%l%9(B($BJ8;zNs(B)
|
76
|
+
<dd><var>port=number</var> $B%5!<%P$,(Blisten$B$7$F$$$k%]!<%HHV9f(B($B@0?t(B)
|
77
|
+
<dd><var>options=string</var> : backend$B$r5/F0$9$k:]$N%*%W%7%g%s(B($BJ8;zNs(B)
|
78
|
+
<dd><var>tty=anything</var> : backend$B$,%G%P%C%0%a%C%;!<%8$rI=<($9$k(Btty($BJ8;zNs(B)
|
79
|
+
<dd><var>dbname=name</var> : $B@\B3$9$k%G!<%?%Y!<%9L>(B($BJ8;zNs(B)
|
80
|
+
<dd><var>user=username</var> : $B%f!<%6L>(B($BJ8;zNs(B)
|
81
|
+
<dd><var>password=censored</var> : $B%Q%9%o!<%I(B($BJ8;zNs(B)
|
82
|
+
<dd><var>sslmode=mode</var> : SSL$B%b!<%I$N;XDj(B($BJ8;zNs(B) (disable, allow, prefer, require)
|
83
|
+
<dd><var>service=name</var> : $BB>$N%Q%i%a!<%?MQ$K;HMQ$5$l$k%5!<%S%9L>(B($BJ8;zNs(B)
|
84
|
+
<dd><var>connect_timeout=seconds</var> : $B@\B3%?%$%`%"%&%H;~4V(B($B@0?t(B)
|
85
|
+
</dl>
|
86
|
+
<p>$B<:GT$7$?>l9g$O(B <code>PGError</code> $BNc30$,H/@8$7$^$9!#(B</p>
|
87
|
+
<h3>methods:</h3>
|
88
|
+
<dl>
|
89
|
+
<dt><a name="db"><code>db</code></a>
|
90
|
+
<dd>$B@\B3$7$?%G!<%?%Y!<%9L>$rJV$7$^$9!#(B
|
91
|
+
<dt><a name="host"><code>host</code></a>
|
92
|
+
<dd>$B@\B3$7$?%5!<%PL>$rJV$7$^$9!#(B
|
93
|
+
<dt><a name="user"><code>user</code></a>
|
94
|
+
<dd>$B%5!<%P$X@\B3;~$KG'>Z$7$?%f!<%6L>$rJV$7$^$9!#(B
|
95
|
+
<dt><a name="options"><code>options</code></a>
|
96
|
+
<dd>backend$B$r5/F0$9$k:]$K;XDj$7$?(Boption$B$rJV$7$^$9!#(B
|
97
|
+
<dt><a name="port"><code>port</code></a>
|
98
|
+
<dd>$B%5!<%P$X@\B3$9$k:]$K;HMQ$7$?%]!<%HHV9f$rJV$7$^$9!#(B
|
99
|
+
<dt><a name="tty"><code>tty</code></a>
|
100
|
+
<dd>$B@\B3$7$F$$$k(Bpgtty$B$rJV$7$^$9!#(B
|
101
|
+
<dt><a name="error"><code>error</code></a>
|
102
|
+
<dd>$B@\B3$K4X$9$k%(%i!<%a%C%;!<%8$rJV$7$^$9!#(B
|
103
|
+
<dt> <a name="finish"><code>finish</code></a>
|
104
|
+
<dt> <a name="close"><code>close</code></a>
|
105
|
+
<dd>$B%P%C%/%(%s%I$H$N@\B3$r=*N;$7$^$9!#(B
|
106
|
+
<dt><a name="reset"><code>reset</code></a>
|
107
|
+
<dd>$B%P%C%/%(%s%I$H$NDL?.%]!<%H$r%j%;%C%H$7$^$9!#$3$N4X?t$O%P%C%/%(%s%I$H$N%=%1%C%H@\B3$r=*N;$7!"$$$:$l$+$N%P%C%/%(%s%I$H$N?7$7$$@\B3$N:F3NN)$r;n$_$^$9!#(B
|
108
|
+
<dt><a name="trace"><code>trace(<var>port</var>)</code></a>
|
109
|
+
<dd>$B%P%C%/%(%s%I$H$N%a%C%;!<%8$N<uEO$7$N%H%l!<%9$rM-8z$K$7$^$9!#%a%C%;!<%8$O(B<var>port</var>$B$G;XDj$5$l$?(B File $B%/%i%9$N%$%s%9%?%s%9$X=q$-=P$5$l$^$9!#(B
|
110
|
+
<dt><a name="untrace"><code>untrace</code></a>
|
111
|
+
<dd>$B%P%C%/%(%s%I$H$N%a%C%;!<%8$N<uEO$7$N%H%l!<%9$rL58z$K$7$^$9!#(B
|
112
|
+
<dt><a name="exec"><code>exec(<var>sql</var>)</code></a>
|
113
|
+
<dd><var>sql</var>$B$G;XDj$5$l$?(BSQL$BLd$$9g$o$;J8$r(BPostgreSQL$B$XAw$j$^$9!#(B
|
114
|
+
$BLd$$9g$o$;$,@.8y$7$?>l9g$K$O!"7k2L$,(B<a href="#PGresult">PGresult</a>$B%/%i%9$N(B
|
115
|
+
$B%$%s%9%?%s%9$H$7$FJV$5$l!"$=$&$G$J$$>l9g$ONc30$,H/@8$7$^$9!#(B
|
116
|
+
<dt><a name="query"><code>query(<var>sql</var>)</code></a>
|
117
|
+
<dd><var>sql</var>$B$G;XDj$5$l$?(BSQL$BLd$$9g$o$;J8$r(BPostgreSQL$B$XAw$j$^$9!#(B
|
118
|
+
$BLd$$9g$o$;$,@.8y$7$?>l9g$K$O!"7k2L$,(B Array $B%/%i%9$N(B
|
119
|
+
$B%$%s%9%?%s%9$H$7$FJV$5$l!"$=$&$G$J$$>l9g$O(B nil $B$,JV$5$l$^$9!#(B
|
120
|
+
<dt><a name="async_exec"><code>async_exec(<var>sql</var>)</code></a>
|
121
|
+
<dd><var>sql</var>$B$G;XDj$5$l$?(BSQL$BLd$$9g$o$;J8$r(BPostgreSQL$B$X(B
|
122
|
+
$BHsF14|$G(B $BAw$j$^$9!#Ld$$9g$o$;$,@.8y$7$?>l9g$K$O!"(B
|
123
|
+
$B7k2L$,(B<a href="#PGresult">PGresult</a>$B%/%i%9$N(B
|
124
|
+
$B%$%s%9%?%s%9$H$7$FJV$5$l!"$=$&$G$J$$>l9g$ONc30$,H/@8$7$^$9!#(B
|
125
|
+
<dt><a name="async_query"><code>async_query(<var>sql</var>)</code></a>
|
126
|
+
<dd><var>sql</var>$B$G;XDj$5$l$?(BSQL$BLd$$9g$o$;J8$r(BPostgreSQL$B$X(B
|
127
|
+
$BHsF14|$G(B $BAw$j$^$9!#Ld$$9g$o$;$,@.8y$7$?>l9g$K$O!"7k2L$,(B Array $B%/%i%9$N(B
|
128
|
+
$B%$%s%9%?%s%9$H$7$FJV$5$l!"$=$&$G$J$$>l9g$O(B nil $B$,JV$5$l$^$9!#(B
|
129
|
+
<dt><a name="get_notify"><code>get_notify</code></a>
|
130
|
+
<dd>$B%P%C%/%(%s%I$+$iL$=hM}$NDLCN%j%9%H$rF@$F!"(BArray $B%/%i%9$N%$%s%9%?%s%9$H$7$FJV$7$^$9!#%P%C%/%(%s%I$+$i$NL$=hM}$NDLCN$,$J$$>l9g$K$O!"(Bnil $B$,JV$5$l$^$9!#(B
|
131
|
+
<dt><a name="insert_table"><code>insert_table(<var>table</var>,
|
132
|
+
<var>array</var>)</code></a>
|
133
|
+
<dd><var>table</var>$B$G;XDj$5$l$?%F!<%V%k$KBP$7!"(B<var>array</var>$B$NFbMF$rA^F~$7$^$9!#(B<var>array</var>$B$O(B Array $B%/%i%9$N%$%s%9%?%s%9$G$J$1$l$P$J$j$^$;$s!#(B
|
134
|
+
<dt><a name="getline"><code>getline</code></a>
|
135
|
+
<dd>$B%P%C%/%(%s%I%5!<%P$+$i2~9T%3!<%I$G=*$k9T$rFI$_<h$j$^$9!#(B<code>fgets(3)</code>$B$HF1MM$K!"$3$N%a%=%C%I$O(B<code>get(3)</code>$B$HF1MM$K=*C<9T$r%L%k$KJQ49$7$^$9!#(Bgetline$B$O(BEOF$B$N>l9g$O!"(Bnil $B$r!"9TA4BN$rFI$_<h$C$?>l9g$O(B0$B$r!"$^$@2~9T%3!<%I$rFI$_<h$C$F$$$J$$>l9g$O(B1$B$rJV$7$^$9!#$3$N%a%=%C%I$r;HMQ$9$k;~$NCm0UE@$O!"%P%C%/%(%s%I%5!<%P$,7k2L$NAw?.$r40N;$7$?$3$H$r<($9C10lJ8;z(B"."$B$r?75,9T$KAw?.$7$?$3$H$r3NG'$7$J$1$l$P$J$i$J$$$3$H$G$9!#(B<br>
|
136
|
+
$B%5%s%W%k%3!<%I(B<a href="../sample/psql.rb">psql.rb</a>$B$O!"(Bcopy$B%W%m%H%3%k$r@5$7$/07$&%=!<%9$r4^$s$G$$$^$9!#(B
|
137
|
+
<dt><a name="putline"><code>putline(<var>string</var>)</code></a>
|
138
|
+
<dd><var>string</var>$B$G;XDj$5$l$?J8;zNs$r%P%C%/%(%s%I!<%5!<%P$XAw?.$7$^$9!#;HMQ<T$O%G!<%?$NAw?.$,40N;$7$?$3$H$r%P%C%/%(%s%I$K<($9$?$a$K!"C10lJ8;z(B"."$B$rL@<(E*$KAw?.$7$J$1$l$P$J$j$^$;$s!#(B
|
139
|
+
<dt><a name="endcopy"><code>endcopy</code></a>
|
140
|
+
<dd>$B%P%C%/%(%s%I$HF14|$r$H$j$^$9!#$3$N%a%=%C%I$O%P%C%/%(%s%I$,(Bcopy$B$r40N;$9$k$^$GBT$A$^$9!#(B<a href="#putline">putline</a>$B$d(B<a href="#getline">getline</a>$B$r;HMQ$7$?>l9g$K;HMQ$9$Y$-%a%=%C%I$G$9!#(Bcopy$B$,$&$^$/40N;$7$?>l9g$K$O(B nil $B$,JV$j!"$=$&$G$J$$>l9g$ONc30$,H/@8$7$^$9!#(B
|
141
|
+
<dt><a name="set_client_encoding"><code>set_client_encoding</code></a>
|
142
|
+
<dd>$B%/%i%$%"%s%H$NJ8;z%3!<%I$r;XDj$7$^$9(B($BJ8;zNs(B)$B!#(B
|
143
|
+
<dt><a name="client_encoding"><code>client_encoding</code></a>
|
144
|
+
<dd>$B%/%i%$%"%s%H$NJ8;z%3!<%I$rJV$7$^$9(B($BJ8;zNs(B)$B!#(B
|
145
|
+
|
146
|
+
<dt><a name="lo_import"><code>lo_import(<var>file</var>)</code></a>
|
147
|
+
<dd><var>file</var>$B$r%i!<%8%*%V%8%'%/%H$K%$%s%]!<%H$7$^$9!#@.8y$9$k$H(B<a href="#PGlarge">PGlarge</a>$B%/%i%9$N%$%s%9%?%s%9$,JV$5$l$^$9!#<:GT$9$k$H(B <code>PGError</code> $BNc30$,H/@8$7$^$9!#(B
|
148
|
+
<dt><a name="lo_export"><code>lo_export(<var>oid</var>, <var>file</var>)</code></a>
|
149
|
+
<dd>$B%i!<%8%*%V%8%'%/%H$r(B <var>file</var> $B$KJ]B8$7$^$9!#(B
|
150
|
+
<dt><a name="lo_create"><code>lo_create([<var>mode</var>])</code></a>
|
151
|
+
<dd>$B?7$7$/%i!<%8%*%V%8%'%/%H$r$D$/$j$^$9!#@.8y$9$k$H(B<a href="#PGlarge">PGlarge</a> $B%/%i%9$N%$%s%9%?%s%9$,JV$5$l$^$9!#<:GT$9$k$H(B <code>PGError</code> $BNc30$,H/@8$7$^$9!#(B
|
152
|
+
<dt><a name="lo_open"><code>lo_open(<var>oid</var>, [<var>mode</var>])</code></a>
|
153
|
+
<dd>oid $B$N%i!<%8%*%V%8%'%/%H$r3+$-$^$9!#@.8y$9$k$H(B<a href="#PGlarge">PGlarge</a> $B%/%i%9$N%$%s%9%?%s%9$,JV$5$l$^$9!#<:GT$9$k$H(B <code>PGError</code> $BNc30$,H/@8$7$^$9!#(B<var>"INV_READ"</var>,<var>"INV_WRITE"</var>$B$N$I$A$i$+$N%b!<%I$r;XDj$7$^$9!#<:GT$9$k$H(B <code>PGError</code> $BNc30$,H/@8$7$^$9!#%b!<%I$r>JN,$7$?>l9g$O(B<var>"INV_READ"</var>$B$G$9!#(B
|
154
|
+
<dt><a name="lo_unlink"><code>lo_unlink(<var>oid</var>)</code></a>
|
155
|
+
<dd><var>oid</var>$B$N%i!<%8%*%V%8%'%/%H$r:o=|$7$^$9!#(B
|
156
|
+
</dl>
|
157
|
+
</div>
|
158
|
+
<hr>
|
159
|
+
<div>
|
160
|
+
<h2><a name="PGresult">PGresult</a></h2>
|
161
|
+
<P>
|
162
|
+
Query$B$N7k2L$H$7$FF@$i$l$?%?%C%W%k$r(Bwrap$B$9$k%/%i%9!%$3$N%/%i%9(B
|
163
|
+
$B$N%$%s%9%?%s%9$O!"(Bquery$B$r9T$&$?$S$K@8@.$5$l$^$9!#8N$KF@$i$l$?(B
|
164
|
+
$B7k2L$,ITMW$K$J$C$?>l9g$K$O!"(Bclear$B$r8F$S=P$7$F%a%b%j$r2rJ|$9$k(B
|
165
|
+
$B$h$&$K$7$F2<$5$$!#(B
|
166
|
+
</P>
|
167
|
+
<h3>$B%9!<%Q!<%/%i%9(B:</h3>
|
168
|
+
<p>
|
169
|
+
<code>Object</code>
|
170
|
+
</p>
|
171
|
+
<h2>$B%a%=%C%I(B:</h2>
|
172
|
+
<dl>
|
173
|
+
<dt><a name="status"><code>status</code></a>
|
174
|
+
<dd><dl>
|
175
|
+
<dt>$BLd$$9g$o$;7k2L$N%9%F!<%?%9$rJV$7$^$9!#%9%F!<%?%9$O0J2<$NCM$N$&$A$N$$$:$l$+0l$D$rJV$7$^$9!#(B
|
176
|
+
<dd>EMPTY_QUERY
|
177
|
+
<dd>COMMAND_OK
|
178
|
+
<dd>TUPLES_OK
|
179
|
+
<dd>COPY_OUT
|
180
|
+
<dd>COPY_IN
|
181
|
+
</dl>
|
182
|
+
<dt><a name="result"><code>result</code></a>
|
183
|
+
<dd>$BLd$$9g$o$;7k2L$N%?%C%W%k(B($B%$%s%9%?%s%9(B)$B$r!"G[Ns$GJV$7$^$9!#(B
|
184
|
+
<dt><a name="fields"><code>fields</code></a>
|
185
|
+
<dd>$BLd$$9g$o$;$N7k2L$N%U%#!<%k%I(B($BB0@-(B)$B$r!"G[Ns$GJV$7$^$9!#(B
|
186
|
+
<dt><a name="num_tuples"><code>num_tuples</code></a>
|
187
|
+
<dd>$BLd$$9g$o$;7k2L$N%?%C%W%k(B($B%$%s%9%?%s%9(B)$B$N?t$rJV$7$^$9!#(B
|
188
|
+
<dt><a name="num_fields"><code>num_fields</code></a>
|
189
|
+
<dd>$BLd$$9g$o$;$N7k2L$N%U%#!<%k%I(B($BB0@-(B)$B$N?t$rJV$7$^$9!#(B
|
190
|
+
<dt><a name="fieldname"><code>fieldname(<var>index</var>)</code></a>
|
191
|
+
<dd>$BM?$($i$l$?%U%#!<%k%I(B($BB0@-(B)$B$N:w0z(B(field index)$B$KBP1~$9$k%U%#!<%k%I(B($BB0@-(B)$B$NL>A0$rJV$7$^$9!#%U%#!<%k%I!&%$%s%G%#%1!<%?$O(B0$B$+$i3+;O$5$l$^$9!#(B
|
192
|
+
<dt><a name="fieldnum"><code>fieldnum(<var>name</var>)</code></a>
|
193
|
+
<dd>$BM?$($i$l$?%U%#!<%k%I(B($BB0@-(B)$B$NL>A0$KBP1~$9$k!"%U%#!<%k%I(B($BB0@-(B)$B$N:w0z$rJV$7$^$9!#(B
|
194
|
+
<dt><a name="type"><code>type(<var>index</var>)</code></a>
|
195
|
+
<dd>$BM?$($i$l$?%U%#!<%k%I(B($BB0@-(B)$B$KBP1~$9$k%U%#!<%k%I$N7?$rJV$7$^$9!#FbIt%3!<%G%#%s%0$5$l$F$$$k7?$,@0?t$GJV$5$l$^$9!#%U%#!<%k%I!&%$%s%G%#%1!<%?$O(B0$B$+$i3+;O$5$l$^$9!#(B
|
196
|
+
<dt><a name="size"><code>size(<var>index</var>)</code></a>
|
197
|
+
<dd>$BM?$($i$l$?%U%#!<%k%I(B($BB0@-(B)$B$KBP1~$9$k%U%#!<%k%I$N%5%$%:$r%P%$%H?t$GJV$7$^$9!#JV$5$l$k%5%$%:$,(B-1$B$N>l9g!"%U%#!<%k%I$O2DJQD9$G$9!#%U%#!<%k%I!&%$%s%G%#%1!<%?$O(B0$B$+$i3+;O$5$l$^$9!#(B
|
198
|
+
<dt><a name="getvalue"><code>getvalue(<var>tup_num, field_num</var>)
|
199
|
+
</code></a>
|
200
|
+
<dd>$B%U%#!<%k%I(B($BB0@-(B)$B$NCM$rJV$7$^$9!#$[$H$s$I$NLd$$9g$o$;$KBP$7$F!"(B<a href="#getvalue">getvalue</a>$B$K$h$C$FJV$5$l$kCM$O!"%L%k$G=*$o$k(BASCII$BJ8;zNs$GI=8=$5$l$^$9!#Ld$$9g$o$;$N7k2L$,%P%$%J%j%+!<%=%k$G$"$C$?>l9g!"(B<a href="#getvalue">getvalue</a>$B$K$h$C$FJV$5$l$kCM$O!"%P%C%/%(%s%I!&%5!<%P$NFbIt%U%)!<%^%C%H$K0MB8$7$?%P%$%J%j$GI=8=$5$l$^$9!#%G!<%?$r@5$7$$%?%$%W$K%-%c%9%H$7$?$j!"JQ49$7$?$j$9$k$N$O%W%m%0%i%^$N@UG$$G$9!#(B<a href="#PGresult">PGresult</a>$B$N%$%s%9%?%s%9$O(Bquery$B$N$?$S$K@8@.$5$l$^$9!#ITMW$K$J$C$?>l9g$O!"%W%m%0%i%^$,@UG$$r$b$C$F(B<a href="#clear">clear</a>$B$r8F$S=P$7%a%b%j$r2rJ|$7$F2<$5$$!#(B
|
201
|
+
<dt><a name="getlength"><code>getlength(<var>tup_num, field_num</var>)
|
202
|
+
</code></a>
|
203
|
+
<dd>$B%U%#!<%k%I(B($BB0@-(B)$B$ND9$5$r%P%$%H$GJV$7$^$9!#(B
|
204
|
+
<dt><a name="cmdtuples"><code>cmdtuples</code></a>
|
205
|
+
<dd>$B:G8e$NLd$$9g$o$;%3%^%s%I$N1F6A$r$&$1$?9T?t$rJV$7$^$9!#(B
|
206
|
+
<dt><a name="cmdstatus"><code>cmdstatus</code></a>
|
207
|
+
<dd>$B:G8e$NLd$$9g$o$;%3%^%s%I$N%3%^%s%I%9%F!<%?%9$rJ8;zNs$GJV$7$^$9!#(B
|
208
|
+
<dt><a name="oid"><code>oid</code></a>
|
209
|
+
<dd>$BA^F~$5$l$?9T$N(BOID$B$rJV$7$^$9!#(B
|
210
|
+
<dt><a name="clear"><code>clear</code></a>
|
211
|
+
<dd>$BLd$$9g$o$;$N7k2L@8@.$5$l$?(B<a href="#PGresult">PGresult</a>$B$N%$%s%9%?%s%9$r%/%j%"$7$^$9!#(B
|
212
|
+
</dl>
|
213
|
+
</div>
|
214
|
+
<hr>
|
215
|
+
<div>
|
216
|
+
<h2><a name="PGlarge">PGlarge</a></h2>
|
217
|
+
<p>
|
218
|
+
$B%i!<%8%*%V%8%'%/%H$K%"%/%;%9$9$k$?$a$N%/%i%9!#$3$N%*%V%8%'%/%H$O(B <a href="lo_import">lo_import</a>, <a href="lo_create">lo_create</a>, <a href="lo_open">lo_open</a> $B$N7k2L$H$7$FJV$5$l$^$9!#(B
|
219
|
+
</p>
|
220
|
+
<h3>super class:</h3>
|
221
|
+
<p>
|
222
|
+
<code>Object</code>
|
223
|
+
</p>
|
224
|
+
<h2>methods:</h2>
|
225
|
+
<dl>
|
226
|
+
<dt><a name="open"><code>open([<var>mode</var>])</code></a>
|
227
|
+
<dd>$B%i!<%8%*%V%8%'%/%H$r3+$-$^$9!#(B <var>"INV_READ"</var>,<var>"INV_WRITE"</var>$B$N$I$A$i$+$N%b!<%I$r;XDj$7$^$9!#<:GT$9$k$H(B <code>PGError</code> $BNc30$,H/@8$7$^$9!#%b!<%I$r>JN,$7$?>l9g$O(B<var>"INV_READ"</var>$B$G$9!#(B
|
228
|
+
<dt><a name="close"><code>close</code></a>
|
229
|
+
<dd>$B%i!<%8%*%V%8%'%/%H$rJD$8$^$9!#0J9_$3$N%*%V%8%'%/%H$KBP$9$k%"%/%;%9$ONc30$rH/@8$7$^$9!#(B
|
230
|
+
<dt><a name="read"><code>read([<var>length</var>])</code></a>
|
231
|
+
<dd><var>length</var> $B%P%$%HFI$_9~$s$G$=$NJ8;zNs$rJV$7$^$9!#(B<var>length</var> $B$,>JN,$5$l$?;~$K$O!"A4$F$N%G!<%?$rFI$_9~$_$^$9!#(B
|
232
|
+
<dt><a name="write"><code>write(<var>str</var>)</code></a>
|
233
|
+
<dd><var>str</var>$B$r%i!<%8%*%V%8%'%/%H$K=q$-9~$_$^$9!#=q$-9~$s$@%P%$%H?t$rJV$7$^$9!#(B
|
234
|
+
<dt><a name="seek"><code>seek(<var>offset</var>, <var>whence</var>)</code></a>
|
235
|
+
<dd>$B%i!<%8%*%V%8%'%/%H$N%]%$%s%?$r(B <var>offset</var> $B0\F0$7$^$9!#(B<var>whence</var> $B$O(B SEEK_SET, SEEK_CUR, and SEEK_END $B$,;XDj$G$-$^$9!#$=$l$>$l(B 0,1,2$B$H?t;z$G;XDj$7$F$b9=$$$^$;$s!#(B
|
236
|
+
<dt><a name="tell"><code>tell</code></a>
|
237
|
+
<dd>$B%i!<%8%*%V%8%'%/%H$N%]%$%s%?$N8=:_$N0LCV$rJV$7$^$9!#(B
|
238
|
+
<dt><a name="unlink"><code>unlink</code></a>
|
239
|
+
<dd>$B%i!<%8%*%V%8%'%/%H$r:o=|$7$^$9!#(B
|
240
|
+
<dt><a name="oid"><code>oid</code></a>
|
241
|
+
<dd>$B%i!<%8%*%V%8%'%/%H$N(B oid $B$rJV$7$^$9!#(B
|
242
|
+
<dt><a name="size"><code>size</code></a>
|
243
|
+
<dd>$B%i!<%8%*%V%8%'%/%H$N%5%$%:$rJV$7$^$9!#(B
|
244
|
+
<dt><a name="export"><code>export(<var>file</var>)</code></a>
|
245
|
+
<dd><var>file</var>$B$K%i!<%8%*%V%8%'%/%H$r=q$-=P$7$^$9!#(B
|
246
|
+
</dl>
|
247
|
+
</div>
|
248
|
+
<hr>
|
249
|
+
<address>
|
250
|
+
mailto:
|
251
|
+
<a href="mailto:noborus@netlab.jp">Noboru Saitou</a>
|
252
|
+
</address>
|
253
|
+
</body>
|
254
|
+
</html>
|
255
|
+
|
256
|
+
|
data/extconf.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
if RUBY_VERSION < '1.3'
|
2
|
+
puts 'This library is for ruby-1.3 or higher.'
|
3
|
+
exit 1
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'mkmf'
|
7
|
+
|
8
|
+
def config_value(type)
|
9
|
+
ENV["POSTGRES_#{type.upcase}"] || pg_config(type)
|
10
|
+
end
|
11
|
+
|
12
|
+
def pg_config(type)
|
13
|
+
IO.popen("pg_config --#{type}dir").readline.chomp rescue nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def have_build_env
|
17
|
+
have_library('pq') && have_header('libpq-fe.h') && have_header('libpq/libpq-fs.h')
|
18
|
+
end
|
19
|
+
|
20
|
+
dir_config('pgsql', config_value('include'), config_value('lib'))
|
21
|
+
|
22
|
+
required_libraries = %w(crypto ssl)
|
23
|
+
desired_functions = %w(PQsetClientEncoding pg_encoding_to_char PQfreemem)
|
24
|
+
compat_functions = %w(PQescapeString PQexecParams)
|
25
|
+
|
26
|
+
if have_build_env
|
27
|
+
required_libraries.each(&method(:have_library))
|
28
|
+
desired_functions.each(&method(:have_func))
|
29
|
+
$objs = ['postgres.o'] if compat_functions.all?(&method(:have_func))
|
30
|
+
create_makefile("postgres")
|
31
|
+
else
|
32
|
+
puts 'Could not find PostgreSQL build environment (libraries & headers): Makefile not created'
|
33
|
+
end
|
data/libpq-compat.c
ADDED
@@ -0,0 +1,253 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
|
3
|
+
#ifndef HAVE_PQESCAPESTRING
|
4
|
+
/*
|
5
|
+
* Escaping arbitrary strings to get valid SQL literal strings.
|
6
|
+
*
|
7
|
+
* Replaces "\\" with "\\\\" and "'" with "''".
|
8
|
+
*
|
9
|
+
* length is the length of the source string. (Note: if a terminating NUL
|
10
|
+
* is encountered sooner, PQescapeString stops short of "length"; the behavior
|
11
|
+
* is thus rather like strncpy.)
|
12
|
+
*
|
13
|
+
* For safety the buffer at "to" must be at least 2*length + 1 bytes long.
|
14
|
+
* A terminating NUL character is added to the output string, whether the
|
15
|
+
* input is NUL-terminated or not.
|
16
|
+
*
|
17
|
+
* Returns the actual length of the output (not counting the terminating NUL).
|
18
|
+
*/
|
19
|
+
size_t
|
20
|
+
PQescapeString(char *to, const char *from, size_t length)
|
21
|
+
{
|
22
|
+
const char *source = from;
|
23
|
+
char *target = to;
|
24
|
+
size_t remaining = length;
|
25
|
+
|
26
|
+
while (remaining > 0 && *source != '\0')
|
27
|
+
{
|
28
|
+
switch (*source)
|
29
|
+
{
|
30
|
+
case '\\':
|
31
|
+
*target++ = '\\';
|
32
|
+
*target++ = '\\';
|
33
|
+
break;
|
34
|
+
|
35
|
+
case '\'':
|
36
|
+
*target++ = '\'';
|
37
|
+
*target++ = '\'';
|
38
|
+
break;
|
39
|
+
|
40
|
+
default:
|
41
|
+
*target++ = *source;
|
42
|
+
break;
|
43
|
+
}
|
44
|
+
source++;
|
45
|
+
remaining--;
|
46
|
+
}
|
47
|
+
|
48
|
+
/* Write the terminating NUL character. */
|
49
|
+
*target = '\0';
|
50
|
+
|
51
|
+
return target - to;
|
52
|
+
}
|
53
|
+
|
54
|
+
/*
|
55
|
+
* PQescapeBytea - converts from binary string to the
|
56
|
+
* minimal encoding necessary to include the string in an SQL
|
57
|
+
* INSERT statement with a bytea type column as the target.
|
58
|
+
*
|
59
|
+
* The following transformations are applied
|
60
|
+
* '\0' == ASCII 0 == \\000
|
61
|
+
* '\'' == ASCII 39 == \'
|
62
|
+
* '\\' == ASCII 92 == \\\\
|
63
|
+
* anything < 0x20, or > 0x7e ---> \\ooo
|
64
|
+
* (where ooo is an octal expression)
|
65
|
+
*/
|
66
|
+
unsigned char *
|
67
|
+
PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
|
68
|
+
{
|
69
|
+
const unsigned char *vp;
|
70
|
+
unsigned char *rp;
|
71
|
+
unsigned char *result;
|
72
|
+
size_t i;
|
73
|
+
size_t len;
|
74
|
+
|
75
|
+
/*
|
76
|
+
* empty string has 1 char ('\0')
|
77
|
+
*/
|
78
|
+
len = 1;
|
79
|
+
|
80
|
+
vp = bintext;
|
81
|
+
for (i = binlen; i > 0; i--, vp++)
|
82
|
+
{
|
83
|
+
if (*vp < 0x20 || *vp > 0x7e)
|
84
|
+
len += 5; /* '5' is for '\\ooo' */
|
85
|
+
else if (*vp == '\'')
|
86
|
+
len += 2;
|
87
|
+
else if (*vp == '\\')
|
88
|
+
len += 4;
|
89
|
+
else
|
90
|
+
len++;
|
91
|
+
}
|
92
|
+
|
93
|
+
rp = result = (unsigned char *) malloc(len);
|
94
|
+
if (rp == NULL)
|
95
|
+
return NULL;
|
96
|
+
|
97
|
+
vp = bintext;
|
98
|
+
*bytealen = len;
|
99
|
+
|
100
|
+
for (i = binlen; i > 0; i--, vp++)
|
101
|
+
{
|
102
|
+
if (*vp < 0x20 || *vp > 0x7e)
|
103
|
+
{
|
104
|
+
(void) sprintf(rp, "\\\\%03o", *vp);
|
105
|
+
rp += 5;
|
106
|
+
}
|
107
|
+
else if (*vp == '\'')
|
108
|
+
{
|
109
|
+
rp[0] = '\\';
|
110
|
+
rp[1] = '\'';
|
111
|
+
rp += 2;
|
112
|
+
}
|
113
|
+
else if (*vp == '\\')
|
114
|
+
{
|
115
|
+
rp[0] = '\\';
|
116
|
+
rp[1] = '\\';
|
117
|
+
rp[2] = '\\';
|
118
|
+
rp[3] = '\\';
|
119
|
+
rp += 4;
|
120
|
+
}
|
121
|
+
else
|
122
|
+
*rp++ = *vp;
|
123
|
+
}
|
124
|
+
*rp = '\0';
|
125
|
+
|
126
|
+
return result;
|
127
|
+
}
|
128
|
+
|
129
|
+
#define ISFIRSTOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '3')
|
130
|
+
#define ISOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '7')
|
131
|
+
#define OCTVAL(CH) ((CH) - '0')
|
132
|
+
|
133
|
+
/*
|
134
|
+
* PQunescapeBytea - converts the null terminated string representation
|
135
|
+
* of a bytea, strtext, into binary, filling a buffer. It returns a
|
136
|
+
* pointer to the buffer (or NULL on error), and the size of the
|
137
|
+
* buffer in retbuflen. The pointer may subsequently be used as an
|
138
|
+
* argument to the function free(3). It is the reverse of PQescapeBytea.
|
139
|
+
*
|
140
|
+
* The following transformations are made:
|
141
|
+
* \\ == ASCII 92 == \
|
142
|
+
* \ooo == a byte whose value = ooo (ooo is an octal number)
|
143
|
+
* \x == x (x is any character not matched by the above transformations)
|
144
|
+
*/
|
145
|
+
unsigned char *
|
146
|
+
PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
|
147
|
+
{
|
148
|
+
size_t strtextlen,
|
149
|
+
buflen;
|
150
|
+
unsigned char *buffer,
|
151
|
+
*tmpbuf;
|
152
|
+
size_t i,
|
153
|
+
j;
|
154
|
+
|
155
|
+
if (strtext == NULL)
|
156
|
+
return NULL;
|
157
|
+
|
158
|
+
strtextlen = strlen(strtext);
|
159
|
+
|
160
|
+
/*
|
161
|
+
* Length of input is max length of output, but add one to avoid
|
162
|
+
* unportable malloc(0) if input is zero-length.
|
163
|
+
*/
|
164
|
+
buffer = (unsigned char *) malloc(strtextlen + 1);
|
165
|
+
if (buffer == NULL)
|
166
|
+
return NULL;
|
167
|
+
|
168
|
+
for (i = j = 0; i < strtextlen;)
|
169
|
+
{
|
170
|
+
switch (strtext[i])
|
171
|
+
{
|
172
|
+
case '\\':
|
173
|
+
i++;
|
174
|
+
if (strtext[i] == '\\')
|
175
|
+
buffer[j++] = strtext[i++];
|
176
|
+
else
|
177
|
+
{
|
178
|
+
if ((ISFIRSTOCTDIGIT(strtext[i])) &&
|
179
|
+
(ISOCTDIGIT(strtext[i + 1])) &&
|
180
|
+
(ISOCTDIGIT(strtext[i + 2])))
|
181
|
+
{
|
182
|
+
int byte;
|
183
|
+
|
184
|
+
byte = OCTVAL(strtext[i++]);
|
185
|
+
byte = (byte << 3) + OCTVAL(strtext[i++]);
|
186
|
+
byte = (byte << 3) + OCTVAL(strtext[i++]);
|
187
|
+
buffer[j++] = byte;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
/*
|
192
|
+
* Note: if we see '\' followed by something that isn't a
|
193
|
+
* recognized escape sequence, we loop around having done
|
194
|
+
* nothing except advance i. Therefore the something will
|
195
|
+
* be emitted as ordinary data on the next cycle. Corner
|
196
|
+
* case: '\' at end of string will just be discarded.
|
197
|
+
*/
|
198
|
+
break;
|
199
|
+
|
200
|
+
default:
|
201
|
+
buffer[j++] = strtext[i++];
|
202
|
+
break;
|
203
|
+
}
|
204
|
+
}
|
205
|
+
buflen = j; /* buflen is the length of the dequoted
|
206
|
+
* data */
|
207
|
+
|
208
|
+
/* Shrink the buffer to be no larger than necessary */
|
209
|
+
/* +1 avoids unportable behavior when buflen==0 */
|
210
|
+
tmpbuf = realloc(buffer, buflen + 1);
|
211
|
+
|
212
|
+
/* It would only be a very brain-dead realloc that could fail, but... */
|
213
|
+
if (!tmpbuf)
|
214
|
+
{
|
215
|
+
free(buffer);
|
216
|
+
return NULL;
|
217
|
+
}
|
218
|
+
|
219
|
+
*retbuflen = buflen;
|
220
|
+
return tmpbuf;
|
221
|
+
}
|
222
|
+
#endif
|
223
|
+
|
224
|
+
#ifndef HAVE_PQEXECPARAMS
|
225
|
+
#include <ruby.h>
|
226
|
+
#include <re.h>
|
227
|
+
#include <libpq-fe.h>
|
228
|
+
|
229
|
+
#define BIND_PARAM_PATTERN "\\$(\\d+)"
|
230
|
+
#define BindParamNumber(match) (FIX2INT(rb_str_to_inum(rb_reg_nth_match(1, match), 10, 0))-1)
|
231
|
+
|
232
|
+
PGresult *PQexecParams_compat(PGconn *conn, VALUE command, VALUE values)
|
233
|
+
{
|
234
|
+
VALUE bind_param_re = rb_reg_new(BIND_PARAM_PATTERN, 7, 0);
|
235
|
+
VALUE result = rb_str_buf_new(RSTRING(command)->len);
|
236
|
+
char* ptr = RSTRING(command)->ptr;
|
237
|
+
int scan = 0;
|
238
|
+
while ((scan = rb_reg_search(bind_param_re, command, scan, 0)) > 0) {
|
239
|
+
VALUE match = rb_backref_get();
|
240
|
+
int pos = BindParamNumber(match);
|
241
|
+
if (pos < RARRAY(values)->len) {
|
242
|
+
rb_str_buf_cat(result, ptr, scan - (ptr - RSTRING(command)->ptr));
|
243
|
+
ptr = RSTRING(command)->ptr + scan;
|
244
|
+
rb_str_buf_append(result, RARRAY(values)->ptr[pos]);
|
245
|
+
}
|
246
|
+
scan += RSTRING(rb_reg_nth_match(0, match))->len;
|
247
|
+
ptr += RSTRING(rb_reg_nth_match(0, match))->len;
|
248
|
+
}
|
249
|
+
rb_str_buf_cat(result, ptr, RSTRING(command)->len - (ptr - RSTRING(command)->ptr));
|
250
|
+
|
251
|
+
return PQexec(conn, StringValuePtr(result));
|
252
|
+
}
|
253
|
+
#endif
|