Repository navigation
Expand file tree
/
Copy pathDBD-Proxy.3
More file actions
353 lines (353 loc) · 11 KB
/
Copy pathDBD-Proxy.3
File metadata and controls
353 lines (353 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man v6.1.0 (Pod::Simple 3.48)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CR
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "DBD::Proxy 3"
.TH DBD::Proxy 3 2026-07-14 "perl v5.44.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation. String
.\" and register settings are required by groff 1.23.0 and later. Changing
.\" tag separation back to 1n is required by groff 1.24.0 and later.
.if n .ds AD l
.if n .ad l
.nr HY 0
.nh
.SH NAME
DBD::Proxy \- A proxy driver for the DBI
.SH SYNOPSIS
.IX Header "SYNOPSIS"
.Vb 1
\& use DBI;
\&
\& $dbh = DBI\->connect("dbi:Proxy:hostname=$host;port=$port;dsn=$db",
\& $user, $passwd);
\&
\& # See the DBI module documentation for full details
.Ve
.SH DESCRIPTION
.IX Header "DESCRIPTION"
DBD::Proxy is a Perl module for connecting to a database via a remote
DBI driver. See DBD::Gofer for an alternative with different trade\-offs.
.PP
This is of course not needed for DBI drivers which already
support connecting to a remote database, but there are engines which
don\*(Aqt offer network connectivity.
.PP
Another application is offering database access through a firewall, as
the driver offers query based restrictions. For example you can
restrict queries to exactly those that are used in a given CGI
application.
.PP
Speaking of CGI, another application is (or rather, will be) to reduce
the database connect/disconnect overhead from CGI scripts by using
proxying the connect_cached method. The proxy server will hold the
database connections open in a cache. The CGI script then trades the
database connect/disconnect overhead for the DBD::Proxy
connect/disconnect overhead which is typically much less.
.SH "CONNECTING TO THE DATABASE"
.IX Header "CONNECTING TO THE DATABASE"
Before connecting to a remote database, you must ensure, that a Proxy
server is running on the remote machine. There\*(Aqs no default port, so
you have to ask your system administrator for the port number. See
DBI::ProxyServer for details.
.PP
Say, your Proxy server is running on machine "alpha", port 3334, and
you\*(Aqd like to connect to an ODBC database called "mydb" as user "joe"
with password "hello". When using DBD::ODBC directly, you\*(Aqd do a
.PP
.Vb 1
\& $dbh = DBI\->connect("DBI:ODBC:mydb", "joe", "hello");
.Ve
.PP
With DBD::Proxy this becomes
.PP
.Vb 2
\& $dsn = "DBI:Proxy:hostname=alpha;port=3334;dsn=DBI:ODBC:mydb";
\& $dbh = DBI\->connect($dsn, "joe", "hello");
.Ve
.PP
You see, this is mainly the same. The DBD::Proxy module will create a
connection to the Proxy server on "alpha" which in turn will connect
to the ODBC database.
.PP
Refer to the DBI documentation on the \f(CR\*(C`connect\*(C'\fR method for a way
to automatically use DBD::Proxy without having to change your code.
.PP
DBD::Proxy\*(Aqs DSN string has the format
.PP
.Vb 1
\& $dsn = "DBI:Proxy:key1=val1; ... ;keyN=valN;dsn=valDSN";
.Ve
.PP
In other words, it is a collection of key/value pairs. The following
keys are recognized:
.TP 4
hostname
.IX Item "hostname"
.PD 0
.TP 4
port
.IX Item "port"
.PD
Hostname and port of the Proxy server; these keys must be present,
no defaults. Example:
.Sp
.Vb 1
\& hostname=alpha;port=3334
.Ve
.TP 4
dsn
.IX Item "dsn"
The value of this attribute will be used as a dsn name by the Proxy
server. Thus it must have the format \f(CR\*(C`DBI:driver:...\*(C'\fR, in particular
it will contain colons. The \fIdsn\fR value may contain semicolons, hence
this key *must* be the last and it\*(Aqs value will be the complete
remaining part of the dsn. Example:
.Sp
.Vb 1
\& dsn=DBI:ODBC:mydb
.Ve
.TP 4
cipher
.IX Item "cipher"
.PD 0
.TP 4
key
.IX Item "key"
.TP 4
usercipher
.IX Item "usercipher"
.TP 4
userkey
.IX Item "userkey"
.PD
By using these fields you can enable encryption. If you set,
for example,
.Sp
.Vb 1
\& cipher=$class;key=$key
.Ve
.Sp
(note the semicolon) then DBD::Proxy will create a new cipher object
by executing
.Sp
.Vb 1
\& $cipherRef = $class\->new(pack("H*", $key));
.Ve
.Sp
and pass this object to the RPC::PlClient module when creating a
client. See RPC::PlClient. Example:
.Sp
.Vb 1
\& cipher=IDEA;key=97cd2375efa329aceef2098babdc9721
.Ve
.Sp
The usercipher/userkey attributes allow you to use two phase encryption:
The cipher/key encryption will be used in the login and authorisation
phase. Once the client is authorised, he will change to usercipher/userkey
encryption. Thus the cipher/key pair is a \fBhost\fR based secret, typically
less secure than the usercipher/userkey secret and readable by anyone.
The usercipher/userkey secret is \fByour\fR private secret.
.Sp
Of course encryption requires an appropriately configured server. See
"CONFIGURATION FILE" in DBD::ProxyServer.
.TP 4
debug
.IX Item "debug"
Turn on debugging mode
.TP 4
stderr
.IX Item "stderr"
This attribute will set the corresponding attribute of the RPC::PlClient
object, thus logging will not use \fBsyslog()\fR, but redirected to stderr.
This is the default under Windows.
.Sp
.Vb 1
\& stderr=1
.Ve
.TP 4
logfile
.IX Item "logfile"
Similar to the stderr attribute, but output will be redirected to the
given file.
.Sp
.Vb 1
\& logfile=/dev/null
.Ve
.TP 4
RowCacheSize
.IX Item "RowCacheSize"
The DBD::Proxy driver supports this attribute (which is DBI standard,
as of DBI 1.02). It\*(Aqs used to reduce network round\-trips by fetching
multiple rows in one go. The current default value is 20, but this may
change.
.TP 4
proxy_no_finish
.IX Item "proxy_no_finish"
This attribute can be used to reduce network traffic: If the
application is calling \f(CR$sth\fR\->\fBfinish()\fR then the proxy tells the server
to finish the remote statement handle. Of course this slows down things
quite a lot, but is perfectly good for reducing memory usage with
persistent connections.
.Sp
However, if you set the \fIproxy_no_finish\fR attribute to a TRUE value,
either in the database handle or in the statement handle, then \fBfinish()\fR
calls will be suppressed. This is what you want, for example, in small
and fast CGI applications.
.TP 4
proxy_quote
.IX Item "proxy_quote"
This attribute can be used to reduce network traffic: By default calls
to \f(CR$dbh\fR\->\fBquote()\fR are passed to the remote driver. Of course this slows
down things quite a lot, but is the safest default behaviour.
.Sp
However, if you set the \fIproxy_quote\fR attribute to the value \*(Aq\f(CR\*(C`local\*(C'\fR\*(Aq
either in the database handle or in the statement handle, and the call
to quote has only one parameter, then the local default DBI quote
method will be used (which will be faster but may be wrong).
.SH "KNOWN ISSUES"
.IX Header "KNOWN ISSUES"
.SS "Unproxied method calls"
.IX Subsection "Unproxied method calls"
If a method isn\*(Aqt being proxied, try declaring a stub sub in the appropriate
package (DBD::Proxy::db for a dbh method, and DBD::Proxy::st for an sth method).
For example:
.PP
.Vb 1
\& sub DBD::Proxy::db::selectall_arrayref;
.Ve
.PP
That will enable selectall_arrayref to be proxied.
.PP
Currently many methods aren\*(Aqt explicitly proxied and so you get the DBI\*(Aqs
default methods executed on the client.
.PP
Some of those methods, like selectall_arrayref, may then call other methods
that are proxied (selectall_arrayref calls fetchall_arrayref which calls fetch
which is proxied). So things may appear to work but operate more slowly than
the could.
.PP
This may all change in a later version.
.SS "Complex handle attributes"
.IX Subsection "Complex handle attributes"
Sometimes handles are having complex attributes like hash refs or
array refs and not simple strings or integers. For example, with
DBD::CSV, you would like to write something like
.PP
.Vb 2
\& $dbh\->{"csv_tables"}\->{"passwd"} =
\& { "sep_char" => ":", "eol" => "\en";
.Ve
.PP
The above example would advice the CSV driver to assume the file
"passwd" to be in the format of the /etc/passwd file: Colons as
separators and a line feed without carriage return as line
terminator.
.PP
Surprisingly this example doesn\*(Aqt work with the proxy driver. To understand
the reasons, you should consider the following: The Perl compiler is
executing the above example in two steps:
.IP 1. 4
The first step is fetching the value of the key "csv_tables" in the
handle \f(CR$dbh\fR. The value returned is complex, a hash ref.
.IP 2. 4
The second step is storing some value (the right hand side of the
assignment) as the key "passwd" in the hash ref from step 1.
.PP
This becomes a little bit clearer, if we rewrite the above code:
.PP
.Vb 2
\& $tables = $dbh\->{"csv_tables"};
\& $tables\->{"passwd"} = { "sep_char" => ":", "eol" => "\en";
.Ve
.PP
While the examples work fine without the proxy, the fail due to a
subtle difference in step 1: By DBI magic, the hash ref
\&\f(CR$dbh\fR\->{\*(Aqcsv_tables\*(Aq} is returned from the server to the client.
The client creates a local copy. This local copy is the result of
step 1. In other words, step 2 modifies a local copy of the hash ref,
but not the server\*(Aqs hash ref.
.PP
The workaround is storing the modified local copy back to the server:
.PP
.Vb 3
\& $tables = $dbh\->{"csv_tables"};
\& $tables\->{"passwd"} = { "sep_char" => ":", "eol" => "\en";
\& $dbh\->{"csv_tables"} = $tables;
.Ve
.SH "SECURITY WARNING"
.IX Header "SECURITY WARNING"
RPC::PlClient used underneath is not secure due to serializing and
deserializing data with Storable module. Use the proxy driver only in
trusted environment.
.SH "AUTHOR AND COPYRIGHT"
.IX Header "AUTHOR AND COPYRIGHT"
This module is Copyright (c) 1997, 1998
.PP
.Vb 4
\& Jochen Wiedmann
\& Am Eisteich 9
\& 72555 Metzingen
\& Germany
\&
\& Email: joe@ispsoft.de
\& Phone: +49 7123 14887
.Ve
.PP
The DBD::Proxy module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. In particular permission
is granted to Tim Bunce for distributing this as a part of the DBI.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
DBI, RPC::PlClient, Storable