postgres 0.7.9.2008.01.03 → 0.7.9.2008.01.09
Sign up to get free protection for your applications and to get access to all the features.
- data/README +45 -17
- data/ext/extconf.rb +7 -24
- data/{compat-ruby-postgres → ext}/libpq-compat.c +0 -0
- data/{compat-ruby-postgres → ext}/postgres.c +10 -18
- data/{compat-ruby-postgres → ext}/type-oids.h +0 -0
- metadata +7 -12
- data/compat-ruby-postgres/extconf.rb +0 -34
- data/ext/compat.c +0 -485
- data/ext/compat.h +0 -130
- data/ext/pg.c +0 -3016
- data/ext/pg.h +0 -13
data/ext/compat.c
DELETED
@@ -1,485 +0,0 @@
|
|
1
|
-
/************************************************
|
2
|
-
|
3
|
-
compat.c -
|
4
|
-
|
5
|
-
Author: matz
|
6
|
-
created at: Tue May 13 20:07:35 JST 1997
|
7
|
-
|
8
|
-
Author: ematsu
|
9
|
-
modified at: Wed Jan 20 16:41:51 1999
|
10
|
-
|
11
|
-
$Author: jdavis $
|
12
|
-
$Date: 2007-12-04 14:25:44 -0800 (Tue, 04 Dec 2007) $
|
13
|
-
************************************************/
|
14
|
-
|
15
|
-
#include "compat.h"
|
16
|
-
|
17
|
-
#ifndef HAVE_PQDESCRIBEPREPARED
|
18
|
-
PGresult *
|
19
|
-
PQdescribePrepared(PGconn *conn, const char *stmtName)
|
20
|
-
{
|
21
|
-
rb_raise(rb_eStandardError, "PQdescribePrepared not supported by this client version.");
|
22
|
-
}
|
23
|
-
#endif /* HAVE_PQDESCRIBEPREPARED */
|
24
|
-
|
25
|
-
#ifndef HAVE_PQDESCRIBEPORTAL
|
26
|
-
PGresult *
|
27
|
-
PQdescribePortal(PGconn *conn, const char *portalName)
|
28
|
-
{
|
29
|
-
rb_raise(rb_eStandardError, "PQdescribePortal not supported by this client version.");
|
30
|
-
}
|
31
|
-
#endif /* HAVE_PQDESCRIBEPORTAL */
|
32
|
-
|
33
|
-
#ifndef HAVE_PQESCAPESTRINGCONN
|
34
|
-
size_t
|
35
|
-
PQescapeStringConn(PGconn *conn, char *to, const char *from,
|
36
|
-
size_t length, int *error)
|
37
|
-
{
|
38
|
-
return PQescapeString(to,from,length);
|
39
|
-
}
|
40
|
-
|
41
|
-
unsigned char *
|
42
|
-
PQescapeByteaConn(PGconn *conn, const unsigned char *from,
|
43
|
-
size_t from_length, size_t *to_length)
|
44
|
-
{
|
45
|
-
return PQescapeBytea(from, from_length, to_length);
|
46
|
-
}
|
47
|
-
#endif /* HAVE_PQESCAPESTRINGCONN */
|
48
|
-
|
49
|
-
#ifndef HAVE_PQPREPARE
|
50
|
-
PGresult *
|
51
|
-
PQprepare(PGconn *conn, const char *stmtName, const char *query,
|
52
|
-
int nParams, const Oid *paramTypes)
|
53
|
-
{
|
54
|
-
rb_raise(rb_eStandardError, "PQprepare not supported by this client version.");
|
55
|
-
}
|
56
|
-
#endif /* HAVE_PQPREPARE */
|
57
|
-
|
58
|
-
#ifndef HAVE_PQCONNECTIONUSEDPASSWORD
|
59
|
-
int
|
60
|
-
PQconnectionUsedPassword(PGconn *conn)
|
61
|
-
{
|
62
|
-
rb_raise(rb_eStandardError,
|
63
|
-
"PQconnectionUsedPassword not supported by this client version.");
|
64
|
-
}
|
65
|
-
#endif /* HAVE_PQCONNECTIONUSEDPASSWORD */
|
66
|
-
|
67
|
-
#ifndef HAVE_PQISTHREADSAFE
|
68
|
-
int
|
69
|
-
PQisthreadsafe()
|
70
|
-
{
|
71
|
-
return Qfalse;
|
72
|
-
}
|
73
|
-
#endif /* HAVE_PQISTHREADSAFE */
|
74
|
-
|
75
|
-
#ifndef HAVE_LO_TRUNCATE
|
76
|
-
int
|
77
|
-
lo_truncate(PGconn *conn, int fd, size_t len)
|
78
|
-
{
|
79
|
-
rb_raise(rb_eStandardError, "lo_truncate not supported by this client version.");
|
80
|
-
}
|
81
|
-
#endif /* HAVE_LO_TRUNCATE */
|
82
|
-
|
83
|
-
#ifndef HAVE_LO_CREATE
|
84
|
-
Oid
|
85
|
-
lo_create(PGconn *conn, Oid lobjId)
|
86
|
-
{
|
87
|
-
rb_raise(rb_eStandardError, "lo_create not supported by this client version.");
|
88
|
-
}
|
89
|
-
#endif /* HAVE_LO_CREATE */
|
90
|
-
|
91
|
-
#ifndef HAVE_PQNPARAMS
|
92
|
-
int
|
93
|
-
PQnparams(const PGresult *res)
|
94
|
-
{
|
95
|
-
rb_raise(rb_eStandardError, "PQnparams not supported by this client version.");
|
96
|
-
}
|
97
|
-
#endif /* HAVE_PQNPARAMS */
|
98
|
-
|
99
|
-
#ifndef HAVE_PQPARAMTYPE
|
100
|
-
Oid
|
101
|
-
PQparamtype(const PGresult *res, int param_number)
|
102
|
-
{
|
103
|
-
rb_raise(rb_eStandardError, "PQparamtype not supported by this client version.");
|
104
|
-
}
|
105
|
-
#endif /* HAVE_PQPARAMTYPE */
|
106
|
-
|
107
|
-
#ifndef HAVE_PQSERVERVERSION
|
108
|
-
int
|
109
|
-
PQserverVersion(const PGconn* conn)
|
110
|
-
{
|
111
|
-
rb_raise(rb_eStandardError, "PQserverVersion not supported by this client version.");
|
112
|
-
}
|
113
|
-
#endif /* HAVE_PQSERVERVERSION */
|
114
|
-
|
115
|
-
#ifndef HAVE_PQSENDDESCRIBEPREPARED
|
116
|
-
int
|
117
|
-
PQsendDescribePrepared(PGconn *conn, const char *stmtName)
|
118
|
-
{
|
119
|
-
rb_raise(rb_eStandardError, "PQsendDescribePrepared not supported by this client version.");
|
120
|
-
}
|
121
|
-
#endif /* HAVE_PQSENDDESCRIBEPREPARED */
|
122
|
-
|
123
|
-
#ifndef HAVE_PQSENDDESCRIBEPORTAL
|
124
|
-
int
|
125
|
-
PQsendDescribePortal(PGconn *conn, const char *portalName)
|
126
|
-
{
|
127
|
-
rb_raise(rb_eStandardError, "PQsendDescribePortal not supported by this client version.");
|
128
|
-
}
|
129
|
-
#endif /* HAVE_PQSENDDESCRIBEPORTAL */
|
130
|
-
|
131
|
-
#ifndef HAVE_PQSENDPREPARE
|
132
|
-
int
|
133
|
-
PQsendPrepare(PGconn *conn, const char *stmtName, const char *query,
|
134
|
-
int nParams, const Oid *paramTypes)
|
135
|
-
{
|
136
|
-
rb_raise(rb_eStandardError, "PQsendPrepare not supported by this client version.");
|
137
|
-
}
|
138
|
-
#endif /* HAVE_PQSENDPREPARE */
|
139
|
-
|
140
|
-
#ifndef HAVE_PQENCRYPTPASSWORD
|
141
|
-
char *
|
142
|
-
PQencryptPassword(const char *passwd, const char *user)
|
143
|
-
{
|
144
|
-
rb_raise(rb_eStandardError, "PQencryptPassword not supported by this client version.");
|
145
|
-
}
|
146
|
-
#endif /* HAVE_PQENCRYPTPASSWORD */
|
147
|
-
|
148
|
-
#ifndef HAVE_PQEXECPARAMS
|
149
|
-
PGresult *
|
150
|
-
PQexecParams(PGconn *conn, const char *command, int nParams,
|
151
|
-
const Oid *paramTypes, const char * const * paramValues, const int *paramLengths,
|
152
|
-
const int *paramFormats, int resultFormat)
|
153
|
-
{
|
154
|
-
rb_raise(rb_eStandardError, "PQexecParams not supported by this client version.");
|
155
|
-
}
|
156
|
-
|
157
|
-
#define BIND_PARAM_PATTERN "\\$(\\d+)"
|
158
|
-
#include <ruby.h>
|
159
|
-
#include <re.h>
|
160
|
-
PGresult *
|
161
|
-
PQexecParams_compat(PGconn *conn, VALUE command, VALUE values)
|
162
|
-
{
|
163
|
-
VALUE bind_param_re = rb_reg_new(BIND_PARAM_PATTERN, 7, 0);
|
164
|
-
VALUE result = rb_str_buf_new(RSTRING(command)->len);
|
165
|
-
char* ptr = RSTRING(command)->ptr;
|
166
|
-
int scan = 0;
|
167
|
-
while ((scan = rb_reg_search(bind_param_re, command, scan, 0)) > 0) {
|
168
|
-
VALUE match = rb_backref_get();
|
169
|
-
int pos = BindParamNumber(match);
|
170
|
-
if (pos < RARRAY(values)->len) {
|
171
|
-
rb_str_buf_cat(result, ptr, scan - (ptr - RSTRING(command)->ptr));
|
172
|
-
ptr = RSTRING(command)->ptr + scan;
|
173
|
-
rb_str_buf_append(result, RARRAY(values)->ptr[pos]);
|
174
|
-
}
|
175
|
-
scan += RSTRING(rb_reg_nth_match(0, match))->len;
|
176
|
-
ptr += RSTRING(rb_reg_nth_match(0, match))->len;
|
177
|
-
}
|
178
|
-
rb_str_buf_cat(result, ptr, RSTRING(command)->len - (ptr - RSTRING(command)->ptr));
|
179
|
-
|
180
|
-
return PQexec(conn, StringValuePtr(result));
|
181
|
-
}
|
182
|
-
#endif /* HAVE_PQEXECPARAMS */
|
183
|
-
|
184
|
-
|
185
|
-
/**************************************************************************
|
186
|
-
|
187
|
-
IF ANY CODE IS COPIED FROM POSTGRESQL, PLACE IT AFTER THIS COMMENT.
|
188
|
-
THE BSD LICENSE REQUIRES THAT YOU MAINTAIN THIS COPYRIGHT NOTICE.
|
189
|
-
|
190
|
-
***************************************************************************
|
191
|
-
|
192
|
-
Portions of code after this point were copied from the PostgreSQL source
|
193
|
-
distribution, available at http://www.postgresql.org
|
194
|
-
|
195
|
-
***************************************************************************
|
196
|
-
|
197
|
-
Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
198
|
-
|
199
|
-
Portions Copyright (c) 1994, The Regents of the University of California
|
200
|
-
|
201
|
-
Permission to use, copy, modify, and distribute this software and its
|
202
|
-
documentation for any purpose, without fee, and without a written agreement
|
203
|
-
is hereby granted, provided that the above copyright notice and this
|
204
|
-
paragraph and the following two paragraphs appear in all copies.
|
205
|
-
|
206
|
-
IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
|
207
|
-
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
|
208
|
-
LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
|
209
|
-
DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
|
210
|
-
POSSIBILITY OF SUCH DAMAGE.
|
211
|
-
|
212
|
-
THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
213
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
214
|
-
AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
215
|
-
ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
|
216
|
-
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
217
|
-
|
218
|
-
**************************************************************************/
|
219
|
-
|
220
|
-
#ifndef HAVE_PQSETCLIENTENCODING
|
221
|
-
|
222
|
-
int
|
223
|
-
PQsetClientEncoding(PGconn *conn, const char *encoding)
|
224
|
-
{
|
225
|
-
char qbuf[128];
|
226
|
-
static const char query[] = "set client_encoding to '%s'";
|
227
|
-
PGresult *res;
|
228
|
-
int status;
|
229
|
-
|
230
|
-
if (!conn || conn->status != CONNECTION_OK)
|
231
|
-
return -1;
|
232
|
-
|
233
|
-
if (!encoding)
|
234
|
-
return -1;
|
235
|
-
|
236
|
-
/* check query buffer overflow */
|
237
|
-
if (sizeof(qbuf) < (sizeof(query) + strlen(encoding)))
|
238
|
-
return -1;
|
239
|
-
|
240
|
-
/* ok, now send a query */
|
241
|
-
sprintf(qbuf, query, encoding);
|
242
|
-
res = PQexec(conn, qbuf);
|
243
|
-
|
244
|
-
if (res == NULL)
|
245
|
-
return -1;
|
246
|
-
if (res->resultStatus != PGRES_COMMAND_OK)
|
247
|
-
status = -1;
|
248
|
-
else
|
249
|
-
{
|
250
|
-
/*
|
251
|
-
* In protocol 2 we have to assume the setting will stick, and adjust
|
252
|
-
* our state immediately. In protocol 3 and up we can rely on the
|
253
|
-
* backend to report the parameter value, and we'll change state at
|
254
|
-
* that time.
|
255
|
-
*/
|
256
|
-
if (PG_PROTOCOL_MAJOR(conn->pversion) < 3)
|
257
|
-
pqSaveParameterStatus(conn, "client_encoding", encoding);
|
258
|
-
status = 0; /* everything is ok */
|
259
|
-
}
|
260
|
-
PQclear(res);
|
261
|
-
return status;
|
262
|
-
}
|
263
|
-
#endif /* HAVE_PQSETCLIENTENCODING */
|
264
|
-
|
265
|
-
#ifndef HAVE_PQESCAPESTRING
|
266
|
-
/*
|
267
|
-
* Escaping arbitrary strings to get valid SQL literal strings.
|
268
|
-
*
|
269
|
-
* Replaces "\\" with "\\\\" and "'" with "''".
|
270
|
-
*
|
271
|
-
* length is the length of the source string. (Note: if a terminating NUL
|
272
|
-
* is encountered sooner, PQescapeString stops short of "length"; the behavior
|
273
|
-
* is thus rather like strncpy.)
|
274
|
-
*
|
275
|
-
* For safety the buffer at "to" must be at least 2*length + 1 bytes long.
|
276
|
-
* A terminating NUL character is added to the output string, whether the
|
277
|
-
* input is NUL-terminated or not.
|
278
|
-
*
|
279
|
-
* Returns the actual length of the output (not counting the terminating NUL).
|
280
|
-
*/
|
281
|
-
size_t
|
282
|
-
PQescapeString(char *to, const char *from, size_t length)
|
283
|
-
{
|
284
|
-
const char *source = from;
|
285
|
-
char *target = to;
|
286
|
-
size_t remaining = length;
|
287
|
-
|
288
|
-
while (remaining > 0 && *source != '\0')
|
289
|
-
{
|
290
|
-
switch (*source)
|
291
|
-
{
|
292
|
-
case '\\':
|
293
|
-
*target++ = '\\';
|
294
|
-
*target++ = '\\';
|
295
|
-
break;
|
296
|
-
|
297
|
-
case '\'':
|
298
|
-
*target++ = '\'';
|
299
|
-
*target++ = '\'';
|
300
|
-
break;
|
301
|
-
|
302
|
-
default:
|
303
|
-
*target++ = *source;
|
304
|
-
break;
|
305
|
-
}
|
306
|
-
source++;
|
307
|
-
remaining--;
|
308
|
-
}
|
309
|
-
|
310
|
-
/* Write the terminating NUL character. */
|
311
|
-
*target = '\0';
|
312
|
-
|
313
|
-
return target - to;
|
314
|
-
}
|
315
|
-
|
316
|
-
/*
|
317
|
-
* PQescapeBytea - converts from binary string to the
|
318
|
-
* minimal encoding necessary to include the string in an SQL
|
319
|
-
* INSERT statement with a bytea type column as the target.
|
320
|
-
*
|
321
|
-
* The following transformations are applied
|
322
|
-
* '\0' == ASCII 0 == \\000
|
323
|
-
* '\'' == ASCII 39 == \'
|
324
|
-
* '\\' == ASCII 92 == \\\\
|
325
|
-
* anything < 0x20, or > 0x7e ---> \\ooo
|
326
|
-
* (where ooo is an octal expression)
|
327
|
-
*/
|
328
|
-
unsigned char *
|
329
|
-
PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
|
330
|
-
{
|
331
|
-
const unsigned char *vp;
|
332
|
-
unsigned char *rp;
|
333
|
-
unsigned char *result;
|
334
|
-
size_t i;
|
335
|
-
size_t len;
|
336
|
-
|
337
|
-
/*
|
338
|
-
* empty string has 1 char ('\0')
|
339
|
-
*/
|
340
|
-
len = 1;
|
341
|
-
|
342
|
-
vp = bintext;
|
343
|
-
for (i = binlen; i > 0; i--, vp++)
|
344
|
-
{
|
345
|
-
if (*vp < 0x20 || *vp > 0x7e)
|
346
|
-
len += 5; /* '5' is for '\\ooo' */
|
347
|
-
else if (*vp == '\'')
|
348
|
-
len += 2;
|
349
|
-
else if (*vp == '\\')
|
350
|
-
len += 4;
|
351
|
-
else
|
352
|
-
len++;
|
353
|
-
}
|
354
|
-
|
355
|
-
rp = result = (unsigned char *) malloc(len);
|
356
|
-
if (rp == NULL)
|
357
|
-
return NULL;
|
358
|
-
|
359
|
-
vp = bintext;
|
360
|
-
*bytealen = len;
|
361
|
-
|
362
|
-
for (i = binlen; i > 0; i--, vp++)
|
363
|
-
{
|
364
|
-
if (*vp < 0x20 || *vp > 0x7e)
|
365
|
-
{
|
366
|
-
(void) sprintf(rp, "\\\\%03o", *vp);
|
367
|
-
rp += 5;
|
368
|
-
}
|
369
|
-
else if (*vp == '\'')
|
370
|
-
{
|
371
|
-
rp[0] = '\\';
|
372
|
-
rp[1] = '\'';
|
373
|
-
rp += 2;
|
374
|
-
}
|
375
|
-
else if (*vp == '\\')
|
376
|
-
{
|
377
|
-
rp[0] = '\\';
|
378
|
-
rp[1] = '\\';
|
379
|
-
rp[2] = '\\';
|
380
|
-
rp[3] = '\\';
|
381
|
-
rp += 4;
|
382
|
-
}
|
383
|
-
else
|
384
|
-
*rp++ = *vp;
|
385
|
-
}
|
386
|
-
*rp = '\0';
|
387
|
-
|
388
|
-
return result;
|
389
|
-
}
|
390
|
-
|
391
|
-
#define ISFIRSTOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '3')
|
392
|
-
#define ISOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '7')
|
393
|
-
#define OCTVAL(CH) ((CH) - '0')
|
394
|
-
|
395
|
-
/*
|
396
|
-
* PQunescapeBytea - converts the null terminated string representation
|
397
|
-
* of a bytea, strtext, into binary, filling a buffer. It returns a
|
398
|
-
* pointer to the buffer (or NULL on error), and the size of the
|
399
|
-
* buffer in retbuflen. The pointer may subsequently be used as an
|
400
|
-
* argument to the function free(3). It is the reverse of PQescapeBytea.
|
401
|
-
*
|
402
|
-
* The following transformations are made:
|
403
|
-
* \\ == ASCII 92 == \
|
404
|
-
* \ooo == a byte whose value = ooo (ooo is an octal number)
|
405
|
-
* \x == x (x is any character not matched by the above transformations)
|
406
|
-
*/
|
407
|
-
unsigned char *
|
408
|
-
PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
|
409
|
-
{
|
410
|
-
size_t strtextlen,
|
411
|
-
buflen;
|
412
|
-
unsigned char *buffer,
|
413
|
-
*tmpbuf;
|
414
|
-
size_t i,
|
415
|
-
j;
|
416
|
-
|
417
|
-
if (strtext == NULL)
|
418
|
-
return NULL;
|
419
|
-
|
420
|
-
strtextlen = strlen(strtext);
|
421
|
-
|
422
|
-
/*
|
423
|
-
* Length of input is max length of output, but add one to avoid
|
424
|
-
* unportable malloc(0) if input is zero-length.
|
425
|
-
*/
|
426
|
-
buffer = (unsigned char *) malloc(strtextlen + 1);
|
427
|
-
if (buffer == NULL)
|
428
|
-
return NULL;
|
429
|
-
|
430
|
-
for (i = j = 0; i < strtextlen;)
|
431
|
-
{
|
432
|
-
switch (strtext[i])
|
433
|
-
{
|
434
|
-
case '\\':
|
435
|
-
i++;
|
436
|
-
if (strtext[i] == '\\')
|
437
|
-
buffer[j++] = strtext[i++];
|
438
|
-
else
|
439
|
-
{
|
440
|
-
if ((ISFIRSTOCTDIGIT(strtext[i])) &&
|
441
|
-
(ISOCTDIGIT(strtext[i + 1])) &&
|
442
|
-
(ISOCTDIGIT(strtext[i + 2])))
|
443
|
-
{
|
444
|
-
int byte;
|
445
|
-
|
446
|
-
byte = OCTVAL(strtext[i++]);
|
447
|
-
byte = (byte << 3) + OCTVAL(strtext[i++]);
|
448
|
-
byte = (byte << 3) + OCTVAL(strtext[i++]);
|
449
|
-
buffer[j++] = byte;
|
450
|
-
}
|
451
|
-
}
|
452
|
-
|
453
|
-
/*
|
454
|
-
* Note: if we see '\' followed by something that isn't a
|
455
|
-
* recognized escape sequence, we loop around having done
|
456
|
-
* nothing except advance i. Therefore the something will
|
457
|
-
* be emitted as ordinary data on the next cycle. Corner
|
458
|
-
* case: '\' at end of string will just be discarded.
|
459
|
-
*/
|
460
|
-
break;
|
461
|
-
|
462
|
-
default:
|
463
|
-
buffer[j++] = strtext[i++];
|
464
|
-
break;
|
465
|
-
}
|
466
|
-
}
|
467
|
-
buflen = j; /* buflen is the length of the dequoted
|
468
|
-
* data */
|
469
|
-
|
470
|
-
/* Shrink the buffer to be no larger than necessary */
|
471
|
-
/* +1 avoids unportable behavior when buflen==0 */
|
472
|
-
tmpbuf = realloc(buffer, buflen + 1);
|
473
|
-
|
474
|
-
/* It would only be a very brain-dead realloc that could fail, but... */
|
475
|
-
if (!tmpbuf)
|
476
|
-
{
|
477
|
-
free(buffer);
|
478
|
-
return NULL;
|
479
|
-
}
|
480
|
-
|
481
|
-
*retbuflen = buflen;
|
482
|
-
return tmpbuf;
|
483
|
-
}
|
484
|
-
#endif
|
485
|
-
|
data/ext/compat.h
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
|
2
|
-
#ifndef __compat_h
|
3
|
-
#define __compat_h
|
4
|
-
|
5
|
-
#include <stdlib.h>
|
6
|
-
|
7
|
-
#include "ruby.h"
|
8
|
-
#include "rubyio.h"
|
9
|
-
#include "libpq-fe.h"
|
10
|
-
#include "libpq/libpq-fs.h" /* large-object interface */
|
11
|
-
|
12
|
-
#if RUBY_VERSION_CODE < 180
|
13
|
-
#define rb_check_string_type(x) rb_check_convert_type(x, T_STRING, "String", "to_str")
|
14
|
-
#endif /* RUBY_VERSION_CODE < 180 */
|
15
|
-
|
16
|
-
#ifndef RARRAY_LEN
|
17
|
-
#define RARRAY_LEN(x) RARRAY((x))->len
|
18
|
-
#endif /* RARRAY_LEN */
|
19
|
-
|
20
|
-
#ifndef RSTRING_LEN
|
21
|
-
#define RSTRING_LEN(x) RSTRING((x))->len
|
22
|
-
#endif /* RSTRING_LEN */
|
23
|
-
|
24
|
-
#ifndef RSTRING_PTR
|
25
|
-
#define RSTRING_PTR(x) RSTRING((x))->ptr
|
26
|
-
#endif /* RSTRING_PTR */
|
27
|
-
|
28
|
-
#ifndef StringValuePtr
|
29
|
-
#define StringValuePtr(x) STR2CSTR(x)
|
30
|
-
#endif /* StringValuePtr */
|
31
|
-
|
32
|
-
#ifndef HAVE_PG_ENCODING_TO_CHAR
|
33
|
-
#define pg_encoding_to_char(x) "SQL_ASCII"
|
34
|
-
#endif /* HAVE_PG_ENCODING_TO_CHAR */
|
35
|
-
|
36
|
-
#ifndef PG_DIAG_INTERNAL_POSITION
|
37
|
-
#define PG_DIAG_INTERNAL_POSITION 'p'
|
38
|
-
#endif /* PG_DIAG_INTERNAL_POSITION */
|
39
|
-
|
40
|
-
#ifndef PG_DIAG_INTERNAL_QUERY
|
41
|
-
#define PG_DIAG_INTERNAL_QUERY 'q'
|
42
|
-
#endif /* PG_DIAG_INTERNAL_QUERY */
|
43
|
-
|
44
|
-
#ifndef HAVE_PQFREEMEM
|
45
|
-
#define PQfreemem(ptr) free(ptr)
|
46
|
-
#endif /* HAVE_PQFREEMEM */
|
47
|
-
|
48
|
-
#ifndef HAVE_PQSETCLIENTENCODING
|
49
|
-
int PQsetClientEncoding(PGconn *conn, const char *encoding)
|
50
|
-
#endif /* HAVE_PQSETCLIENTENCODING */
|
51
|
-
|
52
|
-
#ifndef HAVE_PQESCAPESTRING
|
53
|
-
size_t PQescapeString(char *to, const char *from, size_t length);
|
54
|
-
unsigned char * PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen);
|
55
|
-
unsigned char * PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen);
|
56
|
-
#endif /* HAVE_PQESCAPESTRING */
|
57
|
-
|
58
|
-
#ifndef HAVE_PQESCAPESTRINGCONN
|
59
|
-
size_t PQescapeStringConn(PGconn *conn, char *to, const char *from,
|
60
|
-
size_t length, int *error);
|
61
|
-
unsigned char *PQescapeByteaConn(PGconn *conn, const unsigned char *from,
|
62
|
-
size_t from_length, size_t *to_length);
|
63
|
-
#endif /* HAVE_PQESCAPESTRINGCONN */
|
64
|
-
|
65
|
-
#ifndef HAVE_PQPREPARE
|
66
|
-
PGresult *PQprepare(PGconn *conn, const char *stmtName, const char *query,
|
67
|
-
int nParams, const Oid *paramTypes);
|
68
|
-
#endif /* HAVE_PQPREPARE */
|
69
|
-
|
70
|
-
#ifndef HAVE_PQDESCRIBEPREPARED
|
71
|
-
PGresult * PQdescribePrepared(PGconn *conn, const char *stmtName);
|
72
|
-
#endif /* HAVE_PQDESCRIBEPREPARED */
|
73
|
-
|
74
|
-
#ifndef HAVE_PQDESCRIBEPORTAL
|
75
|
-
PGresult * PQdescribePortal(PGconn *conn, const char *portalName);
|
76
|
-
#endif /* HAVE_PQDESCRIBEPORTAL */
|
77
|
-
|
78
|
-
#ifndef HAVE_PQCONNECTIONUSEDPASSWORD
|
79
|
-
int PQconnectionUsedPassword(PGconn *conn);
|
80
|
-
#endif /* HAVE_PQCONNECTIONUSEDPASSWORD */
|
81
|
-
|
82
|
-
#ifndef HAVE_PQISTHREADSAFE
|
83
|
-
int PQisthreadsafe(void);
|
84
|
-
#endif /* HAVE_PQISTHREADSAFE */
|
85
|
-
|
86
|
-
#ifndef HAVE_LO_TRUNCATE
|
87
|
-
int lo_truncate(PGconn *conn, int fd, size_t len);
|
88
|
-
#endif /* HAVE_LO_TRUNCATE */
|
89
|
-
|
90
|
-
#ifndef HAVE_LO_CREATE
|
91
|
-
Oid lo_create(PGconn *conn, Oid lobjId);
|
92
|
-
#endif /* HAVE_LO_CREATE */
|
93
|
-
|
94
|
-
#ifndef HAVE_PQNPARAMS
|
95
|
-
int PQnparams(const PGresult *res);
|
96
|
-
#endif /* HAVE_PQNPARAMS */
|
97
|
-
|
98
|
-
#ifndef HAVE_PQPARAMTYPE
|
99
|
-
Oid PQparamtype(const PGresult *res, int param_number);
|
100
|
-
#endif /* HAVE_PQPARAMTYPE */
|
101
|
-
|
102
|
-
#ifndef HAVE_PQSERVERVERSION
|
103
|
-
int PQserverVersion(const PGconn* conn);
|
104
|
-
#endif /* HAVE_PQSERVERVERSION */
|
105
|
-
|
106
|
-
#ifndef HAVE_PQEXECPARAMS
|
107
|
-
PGresult *PQexecParams(PGconn *conn, const char *command, int nParams,
|
108
|
-
const Oid *paramTypes, const char * const * paramValues, const int *paramLengths,
|
109
|
-
const int *paramFormats, int resultFormat);
|
110
|
-
PGresult *PQexecParams_compat(PGconn *conn, VALUE command, VALUE values);
|
111
|
-
#endif /* HAVE_PQEXECPARAMS */
|
112
|
-
|
113
|
-
#ifndef HAVE_PQSENDDESCRIBEPREPARED
|
114
|
-
int PQsendDescribePrepared(PGconn *conn, const char *stmtName);
|
115
|
-
#endif /* HAVE_PQSENDDESCRIBEPREPARED */
|
116
|
-
|
117
|
-
#ifndef HAVE_PQSENDDESCRIBEPORTAL
|
118
|
-
int PQsendDescribePortal(PGconn *conn, const char *portalName);
|
119
|
-
#endif /* HAVE_PQSENDDESCRIBEPORTAL */
|
120
|
-
|
121
|
-
#ifndef HAVE_PQSENDPREPARE
|
122
|
-
int PQsendPrepare(PGconn *conn, const char *stmtName, const char *query,
|
123
|
-
int nParams, const Oid *paramTypes);
|
124
|
-
#endif /* HAVE_PQSENDPREPARE */
|
125
|
-
|
126
|
-
#ifndef HAVE_PQENCRYPTPASSWORD
|
127
|
-
char *PQencryptPassword(const char *passwd, const char *user);
|
128
|
-
#endif /* HAVE_PQENCRYPTPASSWORD */
|
129
|
-
|
130
|
-
#endif /* __compat_h */
|