annotate modules/postgresql/postgresql.c @ 1306:371cff0ccdd7

[xemacs-hg @ 2003-02-16 06:08:02 by youngs] Take out Rendhalver - 21.5.11 would have been the first release with him in about.el, but seeing as though he has decided to leave the project, I've taken him out of about.el. If he changes his mind, I can always put him back in.
author youngs
date Sun, 16 Feb 2003 06:08:02 +0000
parents e22b0213b713
children 64eaceca611d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1 /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
2 postgresql.c -- Emacs Lisp binding to libpq.so
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
3 Copyright (C) 2000 Electrotechnical Laboratory, JAPAN.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
4 Licensed to the Free Software Foundation.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
5
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
6 Author: SL Baur <steve@beopen.com>
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
7 Maintainer: SL Baur <steve@beopen.com>
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
8
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
9 Please send patches to this file to me first before submitting them to
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
10 xemacs-patches.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
11
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
12
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
13 KNOWN PROBLEMS (Last update 15-March-2000)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
14 + None.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
15
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
16 Implementation notes:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
17 0. Supported PostgreSQL versions
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
18 This code was developed against libpq-6.5.3 and libpq-7.0-beta1. Earlier
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
19 versions may work. V7 support is more complete than V6.5 support.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
20 1. Mule
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
21 Non-ASCII databases have been tested on both 6.5 and 7.0.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
22 2. Asynchronous Operation
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
23 Starting with libpq-7.0, an asynchronous interface is offered. This
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
24 binding supports the asynchronous calls to a limited extent. Since the
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
25 XEmacs 21.2 core does not support a sensible interface to add managed but
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
26 unreadable (by XEmacs) file descriptors to the main select code, polling
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
27 is required to drive the asynchronous calls. XtAppAddInput would work
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
28 fine, but we want to be able to use the database when running strictly in
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
29 tty mode.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
30 3. Completeness
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
31 Various calls have been deliberately not exported to Lisp. The
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
32 unexported calls are either left-over backwards compatibility code that
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
33 aren't needed, calls that cannot be implemented sensibly, or calls that
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
34 cannot be implemented safely. A list of all global functions in libpq
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
35 but not exported to Lisp is below.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
36 4. Policy
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
37 This interface tries very hard to not set any policy towards how database
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
38 code in Emacs Lisp will be written.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
39 5. Documentation
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
40 For full lisp programming documentation, see the XEmacs Lisp Reference
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
41 Manual. For PostgreSQL documentation, see the PostgreSQL distribution.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
42
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
43 TODO (in rough order of priority):
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
44 1. Asynchronous notifies need to be implemented to the extent they can be.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
45 2. The large object interface needs work with Emacs buffers in addition
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
46 to files. Need two functions buffer->large_object, and large_object->
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
47 buffer.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
48 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
49
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
50 /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
51 Unimplemented functions: [TODO]
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
52 PQsetNoticeProcessor
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
53
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
54 Implemented, but undocumented functions: [TODO]
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
55 PQgetline (copy in/out)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
56 PQputline (copy in/out)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
57 PQgetlineAsync (copy in/out Asynch.)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
58 PQputnbytes (copy in/out Asynch.)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
59 PQendcopy (copy in/out)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
60
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
61 Unsupported functions:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
62 PQsetdbLogin -- This function is deprecated, has a subset of the
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
63 functionality of PQconnectdb, and is better done in Lisp.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
64 PQsetdb -- Same as for PQsetdbLogin
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
65 PQsocket -- Abstraction error, file descriptors should not be leaked
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
66 into Lisp code
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
67 PQprint -- print to a file descriptor, deprecated, better done in Lisp
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
68 PQdisplayTuples -- deprecated
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
69 PQprintTuples -- really, really deprecated
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
70 PQmblen -- Returns the length in bytes of multibyte character encoded
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
71 string.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
72 PQtrace -- controls debug print tracing to a tty.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
73 PQuntrace -- Ditto. I don't see any way to do this sensibly.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
74 PQoidStatus -- deprecated and nearly identical to PQoidValue
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
75 PQfn -- "Fast path" interface
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
76 lo_open (large object) [*]
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
77 lo_close (large object) [*]
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
78 lo_read (large object) [*]
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
79 lo_write (large object) [*]
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
80 lo_lseek (large object) [*]
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
81 lo_creat (large object) [*]
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
82 lo_tell (large object) [*]
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
83 lo_unlink (large object) [*]
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
84 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
85
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
86 #include <config.h>
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
87
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
88 /* This must be portable with XEmacs 21.1 so long as it is the official
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
89 released version of XEmacs and provides the basis of InfoDock. The
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
90 interface to lcrecord handling has changed with 21.2, so unfortunately
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
91 we will need a few snippets of backwards compatibility code.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
92 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
93 #if (EMACS_MAJOR_VERSION == 21) && (EMACS_MINOR_VERSION < 2)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
94 #define RUNNING_XEMACS_21_1 1
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
95 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
96
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
97 /* #define POSTGRES_LO_IMPORT_IS_VOID 1 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
98
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
99 #include "lisp.h"
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
100 #include "sysdep.h"
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
101
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
102 #include "buffer.h"
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
103 #include "postgresql.h"
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
104 #include "process.h"
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
105
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
106 #ifdef RUNNING_XEMACS_21_1 /* handle interface changes */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
107 #define PG_OS_CODING FORMAT_FILENAME
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
108 #define TO_EXTERNAL_FORMAT(a,from,b,to,c) GET_C_STRING_EXT_DATA_ALLOCA(from,FORMAT_FILENAME,to)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
109 #else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
110 #ifdef MULE
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
111 #define PG_OS_CODING get_coding_system_for_text_file (Vpg_coding_system, 1)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
112 #else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
113 #define PG_OS_CODING Qnative
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
114 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
115 Lisp_Object Vpg_coding_system;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
116 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
117
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
118 #define CHECK_LIVE_CONNECTION(P) do { \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
119 if (!P || (PQstatus (P) != CONNECTION_OK)) { \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
120 char *e = "bad value"; \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
121 if (P) e = PQerrorMessage (P); \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
122 signal_ferror (Qprocess_error, "dead connection [%s]", e); \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
123 } } while (0)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
124 #define PUKE_IF_NULL(p) do { \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
125 if (!p) signal_error (Qinvalid_argument, "bad value", Qunbound); \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
126 } while (0)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
127
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
128 static Lisp_Object VXPGHOST;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
129 static Lisp_Object VXPGUSER;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
130 static Lisp_Object VXPGOPTIONS;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
131 static Lisp_Object VXPGPORT;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
132 static Lisp_Object VXPGTTY; /* This needs to be blanked! */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
133 static Lisp_Object VXPGDATABASE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
134 static Lisp_Object VXPGREALM;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
135 #ifdef MULE
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
136 static Lisp_Object VXPGCLIENTENCODING;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
137 #endif /* MULE */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
138
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
139 /* Other variables:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
140 PGAUTHTYPE -- not used after PostgreSQL 6.5
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
141 PGGEQO
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
142 PGCOSTINDEX
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
143 PGCOSTHEAP
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
144 PGTZ
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
145 PGDATESTYLE
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
146 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
147 #ifndef HAVE_POSTGRESQLV7
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
148 static Lisp_Object VXPGAUTHTYPE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
149 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
150 static Lisp_Object VXPGGEQO, VXPGCOSTINDEX, VXPGCOSTHEAP, VXPGTZ, VXPGDATESTYLE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
151
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
152 static Lisp_Object Qpostgresql;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
153 static Lisp_Object Qpg_connection_ok, Qpg_connection_bad;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
154 static Lisp_Object Qpg_connection_started, Qpg_connection_made;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
155 static Lisp_Object Qpg_connection_awaiting_response, Qpg_connection_auth_ok;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
156 static Lisp_Object Qpg_connection_setenv;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
157
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
158 static Lisp_Object Qpqdb, Qpquser, Qpqpass, Qpqhost, Qpqport, Qpqtty;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
159 static Lisp_Object Qpqoptions, Qpqstatus, Qpqerrormessage, Qpqbackendpid;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
160
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
161 static Lisp_Object Qpgres_empty_query, Qpgres_command_ok, Qpgres_tuples_ok;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
162 static Lisp_Object Qpgres_copy_out, Qpgres_copy_in, Qpgres_bad_response;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
163 static Lisp_Object Qpgres_nonfatal_error, Qpgres_fatal_error;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
164
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
165 static Lisp_Object Qpgres_polling_failed, Qpgres_polling_reading;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
166 static Lisp_Object Qpgres_polling_writing, Qpgres_polling_ok;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
167 static Lisp_Object Qpgres_polling_active;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
168 /****/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
169
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
170 /* PGconn is an opaque object and we need to be able to store them in
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
171 Lisp code because libpq supports multiple connections.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
172 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
173 Lisp_Object Qpgconnp;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
174
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
175 static Lisp_Object
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
176 make_pgconn (Lisp_PGconn *pgconn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
177 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
178 return wrap_pgconn (pgconn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
179 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
180
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1111
diff changeset
181 static const struct memory_description pgconn_description [] = {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
182 { XD_END }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
183 };
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
184
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
185 static Lisp_Object
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
186 #ifdef RUNNING_XEMACS_21_1
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
187 mark_pgconn (Lisp_Object obj, void (*markobj) (Lisp_Object))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
188 #else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
189 mark_pgconn (Lisp_Object obj)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
190 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
191 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
192 return Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
193 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
194
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
195 static void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
196 print_pgconn (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
197 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
198 char buf[256];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
199 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
200 ConnStatusType cst;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
201 char *host="", *db="", *user="", *port="";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
202
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
203 P = (XPGCONN (obj))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
204
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
205 if (!P) /* this may happen since we allow PQfinish() to be called */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
206 strcpy (buf, "#<PGconn DEAD>"); /* evil! */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
207 else if ((cst = PQstatus (P)) == CONNECTION_OK)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
208 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
209 if (!(host = PQhost (P)))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
210 host = "";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
211 port = PQport (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
212 db = PQdb (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
213 if (!(user = PQuser (P)))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
214 user = "";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
215 sprintf (buf, "#<PGconn %s:%s %s/%s>", /* evil! */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
216 !strlen (host) ? "localhost" : host,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
217 port,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
218 user,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
219 db);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
220 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
221 else if (cst == CONNECTION_BAD)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
222 strcpy (buf, "#<PGconn BAD>"); /* evil! */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
223 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
224 strcpy (buf, "#<PGconn connecting>"); /* evil! */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
225
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
226 if (print_readably)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
227 printing_unreadable_object ("%s", buf);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
228 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
229 write_c_string (printcharfun, buf);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
230 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
231
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
232 static Lisp_PGconn *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
233 allocate_pgconn (void)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
234 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
235 #ifdef RUNNING_XEMACS_21_1
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
236 Lisp_PGconn *pgconn = alloc_lcrecord_type (Lisp_PGconn,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
237 lrecord_pgconn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
238 #else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
239 Lisp_PGconn *pgconn = alloc_lcrecord_type (Lisp_PGconn,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
240 &lrecord_pgconn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
241 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
242 pgconn->pgconn = (PGconn *)NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
243 return pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
244 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
245
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
246 static void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
247 finalize_pgconn (void *header, int for_disksave)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
248 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
249 Lisp_PGconn *pgconn = (Lisp_PGconn *)header;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
250
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
251 if (for_disksave)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
252 invalid_operation ("Can't dump an emacs containing PGconn objects",
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
253 make_pgconn (pgconn));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
254
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
255 if (pgconn->pgconn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
256 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
257 PQfinish (pgconn->pgconn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
258 pgconn->pgconn = (PGconn *)NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
259 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
260 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
261
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
262 #ifdef RUNNING_XEMACS_21_1
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
263 DEFINE_LRECORD_IMPLEMENTATION ("pgconn", pgconn,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
264 mark_pgconn, print_pgconn, finalize_pgconn,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
265 NULL, NULL,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
266 Lisp_PGconn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
267 #else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
268 DEFINE_LRECORD_IMPLEMENTATION ("pgconn", pgconn,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
269 0, /*dumpable-flag*/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
270 mark_pgconn, print_pgconn, finalize_pgconn,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
271 NULL, NULL,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
272 pgconn_description,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
273 Lisp_PGconn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
274 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
275 /****/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
276
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
277 /* PGresult is an opaque object and we need to be able to store them in
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
278 Lisp code.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
279 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
280 Lisp_Object Qpgresultp;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
281
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
282 static Lisp_Object
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
283 make_pgresult (Lisp_PGresult *pgresult)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
284 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
285 return wrap_pgresult (pgresult);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
286 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
287
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1111
diff changeset
288 static const struct memory_description pgresult_description [] = {
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
289 { XD_END }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
290 };
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
291
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
292
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
293 static Lisp_Object
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
294 #ifdef RUNNING_XEMACS_21_1
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
295 mark_pgresult (Lisp_Object obj, void (*markobj) (Lisp_Object))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
296 #else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
297 mark_pgresult (Lisp_Object obj)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
298 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
299 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
300 return Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
301 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
302
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
303 #define RESULT_TUPLES_FMT "#<PGresult %s[%d] - %s>"
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
304 #define RESULT_CMD_TUPLES_FMT "#<PGresult %s[%s] - %s>"
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
305 #define RESULT_DEFAULT_FMT "#<PGresult %s - %s>"
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
306 static void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
307 print_pgresult (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
308 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
309 char buf[1024];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
310 PGresult *res;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
311
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
312 res = (XPGRESULT (obj))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
313
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
314 if (res)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
315 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
316 switch (PQresultStatus (res))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
317 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
318 case PGRES_TUPLES_OK:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
319 /* Add number of tuples of result to output */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
320 sprintf (buf, RESULT_TUPLES_FMT, /* evil! */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
321 PQresStatus (PQresultStatus (res)),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
322 PQntuples (res),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
323 PQcmdStatus (res));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
324 break;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
325 case PGRES_COMMAND_OK:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
326 /* Add number of tuples affected by output-less command */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
327 if (!strlen (PQcmdTuples (res))) goto notuples;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
328 sprintf (buf, RESULT_CMD_TUPLES_FMT, /* evil! */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
329 PQresStatus (PQresultStatus (res)),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
330 PQcmdTuples (res),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
331 PQcmdStatus (res));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
332 break;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
333 default:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
334 notuples:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
335 /* No counts to print */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
336 sprintf (buf, RESULT_DEFAULT_FMT, /* evil! */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
337 PQresStatus (PQresultStatus (res)),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
338 PQcmdStatus (res));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
339 break;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
340 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
341 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
342 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
343 strcpy (buf, "#<PGresult DEAD>"); /* evil! */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
344
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
345 if (print_readably)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
346 printing_unreadable_object ("%s", buf);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
347 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
348 write_c_string (printcharfun, buf);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
349 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
350
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
351 #undef RESULT_TUPLES_FMT
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
352 #undef RESULT_CMD_TUPLES_FMT
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
353 #undef RESULT_DEFAULT_FMT
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
354
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
355 static Lisp_PGresult *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
356 allocate_pgresult (void)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
357 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
358 #ifdef RUNNING_XEMACS_21_1
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
359 Lisp_PGresult *pgresult = alloc_lcrecord_type (Lisp_PGresult,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
360 lrecord_pgresult);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
361 #else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
362 Lisp_PGresult *pgresult = alloc_lcrecord_type (Lisp_PGresult,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
363 &lrecord_pgresult);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
364 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
365 pgresult->pgresult = (PGresult *)NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
366 return pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
367 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
368
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
369 static void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
370 finalize_pgresult (void *header, int for_disksave)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
371 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
372 Lisp_PGresult *pgresult = (Lisp_PGresult *)header;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
373
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
374 if (for_disksave)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
375 invalid_operation ("Can't dump an emacs containing PGresult objects",
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
376 make_pgresult (pgresult));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
377
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
378 if (pgresult->pgresult)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
379 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
380 PQclear (pgresult->pgresult);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
381 pgresult->pgresult = (PGresult *)NULL;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
382 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
383 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
384
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
385 #ifdef RUNNING_XEMACS_21_1
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
386 DEFINE_LRECORD_IMPLEMENTATION ("pgresult", pgresult,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
387 mark_pgresult, print_pgresult, finalize_pgresult,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
388 NULL, NULL,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
389 Lisp_PGresult);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
390 #else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
391 DEFINE_LRECORD_IMPLEMENTATION ("pgresult", pgresult,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
392 0, /*dumpable-flag*/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
393 mark_pgresult, print_pgresult, finalize_pgresult,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
394 NULL, NULL,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
395 pgresult_description,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
396 Lisp_PGresult);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
397 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
398
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
399 /***********************/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
400
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
401 /* notices */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
402 static void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
403 xemacs_notice_processor (void *arg, const char *msg)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
404 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
405 warn_when_safe (Qpostgresql, Qnotice, "%s", msg);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
406 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
407
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
408 /* There are four ways (as of PostgreSQL v7) to connect to a database.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
409 Two of them, PQsetdb and PQsetdbLogin, are deprecated. Both of those
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
410 routines take a number of positional parameters and are better done in Lisp.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
411 Note that PQconnectStart does not exist prior to v7.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
412 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
413
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
414 /* ###autoload */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
415 DEFUN ("pq-conn-defaults", Fpq_conn_defaults, 0, 0, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
416 Return a connection default structure.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
417 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
418 ())
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
419 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
420 /* This function can GC */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
421 PQconninfoOption *pcio;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
422 Lisp_Object temp, temp1;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
423 int i;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
424
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
425 pcio = PQconndefaults();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
426 if (!pcio) return Qnil; /* can never happen in libpq-7.0 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
427 temp = list1 (Fcons (build_ext_string (pcio[0].keyword, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
428 Fcons (build_ext_string (pcio[0].envvar, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
429 Fcons (build_ext_string (pcio[0].compiled, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
430 Fcons (build_ext_string (pcio[0].val, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
431 Fcons (build_ext_string (pcio[0].label, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
432 Fcons (build_ext_string (pcio[0].dispchar, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
433 Fcons (make_int (pcio[0].dispsize), Qnil))))))));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
434
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
435 for (i = 1; pcio[i].keyword; i++)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
436 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
437 temp1 = list1 (Fcons (build_ext_string (pcio[i].keyword, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
438 Fcons (build_ext_string (pcio[i].envvar, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
439 Fcons (build_ext_string (pcio[i].compiled, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
440 Fcons (build_ext_string (pcio[i].val, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
441 Fcons (build_ext_string (pcio[i].label, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
442 Fcons (build_ext_string (pcio[i].dispchar, PG_OS_CODING),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
443 Fcons (make_int (pcio[i].dispsize), Qnil))))))));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
444 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
445 Lisp_Object args[2];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
446 args[0] = temp;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
447 args[1] = temp1;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
448 /* Fappend GCPROs its arguments */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
449 temp = Fappend (2, args);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
450 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
451 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
452
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
453 return temp;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
454 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
455
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
456 /* PQconnectdb Makes a new connection to a backend.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
457 PGconn *PQconnectdb(const char *conninfo)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
458 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
459
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
460 /* ###autoload */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
461 DEFUN ("pq-connectdb", Fpq_connectdb, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
462 Make a new connection to a PostgreSQL backend.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
463 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
464 (conninfo))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
465 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
466 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
467 Lisp_PGconn *lisp_pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
468 char *error_message = "Out of Memory?";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
469 char *c_conninfo;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
470
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
471 CHECK_STRING (conninfo);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
472
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
473 TO_EXTERNAL_FORMAT(LISP_STRING, conninfo,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
474 C_STRING_ALLOCA, c_conninfo, Qnative);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
475 P = PQconnectdb (c_conninfo);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
476 if (P && (PQstatus (P) == CONNECTION_OK))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
477 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
478 (void)PQsetNoticeProcessor (P, xemacs_notice_processor, NULL);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
479 lisp_pgconn = allocate_pgconn();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
480 lisp_pgconn->pgconn = P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
481 return make_pgconn (lisp_pgconn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
482 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
483 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
484 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
485 /* Connection failed. Destroy the connection and signal an error. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
486 char buf[BLCKSZ];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
487 strcpy (buf, error_message);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
488 if (P)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
489 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
490 /* storage for the error message gets erased when call PQfinish */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
491 /* so we must temporarily stash it somewhere */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
492 strncpy (buf, PQerrorMessage (P), sizeof (buf));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
493 buf[sizeof (buf) - 1] = '\0';
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
494 PQfinish (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
495 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
496 signal_ferror (Qprocess_error, "libpq: %s", buf);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
497 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
498 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
499
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
500 /* PQconnectStart Makes a new asynchronous connection to a backend.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
501 PGconn *PQconnectStart(const char *conninfo)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
502 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
503
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
504 #ifdef HAVE_POSTGRESQLV7
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
505 /* ###autoload */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
506 DEFUN ("pq-connect-start", Fpq_connect_start, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
507 Make a new asynchronous connection to a PostgreSQL backend.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
508 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
509 (conninfo))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
510 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
511 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
512 Lisp_PGconn *lisp_pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
513 char *error_message = "Out of Memory?";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
514 char *c_conninfo;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
515
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
516 CHECK_STRING (conninfo);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
517 TO_EXTERNAL_FORMAT (LISP_STRING, conninfo,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
518 C_STRING_ALLOCA, c_conninfo, Qnative);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
519 P = PQconnectStart (c_conninfo);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
520
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
521 if (P && (PQstatus (P) != CONNECTION_BAD))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
522 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
523 (void)PQsetNoticeProcessor (P, xemacs_notice_processor, NULL);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
524 lisp_pgconn = allocate_pgconn();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
525 lisp_pgconn->pgconn = P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
526
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
527 return make_pgconn (lisp_pgconn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
528 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
529 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
530 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
531 /* capture the error message before destroying the object */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
532 char buf[BLCKSZ];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
533 strcpy (buf, error_message);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
534 if (P)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
535 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
536 strncpy (buf, PQerrorMessage (P), sizeof (buf));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
537 buf[sizeof (buf) - 1] = '\0';
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
538 PQfinish (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
539 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
540 signal_ferror (Qprocess_error, "libpq: %s", buf);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
541 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
542 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
543
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
544 DEFUN ("pq-connect-poll", Fpq_connect_poll, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
545 Poll an asynchronous connection for completion
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
546 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
547 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
548 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
549 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
550 PostgresPollingStatusType polling_status;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
551
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
552 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
553
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
554 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
555 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
556
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
557 polling_status = PQconnectPoll (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
558 switch (polling_status)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
559 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
560 case PGRES_POLLING_FAILED:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
561 /* Something Bad has happened */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
562 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
563 char *e = PQerrorMessage (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
564 signal_ferror (Qprocess_error, "libpq: %s", e);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
565 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
566 case PGRES_POLLING_OK:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
567 return Qpgres_polling_ok;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
568 case PGRES_POLLING_READING:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
569 return Qpgres_polling_reading;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
570 case PGRES_POLLING_WRITING:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
571 return Qpgres_polling_writing;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
572 case PGRES_POLLING_ACTIVE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
573 return Qpgres_polling_active;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
574 default:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
575 /* they've added a new field we don't know about */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
576 signal_ferror (Qprocess_error, "Help! Unknown status code %08x from backend!", polling_status);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
577 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
578 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
579
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
580 #ifdef MULE
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
581 DEFUN ("pq-client-encoding", Fpq_client_encoding, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
582 Return client coding system.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
583 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
584 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
585 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
586 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
587
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
588 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
589 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
590 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
591
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
592 return make_int (PQclientEncoding (P));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
593 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
594
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
595 DEFUN ("pq-set-client-encoding", Fpq_set_client_encoding, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
596 Set client coding system.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
597 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
598 (conn, encoding))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
599 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
600 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
601 int rc;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
602 char *c_encoding;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
603
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
604 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
605 CHECK_STRING (encoding);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
606
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
607 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
608 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
609
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
610 TO_EXTERNAL_FORMAT (LISP_STRING, encoding,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
611 C_STRING_ALLOCA, c_encoding, Qnative);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
612
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
613 if ((rc = PQsetClientEncoding (P, c_encoding)) < 0)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
614 signal_error (Qinvalid_argument, "bad encoding", Qunbound);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
615 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
616 return make_int (rc);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
617 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
618
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
619 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
620 #endif /* HAVE_POSTGRESQLV7 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
621
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
622 /* PQfinish Close the connection to the backend. Also frees memory
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
623 used by the PGconn object.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
624 void PQfinish(PGconn *conn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
625 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
626 DEFUN ("pq-finish", Fpq_finish, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
627 Close the connection to the backend.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
628 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
629 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
630 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
631 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
632
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
633 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
634 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
635 PUKE_IF_NULL (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
636
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
637 PQfinish (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
638 /* #### PQfinish deallocates the PGconn structure, so we now have a
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
639 dangling pointer. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
640 /* Genocided all @'s ... */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
641 (XPGCONN (conn))->pgconn = (PGconn *)NULL; /* You feel DEAD inside */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
642 return Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
643 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
644
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
645 DEFUN ("pq-clear", Fpq_clear, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
646 Forcibly erase a PGresult object.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
647 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
648 (res))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
649 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
650 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
651
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
652 CHECK_PGRESULT (res);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
653 R = (XPGRESULT (res))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
654 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
655
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
656 PQclear (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
657 /* Genocided all @'s ... */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
658 (XPGRESULT (res))->pgresult = (PGresult *)NULL; /* You feel DEAD inside */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
659
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
660 return Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
661 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
662
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
663 DEFUN ("pq-is-busy", Fpq_is_busy, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
664 Return t if PQgetResult would block waiting for input.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
665 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
666 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
667 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
668 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
669
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
670 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
671 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
672 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
673
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
674 return PQisBusy (P) ? Qt : Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
675 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
676
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
677 DEFUN ("pq-consume-input", Fpq_consume_input, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
678 Consume any available input from the backend.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
679 Returns nil if something bad happened.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
680 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
681 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
682 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
683 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
684
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
685 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
686 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
687 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
688
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
689 return PQconsumeInput (P) ? Qt : Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
690 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
691
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
692 /* PQreset Reset the communication port with the backend.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
693 void PQreset(PGconn *conn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
694 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
695 DEFUN ("pq-reset", Fpq_reset, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
696 Reset the connection to the backend.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
697 This function will close the connection to the backend and attempt to
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
698 reestablish a new connection to the same postmaster, using all the same
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
699 parameters previously used. This may be useful for error recovery if a
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
700 working connection is lost.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
701 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
702 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
703 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
704 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
705
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
706 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
707 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
708 PUKE_IF_NULL (P);/* we can resurrect a BAD connection, but not a dead one. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
709
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
710 PQreset (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
711
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
712 return Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
713 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
714
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
715 #ifdef HAVE_POSTGRESQLV7
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
716 DEFUN ("pq-reset-start", Fpq_reset_start, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
717 Reset connection to the backend asynchronously.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
718 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
719 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
720 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
721 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
722
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
723 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
724 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
725 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
726
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
727 if (PQresetStart (P)) return Qt;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
728 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
729 char *e = PQerrorMessage (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
730 signal_ferror (Qprocess_error, "libpq: %s", e);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
731 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
732 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
733
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
734 DEFUN ("pq-reset-poll", Fpq_reset_poll, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
735 Poll an asynchronous reset for completion.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
736 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
737 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
738 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
739 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
740 PostgresPollingStatusType polling_status;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
741
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
742 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
743
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
744 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
745 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
746
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
747 polling_status = PQresetPoll (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
748 switch (polling_status)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
749 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
750 case PGRES_POLLING_FAILED:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
751 /* Something Bad has happened */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
752 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
753 char *e = PQerrorMessage (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
754 signal_ferror (Qprocess_error, "libpq: %s", e);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
755 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
756 case PGRES_POLLING_OK:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
757 return Qpgres_polling_ok;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
758 case PGRES_POLLING_READING:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
759 return Qpgres_polling_reading;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
760 case PGRES_POLLING_WRITING:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
761 return Qpgres_polling_writing;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
762 case PGRES_POLLING_ACTIVE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
763 return Qpgres_polling_active;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
764 default:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
765 /* they've added a new field we don't know about */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
766 signal_ferror (Qprocess_error, "Help! Unknown status code %08x from backend!", polling_status);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
767 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
768 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
769 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
770
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
771 DEFUN ("pq-request-cancel", Fpq_request_cancel, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
772 Attempt to request cancellation of the current operation.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
773
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
774 The return value is t if the cancel request was successfully
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
775 dispatched, nil if not (in which case conn->errorMessage is set).
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
776 Note: successful dispatch is no guarantee that there will be any effect at
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
777 the backend. The application must read the operation result as usual.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
778 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
779 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
780 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
781 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
782
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
783 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
784 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
785 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
786
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
787 return PQrequestCancel (P) ? Qt : Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
788 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
789
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
790 /* accessor function for the PGconn object */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
791 DEFUN ("pq-pgconn", Fpq_pgconn, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
792 Accessor function for the PGconn object.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
793 Currently recognized symbols for the field:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
794 pq::db Database name
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
795 pq::user Database user name
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
796 pq::pass Database user's password
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
797 pq::host Hostname of PostgreSQL backend connected to
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
798 pq::port TCP port number of connection
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
799 pq::tty Debugging TTY (not used in Emacs)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
800 pq::options Additional backend options
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
801 pq::status Connection status (either OK or BAD)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
802 pq::error-message Last error message from the backend
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
803 pq::backend-pid Process ID of backend process
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
804 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
805 (conn, field))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
806 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
807 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
808
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
809 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
810 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
811 PUKE_IF_NULL (P); /* BAD connections still have state to query */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
812
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
813 if (EQ(field, Qpqdb))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
814 /* PQdb Returns the database name of the connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
815 char *PQdb(PGconn *conn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
816 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
817 return build_ext_string (PQdb(P), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
818 else if (EQ (field, Qpquser))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
819 /* PQuser Returns the user name of the connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
820 char *PQuser(PGconn *conn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
821 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
822 return build_ext_string (PQuser(P), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
823 else if (EQ (field, Qpqpass))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
824 /* PQpass Returns the password of the connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
825 char *PQpass(PGconn *conn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
826 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
827 return build_ext_string (PQpass(P), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
828 else if (EQ (field, Qpqhost))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
829 /* PQhost Returns the server host name of the connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
830 char *PQhost(PGconn *conn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
831 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
832 return build_ext_string (PQhost(P), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
833 else if (EQ (field, Qpqport))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
834 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
835 char *p;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
836 /* PQport Returns the port of the connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
837 char *PQport(PGconn *conn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
838 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
839 if ((p = PQport(P)))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
840 return make_int(atoi(p));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
841 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
842 return make_int(-1);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
843 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
844 else if (EQ (field, Qpqtty))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
845 /* PQtty Returns the debug tty of the connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
846 char *PQtty(PGconn *conn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
847 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
848 return build_ext_string (PQtty(P), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
849 else if (EQ (field, Qpqoptions))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
850 /* PQoptions Returns the backend options used in the connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
851 char *PQoptions(PGconn *conn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
852 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
853 return build_ext_string (PQoptions(P), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
854 else if (EQ (field, Qpqstatus))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
855 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
856 ConnStatusType cst;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
857 /* PQstatus Returns the status of the connection. The status can be
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
858 CONNECTION_OK or CONNECTION_BAD.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
859 ConnStatusType PQstatus(PGconn *conn)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
860 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
861 switch ((cst = PQstatus (P)))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
862 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
863 case CONNECTION_OK: return Qpg_connection_ok;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
864 case CONNECTION_BAD: return Qpg_connection_bad;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
865 #ifdef HAVE_POSTGRESQLV7
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
866 case CONNECTION_STARTED: return Qpg_connection_started;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
867 case CONNECTION_MADE: return Qpg_connection_made;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
868 case CONNECTION_AWAITING_RESPONSE: return Qpg_connection_awaiting_response;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
869 case CONNECTION_AUTH_OK: return Qpg_connection_auth_ok;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
870 case CONNECTION_SETENV: return Qpg_connection_setenv;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
871 #endif /* HAVE_POSTGRESQLV7 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
872 default:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
873 /* they've added a new field we don't know about */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
874 signal_ferror (Qprocess_error, "Help! Unknown connection status code %08x from backend!", cst);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
875 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
876 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
877 else if (EQ (field, Qpqerrormessage))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
878 /* PQerrorMessage Returns the error message most recently generated
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
879 by an operation on the connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
880 char *PQerrorMessage(PGconn* conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
881 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
882 return build_ext_string (PQerrorMessage(P), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
883 else if (EQ (field, Qpqbackendpid))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
884 /* PQbackendPID Returns the process ID of the backend server handling
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
885 this connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
886 int PQbackendPID(PGconn *conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
887 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
888 return make_int (PQbackendPID(P));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
889 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
890 signal_error (Qinvalid_argument, "bad PGconn accessor", Qunbound);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
891 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
892
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
893 /* Query functions */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
894 DEFUN ("pq-exec", Fpq_exec, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
895 Submit a query to Postgres and wait for the result.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
896 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
897 (conn, query))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
898 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
899 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
900 Lisp_PGresult *lisp_pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
901 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
902 char *c_query;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
903
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
904 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
905 CHECK_STRING (query);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
906
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
907 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
908 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
909
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
910 TO_EXTERNAL_FORMAT (LISP_STRING, query,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
911 C_STRING_ALLOCA, c_query, Qnative);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
912
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
913 R = PQexec (P, c_query);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
914 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
915 char *tag, buf[BLCKSZ];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
916
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
917 if (!R) out_of_memory ("query: out of memory", Qunbound);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
918 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
919 switch (PQresultStatus (R))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
920 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
921 case PGRES_BAD_RESPONSE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
922 tag = "bad response [%s]";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
923 goto err;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
924 case PGRES_NONFATAL_ERROR:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
925 tag = "non-fatal error [%s]";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
926 goto err;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
927 case PGRES_FATAL_ERROR:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
928 tag = "fatal error [%s]";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
929 err:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
930 strncpy (buf, PQresultErrorMessage (R), sizeof (buf));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
931 buf [sizeof (buf) - 1] = '\0';
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
932 PQclear (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
933 signal_ferror (Qprocess_error, tag, buf);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
934 /*NOTREACHED*/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
935 default:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
936 break;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
937 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
938 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
939
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
940 lisp_pgresult = allocate_pgresult ();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
941 lisp_pgresult->pgresult = R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
942
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
943 return make_pgresult (lisp_pgresult);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
944 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
945
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
946 DEFUN ("pq-send-query", Fpq_send_query, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
947 Submit a query to Postgres and don't wait for the result.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
948 Returns: t if successfully submitted
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
949 nil if error (conn->errorMessage is set)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
950 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
951 (conn, query))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
952 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
953 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
954 char *c_query;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
955
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
956 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
957 CHECK_STRING (query);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
958
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
959 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
960 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
961
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
962 TO_EXTERNAL_FORMAT (LISP_STRING, query,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
963 C_STRING_ALLOCA, c_query, Qnative);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
964
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
965 if (PQsendQuery (P, c_query)) return Qt;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
966 else signal_ferror (Qprocess_error, "async query: %s", PQerrorMessage (P));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
967 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
968
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
969 DEFUN ("pq-get-result", Fpq_get_result, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
970 Retrieve an asynchronous result from a query.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
971 NIL is returned when no more query work remains.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
972 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
973 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
974 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
975 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
976 Lisp_PGresult *lisp_pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
977 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
978
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
979 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
980
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
981 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
982 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
983
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
984 R = PQgetResult (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
985 if (!R) return Qnil; /* not an error, there's no more data to get */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
986
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
987 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
988 char *tag, buf[BLCKSZ];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
989
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
990 switch (PQresultStatus (R))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
991 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
992 case PGRES_BAD_RESPONSE:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
993 tag = "bad response [%s]";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
994 goto err;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
995 case PGRES_NONFATAL_ERROR:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
996 tag = "non-fatal error [%s]";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
997 goto err;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
998 case PGRES_FATAL_ERROR:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
999 tag = "fatal error [%s]";
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1000 err:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1001 strncpy (buf, PQresultErrorMessage (R), sizeof (buf));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1002 buf[sizeof (buf) - 1] = '\0';
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1003 PQclear (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1004 signal_ferror (Qprocess_error, tag, buf);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1005 /*NOTREACHED*/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1006 default:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1007 break;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1008 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1009 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1010
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1011 lisp_pgresult = allocate_pgresult();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1012 lisp_pgresult->pgresult = R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1013
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1014 return make_pgresult (lisp_pgresult);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1015 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1016
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1017 DEFUN ("pq-result-status", Fpq_result_status, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1018 Return result status of the query.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1019 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1020 (result))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1021 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1022 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1023 ExecStatusType est;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1024
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1025 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1026 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1027 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1028
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1029 switch ((est = PQresultStatus (R))) {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1030 case PGRES_EMPTY_QUERY: return Qpgres_empty_query;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1031 case PGRES_COMMAND_OK: return Qpgres_command_ok;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1032 case PGRES_TUPLES_OK: return Qpgres_tuples_ok;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1033 case PGRES_COPY_OUT: return Qpgres_copy_out;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1034 case PGRES_COPY_IN: return Qpgres_copy_in;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1035 case PGRES_BAD_RESPONSE: return Qpgres_bad_response;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1036 case PGRES_NONFATAL_ERROR: return Qpgres_nonfatal_error;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1037 case PGRES_FATAL_ERROR: return Qpgres_fatal_error;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1038 default:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1039 /* they've added a new field we don't know about */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1040 signal_ferror (Qprocess_error, "Help! Unknown exec status code %08x from backend!", est);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1041 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1042 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1043
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1044 DEFUN ("pq-res-status", Fpq_res_status, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1045 Return stringified result status of the query.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1046 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1047 (result))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1048 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1049 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1050
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1051 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1052 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1053 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1054
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1055 return build_ext_string (PQresStatus (PQresultStatus (R)), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1056 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1057
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1058 /* Sundry PGresult accessor functions */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1059 DEFUN ("pq-result-error-message", Fpq_result_error_message, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1060 Return last message associated with the query.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1061 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1062 (result))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1063 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1064 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1065
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1066 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1067 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1068 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1069
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1070 return build_ext_string (PQresultErrorMessage (R), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1071 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1072
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1073 DEFUN ("pq-ntuples", Fpq_ntuples, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1074 Return the number of tuples (instances) in the query result.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1075 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1076 (result))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1077 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1078 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1079
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1080 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1081 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1082 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1083
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1084 return make_int (PQntuples (R));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1085 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1086
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1087 DEFUN ("pq-nfields", Fpq_nfields, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1088 Return the number of fields (attributes) in each tuple of the query result.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1089 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1090 (result))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1091 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1092 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1093
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1094 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1095 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1096 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1097
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1098 return make_int (PQnfields (R));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1099 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1100
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1101 DEFUN ("pq-binary-tuples", Fpq_binary_tuples, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1102 Return t if the query result contains binary data, nil otherwise.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1103 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1104 (result))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1105 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1106 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1107
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1108 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1109 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1110 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1111
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1112 return (PQbinaryTuples (R)) ? Qt : Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1113 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1114
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1115 DEFUN ("pq-fname", Fpq_fname, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1116 Return the field (attribute) name associated with the given field index.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1117 Field indices start at 0.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1118 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1119 (result, field_index))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1120 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1121 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1122
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1123 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1124 CHECK_INT (field_index);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1125 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1126 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1127
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1128 return build_ext_string (PQfname (R, XINT (field_index)), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1129 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1130
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1131 DEFUN ("pq-fnumber", Fpq_fnumber, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1132 Return the number of fields (attributes) in each tuple of the query result.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1133 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1134 (result, field_name))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1135 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1136 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1137 char *c_field_name;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1138
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1139 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1140 CHECK_STRING (field_name);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1141 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1142 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1143
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1144 TO_EXTERNAL_FORMAT (LISP_STRING, field_name,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1145 C_STRING_ALLOCA, c_field_name, Qnative);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1146
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1147 return make_int (PQfnumber (R, c_field_name));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1148 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1149
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1150 DEFUN ("pq-ftype", Fpq_ftype, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1151 Return the field type associated with the given field index.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1152 The integer returned is the internal coding of the type. Field indices
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1153 start at 0.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1154 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1155 (result, field_num))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1156 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1157 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1158
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1159 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1160 CHECK_INT (field_num);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1161 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1162 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1163
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1164 return make_int (PQftype (R, XINT (field_num)));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1165 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1166
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1167 DEFUN ("pq-fsize", Fpq_fsize, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1168 Return the field size in bytes associated with the given field index.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1169 Field indices start at 0.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1170 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1171 (result, field_index))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1172 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1173 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1174
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1175 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1176 CHECK_INT (field_index);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1177 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1178 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1179
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1180 return make_int (PQftype (R, XINT (field_index)));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1181 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1182
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1183 DEFUN ("pq-fmod", Fpq_fmod, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1184 Return the type modifier associated with a field.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1185 Field indices start at 0.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1186 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1187 (result, field_index))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1188 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1189 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1190
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1191 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1192 CHECK_INT (field_index);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1193 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1194 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1195
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1196 return make_int (PQfmod (R, XINT (field_index)));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1197 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1198
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1199 DEFUN ("pq-get-value", Fpq_get_value, 3, 3, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1200 Return a single field (attribute) value of one tuple of a PGresult.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1201 Tuple and field indices start at 0.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1202 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1203 (result, tup_num, field_num))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1204 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1205 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1206
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1207 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1208 CHECK_INT (tup_num);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1209 CHECK_INT (field_num);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1210 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1211 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1212
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1213 return build_ext_string (PQgetvalue (R, XINT (tup_num), XINT (field_num)),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1214 PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1215 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1216
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1217 DEFUN ("pq-get-length", Fpq_get_length, 3, 3, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1218 Returns the length of a field value in bytes.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1219 If result is binary, i.e. a result of a binary portal, then the
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1220 length returned does NOT include the size field of the varlena. (The
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1221 data returned by PQgetvalue doesn't either.)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1222 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1223 (result, tup_num, field_num))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1224 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1225 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1226
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1227 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1228 CHECK_INT (tup_num);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1229 CHECK_INT (field_num);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1230 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1231 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1232
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1233 return make_int (PQgetlength (R, XINT (tup_num), XINT (field_num)));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1234 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1235
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1236 DEFUN ("pq-get-is-null", Fpq_get_is_null, 3, 3, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1237 Returns the null status of a field value.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1238 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1239 (result, tup_num, field_num))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1240 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1241 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1242
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1243 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1244 CHECK_INT (tup_num);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1245 CHECK_INT (field_num);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1246 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1247 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1248
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1249 return PQgetisnull (R, XINT (tup_num), XINT (field_num)) ? Qt : Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1250 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1251
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1252 DEFUN ("pq-cmd-status", Fpq_cmd_status, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1253 Returns the command status string from the SQL command that generated the result.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1254 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1255 (result))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1256 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1257 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1258
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1259 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1260 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1261 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1262
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1263 return build_ext_string (PQcmdStatus (R), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1264 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1265
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1266 DEFUN ("pq-cmd-tuples", Fpq_cmd_tuples, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1267 Returns the number of rows affected by the SQL command.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1268 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1269 (result))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1270 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1271 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1272
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1273 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1274 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1275 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1276
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1277 return build_ext_string (PQcmdTuples (R), PG_OS_CODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1278 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1279
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1280 DEFUN ("pq-oid-value", Fpq_oid_value, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1281 Returns the object id of the tuple inserted.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1282 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1283 (result))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1284 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1285 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1286
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1287 CHECK_PGRESULT (result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1288 R = (XPGRESULT (result))->pgresult;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1289 PUKE_IF_NULL (R);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1290
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1291 #ifdef HAVE_POSTGRESQLV7
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1292 return make_int (PQoidValue (R));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1293 #else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1294 /* Use the old interface */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1295 return make_int (atoi (PQoidStatus (R)));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1296 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1297 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1298
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1299 #ifdef HAVE_POSTGRESQLV7
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1300 DEFUN ("pq-set-nonblocking", Fpq_set_nonblocking, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1301 Sets the PGconn's database connection non-blocking if the arg is TRUE
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1302 or makes it non-blocking if the arg is FALSE, this will not protect
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1303 you from PQexec(), you'll only be safe when using the non-blocking API.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1304
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1305 Needs to be called only on a connected database connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1306 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1307 (conn, arg))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1308 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1309 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1310
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1311 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1312 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1313 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1314
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1315 return make_int (PQsetnonblocking (P, !NILP (arg)));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1316 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1317
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1318 DEFUN ("pq-is-nonblocking", Fpq_is_nonblocking, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1319 Return the blocking status of the database connection.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1320 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1321 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1322 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1323 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1324
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1325 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1326 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1327 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1328
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1329 return PQisnonblocking (P) ? Qt : Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1330 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1331
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1332 DEFUN ("pq-flush", Fpq_flush, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1333 Force the write buffer to be written (or at least try).
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1334 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1335 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1336 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1337 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1338
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1339 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1340 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1341 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1342
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1343 return make_int (PQflush (P));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1344 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1345 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1346
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1347 DEFUN ("pq-notifies", Fpq_notifies, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1348 Return the latest async notification that has not yet been handled.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1349 If there has been a notification, then a list of two elements will be returned.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1350 The first element contains the relation name being notified, the second
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1351 element contains the backend process ID number. nil is returned if there
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1352 aren't any notifications to process.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1353 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1354 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1355 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1356 /* This function cannot GC */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1357 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1358 PGnotify *PGN;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1359
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1360 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1361 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1362 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1363
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1364 PGN = PQnotifies (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1365 if (!PGN)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1366 return Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1367 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1368 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1369 Lisp_Object temp;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1370
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1371 temp = list2 (build_ext_string (PGN->relname, PG_OS_CODING), make_int (PGN->be_pid));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1372 free ((void *)PGN);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1373 return temp;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1374 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1375 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1376
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1377 #if defined (HAVE_POSTGRESQLV7) && defined(MULE)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1378 /* ###autoload */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1379 DEFUN ("pq-env-2-encoding", Fpq_env_2_encoding, 0, 0, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1380 Get encoding id from environment variable PGCLIENTENCODING.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1381 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1382 ())
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1383 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1384 return make_int (PQenv2encoding ());
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1385 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1386 #endif /* MULE */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1387
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1388 DEFUN ("pq-lo-import", Fpq_lo_import, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1389 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1390 (conn, filename))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1391 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1392 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1393 char *c_filename;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1394
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1395 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1396 CHECK_STRING (filename);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1397
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1398 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1399 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1400
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1401 TO_EXTERNAL_FORMAT (LISP_STRING, filename,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1402 C_STRING_ALLOCA, c_filename,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1403 Qfile_name);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1404
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1405 return make_int ((int)lo_import (P, c_filename));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1406 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1407
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1408 DEFUN ("pq-lo-export", Fpq_lo_export, 3, 3, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1409 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1410 (conn, oid, filename))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1411 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1412 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1413 char *c_filename;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1414
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1415 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1416 CHECK_INT (oid);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1417 CHECK_STRING (filename);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1418
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1419 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1420 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1421
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1422 TO_EXTERNAL_FORMAT (LISP_STRING, filename,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1423 C_STRING_ALLOCA, c_filename, Qfile_name);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1424
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1425 return make_int ((int)lo_export (P, XINT (oid), c_filename));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1426 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1427
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1428 DEFUN ("pq-make-empty-pgresult", Fpq_make_empty_pgresult, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1429 Make an empty PGresult object with the given status.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1430 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1431 (conn, status))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1432 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1433 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1434 Lisp_PGresult *lpgr;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1435 PGresult *R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1436 ExecStatusType est;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1437
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1438 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1439 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1440 CHECK_LIVE_CONNECTION (P); /* needed here? */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1441
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1442 if (EQ (status, Qpgres_empty_query)) est = PGRES_EMPTY_QUERY;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1443 else if (EQ (status, Qpgres_command_ok)) est = PGRES_COMMAND_OK;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1444 else if (EQ (status, Qpgres_tuples_ok)) est = PGRES_TUPLES_OK;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1445 else if (EQ (status, Qpgres_copy_out)) est = PGRES_COPY_OUT;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1446 else if (EQ (status, Qpgres_copy_in)) est = PGRES_COPY_IN;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1447 else if (EQ (status, Qpgres_bad_response)) est = PGRES_BAD_RESPONSE;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1448 else if (EQ (status, Qpgres_nonfatal_error)) est = PGRES_NONFATAL_ERROR;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1449 else if (EQ (status, Qpgres_fatal_error)) est = PGRES_FATAL_ERROR;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1450 else invalid_constant ("bad status symbol", status);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1451
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1452 R = PQmakeEmptyPGresult (P, est);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1453 if (!R) out_of_memory (0, Qunbound);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1454
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1455 lpgr = allocate_pgresult ();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1456 lpgr->pgresult = R;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1457
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1458 return make_pgresult (lpgr);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1459 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1460
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1461 DEFUN ("pq-get-line", Fpq_get_line, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1462 Retrieve a line from server in copy in operation.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1463 The return value is a dotted pair where the cons cell is an integer code:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1464 -1: Copying is complete
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1465 0: A record is complete
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1466 1: A record is incomplete, it will be continued in the next `pq-get-line'
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1467 operation.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1468 and the cdr cell is returned string data.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1469
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1470 The copy operation is complete when the value `\.' (backslash dot) is
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1471 returned.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1472 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1473 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1474 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1475 char buffer[BLCKSZ]; /* size of a Postgres disk block */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1476 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1477 int ret;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1478
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1479 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1480 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1481 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1482
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1483 ret = PQgetline (P, buffer, sizeof (buffer));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1484
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1485 return Fcons (make_int (ret), build_ext_string (buffer, PG_OS_CODING));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1486 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1487
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1488 DEFUN ("pq-put-line", Fpq_put_line, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1489 Send a line to the server in copy out operation.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1490
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1491 Returns t if the operation succeeded, nil otherwise.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1492 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1493 (conn, string))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1494 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1495 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1496 char *c_string;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1497
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1498 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1499 CHECK_STRING (string);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1500
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1501 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1502 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1503 TO_EXTERNAL_FORMAT (LISP_STRING, string,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1504 C_STRING_ALLOCA, c_string, Qnative);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1505
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1506 return !PQputline (P, c_string) ? Qt : Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1507 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1508
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1509 DEFUN ("pq-get-line-async", Fpq_get_line_async, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1510 Get a line from the server in copy in operation asynchronously.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1511
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1512 This routine is for applications that want to do "COPY <rel> to stdout"
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1513 asynchronously, that is without blocking. Having issued the COPY command
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1514 and gotten a PGRES_COPY_OUT response, the app should call PQconsumeInput
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1515 and this routine until the end-of-data signal is detected. Unlike
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1516 PQgetline, this routine takes responsibility for detecting end-of-data.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1517
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1518 On each call, PQgetlineAsync will return data if a complete newline-
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1519 terminated data line is available in libpq's input buffer, or if the
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1520 incoming data line is too long to fit in the buffer offered by the caller.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1521 Otherwise, no data is returned until the rest of the line arrives.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1522
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1523 If -1 is returned, the end-of-data signal has been recognized (and removed
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1524 from libpq's input buffer). The caller *must* next call PQendcopy and
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1525 then return to normal processing.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1526
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1527 RETURNS:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1528 -1 if the end-of-copy-data marker has been recognized
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1529 0 if no data is available
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1530 >0 the number of bytes returned.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1531 The data returned will not extend beyond a newline character. If possible
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1532 a whole line will be returned at one time. But if the buffer offered by
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1533 the caller is too small to hold a line sent by the backend, then a partial
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1534 data line will be returned. This can be detected by testing whether the
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1535 last returned byte is '\n' or not.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1536 The returned string is *not* null-terminated.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1537 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1538 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1539 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1540 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1541 char buffer[BLCKSZ];
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1542 int ret;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1543
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1544 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1545
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1546 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1547 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1548
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1549 ret = PQgetlineAsync (P, buffer, sizeof (buffer));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1550
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1551 if (ret == -1) return Qt; /* done! */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1552 else if (!ret) return Qnil; /* no data yet */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1553 else return Fcons (make_int (ret),
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1554 make_ext_string ((Extbyte *) buffer, ret, PG_OS_CODING));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1555 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1556
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1557 DEFUN ("pq-put-nbytes", Fpq_put_nbytes, 2, 2, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1558 Asynchronous copy out.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1559 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1560 (conn, data))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1561 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1562 /* NULs are not allowed. I don't think this matters at this time. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1563 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1564 char *c_data;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1565
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1566 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1567 CHECK_STRING (data);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1568
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1569 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1570 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1571 TO_EXTERNAL_FORMAT (LISP_STRING, data,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1572 C_STRING_ALLOCA, c_data, Qnative);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1573
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1574 return !PQputnbytes (P, c_data, strlen (c_data)) ? Qt : Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1575 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1576
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1577 DEFUN ("pq-end-copy", Fpq_end_copy, 1, 1, 0, /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1578 End a copying operation.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1579 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1580 (conn))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1581 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1582 PGconn *P;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1583
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1584 CHECK_PGCONN (conn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1585 P = (XPGCONN (conn))->pgconn;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1586 CHECK_LIVE_CONNECTION (P);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1587
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1588 return PQendcopy (P) ? Qt : Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1589 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1590
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1591 void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1592 syms_of_postgresql(void)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1593 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1594 #ifndef RUNNING_XEMACS_21_1
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1595 INIT_LRECORD_IMPLEMENTATION (pgconn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1596 INIT_LRECORD_IMPLEMENTATION (pgresult);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1597 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1598 DEFSYMBOL (Qpostgresql);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1599
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1600 /* opaque exported types */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1601 DEFSYMBOL (Qpgconnp);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1602 DEFSYMBOL (Qpgresultp);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1603
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1604 /* connection status types */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1605 defsymbol (&Qpg_connection_ok, "pg::connection-ok");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1606 defsymbol (&Qpg_connection_bad, "pg::connection-bad");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1607 defsymbol (&Qpg_connection_started, "pg::connection-started");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1608 defsymbol (&Qpg_connection_made, "pg::connection-made");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1609 defsymbol (&Qpg_connection_awaiting_response, "pg::connection-awaiting-response");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1610 defsymbol (&Qpg_connection_auth_ok, "pg::connection-auth-ok");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1611 defsymbol (&Qpg_connection_setenv, "pg::connection-setenv");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1612
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1613 /* Fields of PGconn */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1614 defsymbol (&Qpqdb, "pq::db");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1615 defsymbol (&Qpquser, "pq::user");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1616 defsymbol (&Qpqpass, "pq::pass");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1617 defsymbol (&Qpqhost, "pq::host");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1618 defsymbol (&Qpqport, "pq::port");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1619 defsymbol (&Qpqtty, "pq::tty");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1620 defsymbol (&Qpqoptions, "pq::options");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1621 defsymbol (&Qpqstatus, "pq::status");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1622 defsymbol (&Qpqerrormessage, "pq::error-message");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1623 defsymbol (&Qpqbackendpid, "pq::backend-pid");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1624
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1625 /* Query status results */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1626 defsymbol (&Qpgres_empty_query, "pgres::empty-query");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1627 defsymbol (&Qpgres_command_ok, "pgres::command-ok");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1628 defsymbol (&Qpgres_tuples_ok, "pgres::tuples-ok");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1629 defsymbol (&Qpgres_copy_out, "pgres::copy-out");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1630 defsymbol (&Qpgres_copy_in, "pgres::copy-in");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1631 defsymbol (&Qpgres_bad_response, "pgres::bad-response");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1632 defsymbol (&Qpgres_nonfatal_error, "pgres::nonfatal-error");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1633 defsymbol (&Qpgres_fatal_error, "pgres::fatal-error");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1634
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1635 /* Poll status results */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1636 defsymbol (&Qpgres_polling_failed, "pgres::polling-failed");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1637 defsymbol (&Qpgres_polling_reading, "pgres::polling-reading");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1638 defsymbol (&Qpgres_polling_writing, "pgres::polling-writing");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1639 defsymbol (&Qpgres_polling_ok, "pgres::polling-ok");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1640 defsymbol (&Qpgres_polling_active, "pgres::polling-active");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1641
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1642 #ifdef HAVE_POSTGRESQLV7
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1643 DEFSUBR (Fpq_connect_start);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1644 DEFSUBR (Fpq_connect_poll);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1645 #ifdef MULE
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1646 DEFSUBR (Fpq_client_encoding);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1647 DEFSUBR (Fpq_set_client_encoding);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1648 #endif /* MULE */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1649 #endif /* HAVE_POSTGRESQLV7 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1650 DEFSUBR (Fpq_conn_defaults);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1651 DEFSUBR (Fpq_connectdb);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1652 DEFSUBR (Fpq_finish);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1653 DEFSUBR (Fpq_clear);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1654 DEFSUBR (Fpq_is_busy);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1655 DEFSUBR (Fpq_consume_input);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1656
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1657 DEFSUBR (Fpq_reset);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1658 #ifdef HAVE_POSTGRESQLV7
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1659 DEFSUBR (Fpq_reset_start);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1660 DEFSUBR (Fpq_reset_poll);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1661 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1662 DEFSUBR (Fpq_request_cancel);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1663 DEFSUBR (Fpq_pgconn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1664
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1665 DEFSUBR (Fpq_exec);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1666 DEFSUBR (Fpq_send_query);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1667 DEFSUBR (Fpq_get_result);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1668 DEFSUBR (Fpq_result_status);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1669 DEFSUBR (Fpq_res_status);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1670 DEFSUBR (Fpq_result_error_message);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1671 DEFSUBR (Fpq_ntuples);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1672 DEFSUBR (Fpq_nfields);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1673 DEFSUBR (Fpq_binary_tuples);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1674 DEFSUBR (Fpq_fname);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1675 DEFSUBR (Fpq_fnumber);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1676 DEFSUBR (Fpq_ftype);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1677 DEFSUBR (Fpq_fsize);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1678 DEFSUBR (Fpq_fmod);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1679 /***/
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1680 DEFSUBR (Fpq_get_value);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1681 DEFSUBR (Fpq_get_length);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1682 DEFSUBR (Fpq_get_is_null);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1683 DEFSUBR (Fpq_cmd_status);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1684 DEFSUBR (Fpq_cmd_tuples);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1685 DEFSUBR (Fpq_oid_value);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1686
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1687 #ifdef HAVE_POSTGRESQLV7
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1688 DEFSUBR (Fpq_set_nonblocking);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1689 DEFSUBR (Fpq_is_nonblocking);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1690 DEFSUBR (Fpq_flush);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1691 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1692 DEFSUBR (Fpq_notifies);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1693
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1694 #if defined (HAVE_POSTGRESQLV7) && defined(MULE)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1695 DEFSUBR (Fpq_env_2_encoding);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1696 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1697
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1698 DEFSUBR (Fpq_lo_import);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1699 DEFSUBR (Fpq_lo_export);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1700
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1701 DEFSUBR (Fpq_make_empty_pgresult);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1702
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1703 /* copy in/out functions */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1704 DEFSUBR (Fpq_get_line);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1705 DEFSUBR (Fpq_put_line);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1706 DEFSUBR (Fpq_get_line_async);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1707 DEFSUBR (Fpq_put_nbytes);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1708 DEFSUBR (Fpq_end_copy);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1709 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1710
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1711 void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1712 vars_of_postgresql(void)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1713 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1714 Fprovide (Qpostgresql);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1715 #ifdef HAVE_POSTGRESQLV7
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1716 Fprovide (intern ("postgresqlv7"));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1717 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1718 #ifndef RUNNING_XEMACS_21_1
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1719 Vpg_coding_system = Qnative;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1720 DEFVAR_LISP ("pg-coding-system", &Vpg_coding_system /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1721 Default Postgres client coding system.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1722 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1723 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1724
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1725 DEFVAR_LISP ("pg:host", &VXPGHOST /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1726 Default PostgreSQL server name.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1727 If not set, the server running on the local host is used. The
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1728 initial value is set from the PGHOST environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1729 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1730
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1731 DEFVAR_LISP ("pg:user", &VXPGUSER /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1732 Default PostgreSQL user name.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1733 This value is used when connecting to a database for authentication.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1734 The initial value is set from the PGUSER environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1735 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1736
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1737 DEFVAR_LISP ("pg:options", &VXPGOPTIONS /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1738 Default PostgreSQL user name.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1739 This value is used when connecting to a database for authentication.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1740 The initial value is set from the PGUSER environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1741 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1742
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1743 DEFVAR_LISP ("pg:port", &VXPGPORT /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1744 Default port to connect to PostgreSQL backend.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1745 This value is used when connecting to a database.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1746 The initial value is set from the PGPORT environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1747 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1748
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1749 DEFVAR_LISP ("pg:tty", &VXPGTTY /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1750 Default debugging TTY.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1751 There is no useful setting of this variable in the XEmacs Lisp API.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1752 The initial value is set from the PGTTY environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1753 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1754
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1755 DEFVAR_LISP ("pg:database", &VXPGDATABASE /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1756 Default database to connect to.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1757 The initial value is set from the PGDATABASE environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1758 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1759
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1760 DEFVAR_LISP ("pg:realm", &VXPGREALM /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1761 Default kerberos realm to use for authentication.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1762 The initial value is set from the PGREALM environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1763 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1764
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1765 #ifdef MULE
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1766 /* It's not clear whether this is any use. My intent is to
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1767 autodetect the coding system from the database. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1768 DEFVAR_LISP ("pg:client-encoding", &VXPGCLIENTENCODING /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1769 Default client encoding to use.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1770 The initial value is set from the PGCLIENTENCODING environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1771 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1772 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1773
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1774 #if !defined(HAVE_POSTGRESQLV7)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1775 DEFVAR_LISP ("pg:authtype", &VXPGAUTHTYPE /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1776 Default authentication to use.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1777 The initial value is set from the PGAUTHTYPE environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1778
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1779 WARNING: This variable has gone away in versions of PostgreSQL newer
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1780 than 6.5.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1781 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1782 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1783
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1784 DEFVAR_LISP ("pg:geqo", &VXPGGEQO /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1785 Genetic Query Optimizer options.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1786 The initial value is set from the PGGEQO environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1787 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1788
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1789 DEFVAR_LISP ("pg:cost-index", &VXPGCOSTINDEX /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1790 Default cost index options.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1791 The initial value is set from the PGCOSTINDEX environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1792 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1793
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1794 DEFVAR_LISP ("pg:cost-heap", &VXPGCOSTHEAP /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1795 Default cost heap options.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1796 The initial value is set from the PGCOSTHEAP environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1797 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1798
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1799 DEFVAR_LISP ("pg:tz", &VXPGTZ /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1800 Default timezone to use.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1801 The initial value is set from the PGTZ environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1802 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1803
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1804 DEFVAR_LISP ("pg:date-style", &VXPGDATESTYLE /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1805 Default date style to use.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1806 The initial value is set from the PGDATESTYLE environment variable.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1807 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1808
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1809 #ifdef HAVE_SHLIB
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1810 /* If we are building this as a module, we need the initializing function to
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1811 run at module load time. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1812 init_postgresql_from_environment ();
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1813 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1814 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1815
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1816 /* These initializations should not be done at dump-time. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1817 void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1818 init_postgresql_from_environment (void)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1819 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1820 Ibyte *p;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1821
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1822 #define FROB(envvar, var) \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1823 if ((p = egetenv (envvar))) \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1824 var = build_intstring (p); \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1825 else \
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1826 var = Qnil
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1827
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1828 if (initialized)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1829 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1830 FROB ("PGHOST", VXPGHOST);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1831 FROB ("PGUSER", VXPGUSER);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1832 FROB ("PGOPTIONS", VXPGOPTIONS);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1833
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1834 if ((p = egetenv ("PGPORT")))
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1835 VXPGPORT = make_int (atoi ((char *) p));
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1836 else
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1837 VXPGPORT = Qnil;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1838
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1839 FROB ("PGTTY", VXPGTTY);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1840 FROB ("PGDATABASE", VXPGDATABASE);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1841 FROB ("PGREALM", VXPGREALM);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1842 #ifdef MULE
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1843 /* It's not clear whether this is any use. My intent is to
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1844 autodetect the coding system from the database. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1845 FROB ("PGCLIENTENCODING", VXPGCLIENTENCODING);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1846 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1847
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1848 #if !defined(HAVE_POSTGRESQLV7)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1849 FROB ("PGAUTHTYPE", VXPGAUTHTYPE);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1850 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1851
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1852 FROB ("PGGEQO", VXPGGEQO);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1853 FROB ("PGCOSTINDEX", VXPGCOSTINDEX);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1854 FROB ("PGCOSTHEAP", VXPGCOSTHEAP);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1855 FROB ("PGTZ", VXPGTZ);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1856 FROB ("PGDATESTYLE", VXPGDATESTYLE);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1857 #undef FROB
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1858 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1859 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1860
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1861 #ifdef HAVE_SHLIB
1111
184461bc8de4 [xemacs-hg @ 2002-11-18 06:52:23 by ben]
ben
parents: 996
diff changeset
1862 void unload_postgresql (void);
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1863 void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1864 unload_postgresql (void)
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1865 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1866 #ifndef RUNNING_XEMACS_21_1
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1867 /* Remove defined types */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1868 UNDEF_LRECORD_IMPLEMENTATION (pgconn);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1869 UNDEF_LRECORD_IMPLEMENTATION (pgresult);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1870 #endif
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1871
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1872 /* Remove staticpro'ing of symbols */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1873 unstaticpro_nodump (&Qpostgresql);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1874 unstaticpro_nodump (&Qpgconnp);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1875 unstaticpro_nodump (&Qpgresultp);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1876 unstaticpro_nodump (&Qpg_connection_ok);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1877 unstaticpro_nodump (&Qpg_connection_bad);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1878 unstaticpro_nodump (&Qpg_connection_started);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1879 unstaticpro_nodump (&Qpg_connection_made);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1880 unstaticpro_nodump (&Qpg_connection_awaiting_response);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1881 unstaticpro_nodump (&Qpg_connection_auth_ok);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1882 unstaticpro_nodump (&Qpg_connection_setenv);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1883 unstaticpro_nodump (&Qpqdb);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1884 unstaticpro_nodump (&Qpquser);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1885 unstaticpro_nodump (&Qpqpass);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1886 unstaticpro_nodump (&Qpqhost);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1887 unstaticpro_nodump (&Qpqport);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1888 unstaticpro_nodump (&Qpqtty);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1889 unstaticpro_nodump (&Qpqoptions);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1890 unstaticpro_nodump (&Qpqstatus);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1891 unstaticpro_nodump (&Qpqerrormessage);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1892 unstaticpro_nodump (&Qpqbackendpid);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1893 unstaticpro_nodump (&Qpgres_empty_query);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1894 unstaticpro_nodump (&Qpgres_command_ok);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1895 unstaticpro_nodump (&Qpgres_tuples_ok);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1896 unstaticpro_nodump (&Qpgres_copy_out);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1897 unstaticpro_nodump (&Qpgres_copy_in);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1898 unstaticpro_nodump (&Qpgres_bad_response);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1899 unstaticpro_nodump (&Qpgres_nonfatal_error);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1900 unstaticpro_nodump (&Qpgres_fatal_error);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1901 unstaticpro_nodump (&Qpgres_polling_failed);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1902 unstaticpro_nodump (&Qpgres_polling_reading);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1903 unstaticpro_nodump (&Qpgres_polling_writing);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1904 unstaticpro_nodump (&Qpgres_polling_ok);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1905 unstaticpro_nodump (&Qpgres_polling_active);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1906 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1907 #endif /* HAVE_SHLIB */