pg 0.12.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +2 -0
  3. data/BSDL +22 -0
  4. data/ChangeLog +1504 -11
  5. data/Contributors.rdoc +7 -0
  6. data/History.rdoc +181 -3
  7. data/LICENSE +12 -14
  8. data/Manifest.txt +29 -15
  9. data/{BSD → POSTGRES} +0 -0
  10. data/{README.OS_X.rdoc → README-OS_X.rdoc} +0 -0
  11. data/{README.windows.rdoc → README-Windows.rdoc} +0 -0
  12. data/README.ja.rdoc +10 -3
  13. data/README.rdoc +54 -28
  14. data/Rakefile +53 -26
  15. data/Rakefile.cross +235 -196
  16. data/ext/errorcodes.def +931 -0
  17. data/ext/errorcodes.rb +45 -0
  18. data/ext/errorcodes.txt +463 -0
  19. data/ext/extconf.rb +37 -7
  20. data/ext/gvl_wrappers.c +19 -0
  21. data/ext/gvl_wrappers.h +211 -0
  22. data/ext/pg.c +317 -4277
  23. data/ext/pg.h +124 -21
  24. data/ext/pg_connection.c +3642 -0
  25. data/ext/pg_errors.c +89 -0
  26. data/ext/pg_result.c +920 -0
  27. data/lib/pg/connection.rb +86 -0
  28. data/lib/pg/constants.rb +11 -0
  29. data/lib/pg/exceptions.rb +11 -0
  30. data/lib/pg/result.rb +16 -0
  31. data/lib/pg.rb +26 -43
  32. data/sample/array_insert.rb +20 -0
  33. data/sample/async_api.rb +21 -24
  34. data/sample/async_copyto.rb +2 -2
  35. data/sample/async_mixed.rb +56 -0
  36. data/sample/check_conn.rb +21 -0
  37. data/sample/copyfrom.rb +1 -1
  38. data/sample/copyto.rb +1 -1
  39. data/sample/cursor.rb +2 -2
  40. data/sample/disk_usage_report.rb +186 -0
  41. data/sample/issue-119.rb +94 -0
  42. data/sample/losample.rb +6 -6
  43. data/sample/minimal-testcase.rb +17 -0
  44. data/sample/notify_wait.rb +51 -22
  45. data/sample/pg_statistics.rb +294 -0
  46. data/sample/replication_monitor.rb +231 -0
  47. data/sample/test_binary_values.rb +4 -6
  48. data/sample/wal_shipper.rb +434 -0
  49. data/sample/warehouse_partitions.rb +320 -0
  50. data/spec/lib/helpers.rb +70 -23
  51. data/spec/pg/connection_spec.rb +1128 -0
  52. data/spec/{pgresult_spec.rb → pg/result_spec.rb} +142 -47
  53. data/spec/pg_spec.rb +44 -0
  54. data.tar.gz.sig +0 -0
  55. metadata +145 -100
  56. metadata.gz.sig +0 -0
  57. data/GPL +0 -340
  58. data/ext/compat.c +0 -541
  59. data/ext/compat.h +0 -184
  60. data/misc/openssl-pg-segfault.rb +0 -31
  61. data/sample/psql.rb +0 -1181
  62. data/sample/psqlHelp.rb +0 -158
  63. data/sample/test1.rb +0 -60
  64. data/sample/test2.rb +0 -44
  65. data/sample/test4.rb +0 -71
  66. data/spec/m17n_spec.rb +0 -151
  67. data/spec/pgconn_spec.rb +0 -643
data/ext/compat.c DELETED
@@ -1,541 +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: ged $
12
- $Date: 2010/10/31 23:29:59 $
13
- ************************************************/
14
-
15
- #include <ctype.h>
16
- #include "compat.h"
17
-
18
- #ifdef PG_BEFORE_080300
19
- int
20
- PQconnectionNeedsPassword(PGconn *conn)
21
- {
22
- rb_raise(rb_eStandardError,
23
- "PQconnectionNeedsPassword not supported by this client version.");
24
- }
25
-
26
- int
27
- PQconnectionUsedPassword(PGconn *conn)
28
- {
29
- rb_raise(rb_eStandardError,
30
- "PQconnectionUsedPassword not supported by this client version.");
31
- }
32
-
33
- int
34
- lo_truncate(PGconn *conn, int fd, size_t len)
35
- {
36
- rb_raise(rb_eStandardError, "lo_truncate not supported by this client version.");
37
- }
38
- #endif /* PG_BEFORE_080300 */
39
-
40
- #ifdef PG_BEFORE_080200
41
- int
42
- PQisthreadsafe()
43
- {
44
- return Qfalse;
45
- }
46
-
47
- int
48
- PQnparams(const PGresult *res)
49
- {
50
- rb_raise(rb_eStandardError, "PQnparams not supported by this client version.");
51
- }
52
-
53
- Oid
54
- PQparamtype(const PGresult *res, int param_number)
55
- {
56
- rb_raise(rb_eStandardError, "PQparamtype not supported by this client version.");
57
- }
58
-
59
- PGresult *
60
- PQdescribePrepared(PGconn *conn, const char *stmtName)
61
- {
62
- rb_raise(rb_eStandardError, "PQdescribePrepared not supported by this client version.");
63
- }
64
-
65
- PGresult *
66
- PQdescribePortal(PGconn *conn, const char *portalName)
67
- {
68
- rb_raise(rb_eStandardError, "PQdescribePortal not supported by this client version.");
69
- }
70
-
71
- int
72
- PQsendDescribePrepared(PGconn *conn, const char *stmtName)
73
- {
74
- rb_raise(rb_eStandardError, "PQsendDescribePrepared not supported by this client version.");
75
- }
76
-
77
- int
78
- PQsendDescribePortal(PGconn *conn, const char *portalName)
79
- {
80
- rb_raise(rb_eStandardError, "PQsendDescribePortal not supported by this client version.");
81
- }
82
-
83
- char *
84
- PQencryptPassword(const char *passwd, const char *user)
85
- {
86
- rb_raise(rb_eStandardError, "PQencryptPassword not supported by this client version.");
87
- }
88
- #endif /* PG_BEFORE_080200 */
89
-
90
- #ifdef PG_BEFORE_080100
91
- Oid
92
- lo_create(PGconn *conn, Oid lobjId)
93
- {
94
- rb_raise(rb_eStandardError, "lo_create not supported by this client version.");
95
- }
96
- #endif /* PG_BEFORE_080100 */
97
-
98
- #ifdef PG_BEFORE_080000
99
- PGresult *
100
- PQprepare(PGconn *conn, const char *stmtName, const char *query,
101
- int nParams, const Oid *paramTypes)
102
- {
103
- rb_raise(rb_eStandardError, "PQprepare not supported by this client version.");
104
- }
105
-
106
- int
107
- PQsendPrepare(PGconn *conn, const char *stmtName, const char *query,
108
- int nParams, const Oid *paramTypes)
109
- {
110
- rb_raise(rb_eStandardError, "PQsendPrepare not supported by this client version.");
111
- }
112
-
113
- int
114
- PQserverVersion(const PGconn* conn)
115
- {
116
- rb_raise(rb_eStandardError, "PQserverVersion not supported by this client version.");
117
- }
118
- #endif /* PG_BEFORE_080000 */
119
-
120
- #ifdef PG_BEFORE_070400
121
- PGresult *
122
- PQexecParams(PGconn *conn, const char *command, int nParams,
123
- const Oid *paramTypes, const char * const * paramValues, const int *paramLengths,
124
- const int *paramFormats, int resultFormat)
125
- {
126
- rb_raise(rb_eStandardError, "PQexecParams not supported by this client version.");
127
- }
128
-
129
- PGTransactionStatusType
130
- PQtransactionStatus(const PGconn *conn)
131
- {
132
- rb_raise(rb_eStandardError, "PQtransactionStatus not supported by this client version.");
133
- }
134
-
135
- char *
136
- PQparameterStatus(const PGconn *conn, const char *paramName)
137
- {
138
- rb_raise(rb_eStandardError, "PQparameterStatus not supported by this client version.");
139
- }
140
-
141
- int
142
- PQprotocolVersion(const PGconn *conn)
143
- {
144
- rb_raise(rb_eStandardError, "PQprotocolVersion not supported by this client version.");
145
- }
146
-
147
- PGresult
148
- *PQexecPrepared(PGconn *conn, const char *stmtName, int nParams,
149
- const char * const *ParamValues, const int *paramLengths, const int *paramFormats,
150
- int resultFormat)
151
- {
152
- rb_raise(rb_eStandardError, "PQexecPrepared not supported by this client version.");
153
- }
154
-
155
- int
156
- PQsendQueryParams(PGconn *conn, const char *command, int nParams,
157
- const Oid *paramTypes, const char * const * paramValues, const int *paramLengths,
158
- const int *paramFormats, int resultFormat)
159
- {
160
- rb_raise(rb_eStandardError, "PQsendQueryParams not supported by this client version.");
161
- }
162
-
163
- int
164
- PQsendQueryPrepared(PGconn *conn, const char *stmtName, int nParams,
165
- const char * const *ParamValues, const int *paramLengths, const int *paramFormats,
166
- int resultFormat)
167
- {
168
- rb_raise(rb_eStandardError, "PQsendQueryPrepared not supported by this client version.");
169
- }
170
-
171
- int
172
- PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
173
- {
174
- rb_raise(rb_eStandardError, "PQputCopyData not supported by this client version.");
175
- }
176
-
177
- int
178
- PQputCopyEnd(PGconn *conn, const char *errormsg)
179
- {
180
- rb_raise(rb_eStandardError, "PQputCopyEnd not supported by this client version.");
181
- }
182
-
183
- int
184
- PQgetCopyData(PGconn *conn, char **buffer, int async)
185
- {
186
- rb_raise(rb_eStandardError, "PQgetCopyData not supported by this client version.");
187
- }
188
-
189
- PGVerbosity
190
- PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)
191
- {
192
- rb_raise(rb_eStandardError, "PQsetErrorVerbosity not supported by this client version.");
193
- }
194
-
195
- Oid
196
- PQftable(const PGresult *res, int column_number)
197
- {
198
- rb_raise(rb_eStandardError, "PQftable not supported by this client version.");
199
- }
200
-
201
- int
202
- PQftablecol(const PGresult *res, int column_number)
203
- {
204
- rb_raise(rb_eStandardError, "PQftablecol not supported by this client version.");
205
- }
206
-
207
- int
208
- PQfformat(const PGresult *res, int column_number)
209
- {
210
- rb_raise(rb_eStandardError, "PQfformat not supported by this client version.");
211
- }
212
-
213
- PQnoticeReceiver
214
- PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg)
215
- {
216
- rb_raise(rb_eStandardError, "PQsetNoticeReceiver not supported by this client version.");
217
- }
218
-
219
- char *
220
- PQresultErrorField(const PGresult *res, int fieldcode)
221
- {
222
- rb_raise(rb_eStandardError, "PQresultErrorField not supported by this client version.");
223
- }
224
- #endif /* PG_BEFORE_070400 */
225
-
226
- #ifdef PG_BEFORE_070300
227
- size_t
228
- PQescapeStringConn(PGconn *conn, char *to, const char *from,
229
- size_t length, int *error)
230
- {
231
- return PQescapeString(to,from,length);
232
- }
233
-
234
- unsigned char *
235
- PQescapeByteaConn(PGconn *conn, const unsigned char *from,
236
- size_t from_length, size_t *to_length)
237
- {
238
- return PQescapeBytea(from, from_length, to_length);
239
- }
240
- #endif /* PG_BEFORE_070300 */
241
-
242
-
243
- /**************************************************************************
244
-
245
- IF ANY CODE IS COPIED FROM POSTGRESQL, PLACE IT AFTER THIS COMMENT.
246
-
247
- ***************************************************************************
248
-
249
- Portions of code after this point were copied from the PostgreSQL source
250
- distribution, available at http://www.postgresql.org
251
-
252
- ***************************************************************************
253
-
254
- Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
255
-
256
- Portions Copyright (c) 1994, The Regents of the University of California
257
-
258
- Permission to use, copy, modify, and distribute this software and its
259
- documentation for any purpose, without fee, and without a written agreement
260
- is hereby granted, provided that the above copyright notice and this
261
- paragraph and the following two paragraphs appear in all copies.
262
-
263
- IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
264
- DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
265
- LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
266
- DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
267
- POSSIBILITY OF SUCH DAMAGE.
268
-
269
- THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
270
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
271
- AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
272
- ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
273
- PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
274
-
275
- **************************************************************************/
276
-
277
- #ifndef HAVE_PQSETCLIENTENCODING
278
- int
279
- PQsetClientEncoding(PGconn *conn, const char *encoding)
280
- {
281
- char qbuf[128];
282
- static const char query[] = "set client_encoding to '%s'";
283
- PGresult *res;
284
- int status;
285
-
286
- if (!conn || PQstatus(conn) != CONNECTION_OK)
287
- return -1;
288
-
289
- if (!encoding)
290
- return -1;
291
-
292
- /* check query buffer overflow */
293
- if (sizeof(qbuf) < (sizeof(query) + strlen(encoding)))
294
- return -1;
295
-
296
- /* ok, now send a query */
297
- sprintf(qbuf, query, encoding);
298
- res = PQexec(conn, qbuf);
299
-
300
- if (res == NULL)
301
- return -1;
302
- if (PQresultStatus(res) != PGRES_COMMAND_OK)
303
- status = -1;
304
- else
305
- {
306
- /*
307
- * In protocol 2 we have to assume the setting will stick, and adjust
308
- * our state immediately. In protocol 3 and up we can rely on the
309
- * backend to report the parameter value, and we'll change state at
310
- * that time.
311
- */
312
- if (PQprotocolVersion(conn) < 3)
313
- pqSaveParameterStatus(conn, "client_encoding", encoding);
314
- status = 0; /* everything is ok */
315
- }
316
- PQclear(res);
317
- return status;
318
- }
319
- #endif /* HAVE_PQSETCLIENTENCODING */
320
-
321
- #ifndef HAVE_PQESCAPESTRING
322
- /*
323
- * Escaping arbitrary strings to get valid SQL literal strings.
324
- *
325
- * Replaces "\\" with "\\\\" and "'" with "''".
326
- *
327
- * length is the length of the source string. (Note: if a terminating NUL
328
- * is encountered sooner, PQescapeString stops short of "length"; the behavior
329
- * is thus rather like strncpy.)
330
- *
331
- * For safety the buffer at "to" must be at least 2*length + 1 bytes long.
332
- * A terminating NUL character is added to the output string, whether the
333
- * input is NUL-terminated or not.
334
- *
335
- * Returns the actual length of the output (not counting the terminating NUL).
336
- */
337
- size_t
338
- PQescapeString(char *to, const char *from, size_t length)
339
- {
340
- const char *source = from;
341
- char *target = to;
342
- size_t remaining = length;
343
-
344
- while (remaining > 0 && *source != '\0')
345
- {
346
- switch (*source)
347
- {
348
- case '\\':
349
- *target++ = '\\';
350
- *target++ = '\\';
351
- break;
352
-
353
- case '\'':
354
- *target++ = '\'';
355
- *target++ = '\'';
356
- break;
357
-
358
- default:
359
- *target++ = *source;
360
- break;
361
- }
362
- source++;
363
- remaining--;
364
- }
365
-
366
- /* Write the terminating NUL character. */
367
- *target = '\0';
368
-
369
- return target - to;
370
- }
371
-
372
- /*
373
- * PQescapeBytea - converts from binary string to the
374
- * minimal encoding necessary to include the string in an SQL
375
- * INSERT statement with a bytea type column as the target.
376
- *
377
- * The following transformations are applied
378
- * '\0' == ASCII 0 == \\000
379
- * '\'' == ASCII 39 == \'
380
- * '\\' == ASCII 92 == \\\\
381
- * anything < 0x20, or > 0x7e ---> \\ooo
382
- * (where ooo is an octal expression)
383
- */
384
- unsigned char *
385
- PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
386
- {
387
- const unsigned char *vp;
388
- unsigned char *rp;
389
- unsigned char *result;
390
- size_t i;
391
- size_t len;
392
-
393
- /*
394
- * empty string has 1 char ('\0')
395
- */
396
- len = 1;
397
-
398
- vp = bintext;
399
- for (i = binlen; i > 0; i--, vp++)
400
- {
401
- if (*vp < 0x20 || *vp > 0x7e)
402
- len += 5; /* '5' is for '\\ooo' */
403
- else if (*vp == '\'')
404
- len += 2;
405
- else if (*vp == '\\')
406
- len += 4;
407
- else
408
- len++;
409
- }
410
-
411
- rp = result = (unsigned char *) malloc(len);
412
- if (rp == NULL)
413
- return NULL;
414
-
415
- vp = bintext;
416
- *bytealen = len;
417
-
418
- for (i = binlen; i > 0; i--, vp++)
419
- {
420
- if (*vp < 0x20 || *vp > 0x7e)
421
- {
422
- (void) sprintf(rp, "\\\\%03o", *vp);
423
- rp += 5;
424
- }
425
- else if (*vp == '\'')
426
- {
427
- rp[0] = '\\';
428
- rp[1] = '\'';
429
- rp += 2;
430
- }
431
- else if (*vp == '\\')
432
- {
433
- rp[0] = '\\';
434
- rp[1] = '\\';
435
- rp[2] = '\\';
436
- rp[3] = '\\';
437
- rp += 4;
438
- }
439
- else
440
- *rp++ = *vp;
441
- }
442
- *rp = '\0';
443
-
444
- return result;
445
- }
446
-
447
- #define ISFIRSTOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '3')
448
- #define ISOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '7')
449
- #define OCTVAL(CH) ((CH) - '0')
450
-
451
- /*
452
- * PQunescapeBytea - converts the null terminated string representation
453
- * of a bytea, strtext, into binary, filling a buffer. It returns a
454
- * pointer to the buffer (or NULL on error), and the size of the
455
- * buffer in retbuflen. The pointer may subsequently be used as an
456
- * argument to the function free(3). It is the reverse of PQescapeBytea.
457
- *
458
- * The following transformations are made:
459
- * \\ == ASCII 92 == \
460
- * \ooo == a byte whose value = ooo (ooo is an octal number)
461
- * \x == x (x is any character not matched by the above transformations)
462
- */
463
- unsigned char *
464
- PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
465
- {
466
- size_t strtextlen,
467
- buflen;
468
- unsigned char *buffer,
469
- *tmpbuf;
470
- size_t i,
471
- j;
472
-
473
- if (strtext == NULL)
474
- return NULL;
475
-
476
- strtextlen = strlen(strtext);
477
-
478
- /*
479
- * Length of input is max length of output, but add one to avoid
480
- * unportable malloc(0) if input is zero-length.
481
- */
482
- buffer = (unsigned char *) malloc(strtextlen + 1);
483
- if (buffer == NULL)
484
- return NULL;
485
-
486
- for (i = j = 0; i < strtextlen;)
487
- {
488
- switch (strtext[i])
489
- {
490
- case '\\':
491
- i++;
492
- if (strtext[i] == '\\')
493
- buffer[j++] = strtext[i++];
494
- else
495
- {
496
- if ((ISFIRSTOCTDIGIT(strtext[i])) &&
497
- (ISOCTDIGIT(strtext[i + 1])) &&
498
- (ISOCTDIGIT(strtext[i + 2])))
499
- {
500
- int byte;
501
-
502
- byte = OCTVAL(strtext[i++]);
503
- byte = (byte << 3) + OCTVAL(strtext[i++]);
504
- byte = (byte << 3) + OCTVAL(strtext[i++]);
505
- buffer[j++] = byte;
506
- }
507
- }
508
-
509
- /*
510
- * Note: if we see '\' followed by something that isn't a
511
- * recognized escape sequence, we loop around having done
512
- * nothing except advance i. Therefore the something will
513
- * be emitted as ordinary data on the next cycle. Corner
514
- * case: '\' at end of string will just be discarded.
515
- */
516
- break;
517
-
518
- default:
519
- buffer[j++] = strtext[i++];
520
- break;
521
- }
522
- }
523
- buflen = j; /* buflen is the length of the dequoted
524
- * data */
525
-
526
- /* Shrink the buffer to be no larger than necessary */
527
- /* +1 avoids unportable behavior when buflen==0 */
528
- tmpbuf = realloc(buffer, buflen + 1);
529
-
530
- /* It would only be a very brain-dead realloc that could fail, but... */
531
- if (!tmpbuf)
532
- {
533
- free(buffer);
534
- return NULL;
535
- }
536
-
537
- *retbuflen = buflen;
538
- return tmpbuf;
539
- }
540
- #endif
541
-
data/ext/compat.h DELETED
@@ -1,184 +0,0 @@
1
-
2
- #ifndef __compat_h
3
- #define __compat_h
4
-
5
- #include <stdlib.h>
6
-
7
- #ifdef RUBY_EXTCONF_H
8
- #include RUBY_EXTCONF_H
9
- #endif
10
-
11
- #include "libpq-fe.h"
12
- #include "libpq/libpq-fs.h" /* large-object interface */
13
-
14
- #include "ruby.h"
15
-
16
- /* pg_config.h does not exist in older versions of
17
- * PostgreSQL, so I can't effectively use PG_VERSION_NUM
18
- * Instead, I create some #defines to help organization.
19
- */
20
- #ifndef HAVE_PQCONNECTIONUSEDPASSWORD
21
- #define PG_BEFORE_080300
22
- #endif
23
-
24
- #ifndef HAVE_PQISTHREADSAFE
25
- #define PG_BEFORE_080200
26
- #endif
27
-
28
- #ifndef HAVE_LO_CREATE
29
- #define PG_BEFORE_080100
30
- #endif
31
-
32
- #ifndef HAVE_PQPREPARE
33
- #define PG_BEFORE_080000
34
- #endif
35
-
36
- #ifndef HAVE_PQEXECPARAMS
37
- #define PG_BEFORE_070400
38
- #endif
39
-
40
- #ifndef HAVE_PQESCAPESTRINGCONN
41
- #define PG_BEFORE_070300
42
- #error PostgreSQL client version too old, requires 7.3 or later.
43
- #endif
44
-
45
- /* This is necessary because NAMEDATALEN is defined in
46
- * pg_config_manual.h in 8.3, and that include file doesn't
47
- * exist before 7.4
48
- */
49
- #ifndef PG_BEFORE_070400
50
- #include "pg_config_manual.h"
51
- #endif
52
-
53
- #ifndef PG_DIAG_INTERNAL_POSITION
54
- #define PG_DIAG_INTERNAL_POSITION 'p'
55
- #endif /* PG_DIAG_INTERNAL_POSITION */
56
-
57
- #ifndef PG_DIAG_INTERNAL_QUERY
58
- #define PG_DIAG_INTERNAL_QUERY 'q'
59
- #endif /* PG_DIAG_INTERNAL_QUERY */
60
-
61
- #ifdef PG_BEFORE_080300
62
-
63
- #ifndef HAVE_PG_ENCODING_TO_CHAR
64
- #define pg_encoding_to_char(x) "SQL_ASCII"
65
- #else
66
- /* Some versions ofPostgreSQL prior to 8.3 define pg_encoding_to_char
67
- * but do not declare it in a header file, so this declaration will
68
- * eliminate an unecessary warning
69
- */
70
- extern char* pg_encoding_to_char(int);
71
- #endif /* HAVE_PG_ENCODING_TO_CHAR */
72
-
73
- int PQconnectionNeedsPassword(PGconn *conn);
74
- int PQconnectionUsedPassword(PGconn *conn);
75
- int lo_truncate(PGconn *conn, int fd, size_t len);
76
-
77
- #endif /* PG_BEFORE_080300 */
78
-
79
- #ifdef PG_BEFORE_080200
80
- int PQisthreadsafe(void);
81
- int PQnparams(const PGresult *res);
82
- Oid PQparamtype(const PGresult *res, int param_number);
83
- PGresult * PQdescribePrepared(PGconn *conn, const char *stmtName);
84
- PGresult * PQdescribePortal(PGconn *conn, const char *portalName);
85
- int PQsendDescribePrepared(PGconn *conn, const char *stmtName);
86
- int PQsendDescribePortal(PGconn *conn, const char *portalName);
87
- char *PQencryptPassword(const char *passwd, const char *user);
88
- #endif /* PG_BEFORE_080200 */
89
-
90
- #ifdef PG_BEFORE_080100
91
- Oid lo_create(PGconn *conn, Oid lobjId);
92
- #endif /* PG_BEFORE_080100 */
93
-
94
- #ifdef PG_BEFORE_080000
95
- PGresult *PQprepare(PGconn *conn, const char *stmtName, const char *query,
96
- int nParams, const Oid *paramTypes);
97
- int PQsendPrepare(PGconn *conn, const char *stmtName, const char *query,
98
- int nParams, const Oid *paramTypes);
99
- int PQserverVersion(const PGconn* conn);
100
- #endif /* PG_BEFORE_080000 */
101
-
102
- #ifdef PG_BEFORE_070400
103
-
104
- #define PG_DIAG_SEVERITY 'S'
105
- #define PG_DIAG_SQLSTATE 'C'
106
- #define PG_DIAG_MESSAGE_PRIMARY 'M'
107
- #define PG_DIAG_MESSAGE_DETAIL 'D'
108
- #define PG_DIAG_MESSAGE_HINT 'H'
109
- #define PG_DIAG_STATEMENT_POSITION 'P'
110
- #define PG_DIAG_CONTEXT 'W'
111
- #define PG_DIAG_SOURCE_FILE 'F'
112
- #define PG_DIAG_SOURCE_LINE 'L'
113
- #define PG_DIAG_SOURCE_FUNCTION 'R'
114
-
115
- #define PQfreemem(ptr) free(ptr)
116
- #define PGNOTIFY_EXTRA(notify) ""
117
-
118
- /* CONNECTION_SSL_STARTUP was added to an enum type
119
- * after 7.3. For 7.3 in order to compile, we just need
120
- * it to evaluate to something that is not present in that
121
- * enum.
122
- */
123
- #define CONNECTION_SSL_STARTUP 1000000
124
-
125
- typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);
126
-
127
- typedef enum
128
- {
129
- PQERRORS_TERSE, /* single-line error messages */
130
- PQERRORS_DEFAULT, /* recommended style */
131
- PQERRORS_VERBOSE /* all the facts, ma'am */
132
- } PGVerbosity;
133
-
134
- typedef enum
135
- {
136
- PQTRANS_IDLE, /* connection idle */
137
- PQTRANS_ACTIVE, /* command in progress */
138
- PQTRANS_INTRANS, /* idle, within transaction block */
139
- PQTRANS_INERROR, /* idle, within failed transaction */
140
- PQTRANS_UNKNOWN /* cannot determine status */
141
- } PGTransactionStatusType;
142
-
143
- PGresult *PQexecParams(PGconn *conn, const char *command, int nParams,
144
- const Oid *paramTypes, const char * const * paramValues, const int *paramLengths,
145
- const int *paramFormats, int resultFormat);
146
- PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
147
- char *PQparameterStatus(const PGconn *conn, const char *paramName);
148
- int PQprotocolVersion(const PGconn *conn);
149
- PGresult *PQexecPrepared(PGconn *conn, const char *stmtName, int nParams,
150
- const char * const *ParamValues, const int *paramLengths, const int *paramFormats,
151
- int resultFormat);
152
- int PQsendQueryParams(PGconn *conn, const char *command, int nParams,
153
- const Oid *paramTypes, const char * const * paramValues, const int *paramLengths,
154
- const int *paramFormats, int resultFormat);
155
- int PQsendQueryPrepared(PGconn *conn, const char *stmtName, int nParams,
156
- const char * const *ParamValues, const int *paramLengths, const int *paramFormats,
157
- int resultFormat);
158
- int PQputCopyData(PGconn *conn, const char *buffer, int nbytes);
159
- int PQputCopyEnd(PGconn *conn, const char *errormsg);
160
- int PQgetCopyData(PGconn *conn, char **buffer, int async);
161
- PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);
162
- Oid PQftable(const PGresult *res, int column_number);
163
- int PQftablecol(const PGresult *res, int column_number);
164
- int PQfformat(const PGresult *res, int column_number);
165
- char *PQresultErrorField(const PGresult *res, int fieldcode);
166
- PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg);
167
-
168
- #else
169
- #define PGNOTIFY_EXTRA(notify) ((notify)->extra)
170
- #endif /* PG_BEFORE_070400 */
171
-
172
- #ifdef PG_BEFORE_070300
173
- #error unsupported postgresql version, requires 7.3 or later.
174
- int PQsetClientEncoding(PGconn *conn, const char *encoding)
175
- size_t PQescapeString(char *to, const char *from, size_t length);
176
- unsigned char * PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen);
177
- unsigned char * PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen);
178
- size_t PQescapeStringConn(PGconn *conn, char *to, const char *from,
179
- size_t length, int *error);
180
- unsigned char *PQescapeByteaConn(PGconn *conn, const unsigned char *from,
181
- size_t from_length, size_t *to_length);
182
- #endif /* PG_BEFORE_070300 */
183
-
184
- #endif /* __compat_h */