annotate src/postgresql.c @ 908:aa5bf79c0076

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