annotate src/postgresql.c @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents 183866b06e0b
children e38acbeb1cae
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"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
101 #include "buffer.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
102 #include "postgresql.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
103
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
104 #ifdef RUNNING_XEMACS_21_1 /* handle interface changes */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
105 #define PG_OS_CODING FORMAT_FILENAME
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
106 #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
107 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
108 #ifdef MULE
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
109 #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
110 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
111 #define PG_OS_CODING Qnative
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
112 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
113 Lisp_Object Vpg_coding_system;
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
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
116 #define CHECK_LIVE_CONNECTION(P) do { \
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
117 if (!P || (PQstatus (P) != CONNECTION_OK)) { \
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
118 char *e = "bad value"; \
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
119 if (P) e = PQerrorMessage (P); \
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
120 signal_ferror (Qprocess_error, "dead connection [%s]", e); \
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
121 } } while (0)
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
122 #define PUKE_IF_NULL(p) do { \
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
123 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
124 } while (0)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
125
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
126 static Lisp_Object VXPGHOST;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
127 static Lisp_Object VXPGUSER;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
128 static Lisp_Object VXPGOPTIONS;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
129 static Lisp_Object VXPGPORT;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
130 static Lisp_Object VXPGTTY; /* This needs to be blanked! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
131 static Lisp_Object VXPGDATABASE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
132 static Lisp_Object VXPGREALM;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
133 #ifdef MULE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
134 static Lisp_Object VXPGCLIENTENCODING;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
135 #endif /* MULE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
136
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
137 /* Other variables:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
138 PGAUTHTYPE -- not used after PostgreSQL 6.5
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
139 PGGEQO
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
140 PGCOSTINDEX
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
141 PGCOSTHEAP
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
142 PGTZ
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
143 PGDATESTYLE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
144 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
145 #ifndef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
146 static Lisp_Object VXPGAUTHTYPE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
147 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
148 static Lisp_Object VXPGGEQO, VXPGCOSTINDEX, VXPGCOSTHEAP, VXPGTZ, VXPGDATESTYLE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
149
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
150 static Lisp_Object Qpostgresql;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
151 static Lisp_Object Qpg_connection_ok, Qpg_connection_bad;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
152 static Lisp_Object Qpg_connection_started, Qpg_connection_made;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
153 static Lisp_Object Qpg_connection_awaiting_response, Qpg_connection_auth_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
154 static Lisp_Object Qpg_connection_setenv;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
155
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
156 static Lisp_Object Qpqdb, Qpquser, Qpqpass, Qpqhost, Qpqport, Qpqtty;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
157 static Lisp_Object Qpqoptions, Qpqstatus, Qpqerrormessage, Qpqbackendpid;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
158
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
159 static Lisp_Object Qpgres_empty_query, Qpgres_command_ok, Qpgres_tuples_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
160 static Lisp_Object Qpgres_copy_out, Qpgres_copy_in, Qpgres_bad_response;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
161 static Lisp_Object Qpgres_nonfatal_error, Qpgres_fatal_error;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
162
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
163 static Lisp_Object Qpgres_polling_failed, Qpgres_polling_reading;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
164 static Lisp_Object Qpgres_polling_writing, Qpgres_polling_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
165 static Lisp_Object Qpgres_polling_active;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
166 /****/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
167
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
168 /* 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
169 Lisp code because libpq supports multiple connections.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
170 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
171 Lisp_Object Qpgconnp;
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 static Lisp_Object
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
174 make_pgconn (Lisp_PGconn *pgconn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
175 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
176 Lisp_Object lisp_pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
177 XSETPGCONN (lisp_pgconn, pgconn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
178 return lisp_pgconn;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
225 write_c_string (buf, printcharfun);
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 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
280 Lisp_Object lisp_pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
281 XSETPGRESULT (lisp_pgresult, pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
282 return lisp_pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
283 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
284
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
285 static Lisp_Object
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
286 #ifdef RUNNING_XEMACS_21_1
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
287 mark_pgresult (Lisp_Object obj, void (*markobj) (Lisp_Object))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
288 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
289 mark_pgresult (Lisp_Object obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
290 #endif
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 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
293 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
294
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
295 #define RESULT_TUPLES_FMT "#<PGresult %s[%d] - %s>"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
296 #define RESULT_CMD_TUPLES_FMT "#<PGresult %s[%s] - %s>"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
297 #define RESULT_DEFAULT_FMT "#<PGresult %s - %s>"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
298 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
299 print_pgresult (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
300 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
301 char buf[1024];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
302 PGresult *res;
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 res = (XPGRESULT (obj))->pgresult;
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 if (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 switch (PQresultStatus (res))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
309 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
310 case PGRES_TUPLES_OK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
311 /* Add number of tuples of result to output */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
312 sprintf (buf, RESULT_TUPLES_FMT, /* evil! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
313 PQresStatus (PQresultStatus (res)),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
314 PQntuples (res),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
315 PQcmdStatus (res));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
316 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
317 case PGRES_COMMAND_OK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
318 /* Add number of tuples affected by output-less command */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
319 if (!strlen (PQcmdTuples (res))) goto notuples;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
320 sprintf (buf, RESULT_CMD_TUPLES_FMT, /* evil! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
321 PQresStatus (PQresultStatus (res)),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
322 PQcmdTuples (res),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
323 PQcmdStatus (res));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
324 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
325 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
326 notuples:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
327 /* No counts to print */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
328 sprintf (buf, RESULT_DEFAULT_FMT, /* evil! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
329 PQresStatus (PQresultStatus (res)),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
330 PQcmdStatus (res));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
331 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
332 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
333 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
334 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
335 strcpy (buf, "#<PGresult DEAD>"); /* evil! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
336
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
337 if (print_readably)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
338 printing_unreadable_object ("%s", buf);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
339 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
340 write_c_string (buf, printcharfun);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
341 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
342
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
343 #undef RESULT_TUPLES_FMT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
344 #undef RESULT_CMD_TUPLES_FMT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
345 #undef RESULT_DEFAULT_FMT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
346
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
347 static Lisp_PGresult *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
348 allocate_pgresult (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
349 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
350 #ifdef RUNNING_XEMACS_21_1
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
351 Lisp_PGresult *pgresult = alloc_lcrecord_type (Lisp_PGresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
352 lrecord_pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
353 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
354 Lisp_PGresult *pgresult = alloc_lcrecord_type (Lisp_PGresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
355 &lrecord_pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
356 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
357 pgresult->pgresult = (PGresult *)NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
358 return pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
359 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
360
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
361 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
362 finalize_pgresult (void *header, int for_disksave)
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 Lisp_PGresult *pgresult = (Lisp_PGresult *)header;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
365
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
366 if (for_disksave)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
367 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
368 make_pgresult (pgresult));
442
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 if (pgresult->pgresult)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
371 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
372 PQclear (pgresult->pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
373 pgresult->pgresult = (PGresult *)NULL;
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 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
376
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
377 #ifdef RUNNING_XEMACS_21_1
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
378 DEFINE_LRECORD_IMPLEMENTATION ("pgresult", pgresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
379 mark_pgresult, print_pgresult, finalize_pgresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
380 NULL, NULL,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
381 Lisp_PGresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
382 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
383 DEFINE_LRECORD_IMPLEMENTATION ("pgresult", pgresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
384 mark_pgresult, print_pgresult, finalize_pgresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
385 NULL, NULL,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
386 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
387 Lisp_PGresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
388 #endif
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 /***********************/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
391
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
392 /* notices */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
393 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
394 xemacs_notice_processor (void *arg, const char *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 warn_when_safe (Qpostgresql, Qnotice, "%s", msg);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
397 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
398
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
399 /* 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
400 Two of them, PQsetdb and PQsetdbLogin, are deprecated. Both of those
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
401 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
402 Note that PQconnectStart does not exist prior to v7.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
403 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
404
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
405 DEFUN ("pq-conn-defaults", Fpq_conn_defaults, 0, 0, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
406 Return a connection default structure.
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 ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
409 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
410 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
411 PQconninfoOption *pcio;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
412 Lisp_Object temp, temp1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
413 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
414
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
415 pcio = PQconndefaults();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
416 if (!pcio) return Qnil; /* can never happen in libpq-7.0 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
417 temp = list1 (Fcons (build_ext_string (pcio[0].keyword, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
418 Fcons (build_ext_string (pcio[0].envvar, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
419 Fcons (build_ext_string (pcio[0].compiled, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
420 Fcons (build_ext_string (pcio[0].val, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
421 Fcons (build_ext_string (pcio[0].label, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
422 Fcons (build_ext_string (pcio[0].dispchar, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
423 Fcons (make_int (pcio[0].dispsize), Qnil))))))));
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 for (i = 1; pcio[i].keyword; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
426 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
427 temp1 = list1 (Fcons (build_ext_string (pcio[i].keyword, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
428 Fcons (build_ext_string (pcio[i].envvar, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
429 Fcons (build_ext_string (pcio[i].compiled, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
430 Fcons (build_ext_string (pcio[i].val, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
431 Fcons (build_ext_string (pcio[i].label, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
432 Fcons (build_ext_string (pcio[i].dispchar, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
433 Fcons (make_int (pcio[i].dispsize), Qnil))))))));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
434 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
435 Lisp_Object args[2];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
436 args[0] = temp;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
437 args[1] = temp1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
438 /* Fappend GCPROs its arguments */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
439 temp = Fappend (2, args);
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 }
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 return temp;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
444 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
445
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
446 /* PQconnectdb Makes a new connection to a backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
447 PGconn *PQconnectdb(const char *conninfo)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
448 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
449
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
450 DEFUN ("pq-connectdb", Fpq_connectdb, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
451 Make a new connection to a PostgreSQL backend.
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 (conninfo))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
454 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
455 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
456 Lisp_PGconn *lisp_pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
457 char *error_message = "Out of Memory?";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
458 char *c_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 CHECK_STRING (conninfo);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
461
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
462 TO_EXTERNAL_FORMAT(LISP_STRING, conninfo,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
463 C_STRING_ALLOCA, c_conninfo, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
464 P = PQconnectdb (c_conninfo);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
465 if (P && (PQstatus (P) == CONNECTION_OK))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
466 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
467 (void)PQsetNoticeProcessor (P, xemacs_notice_processor, NULL);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
468 lisp_pgconn = allocate_pgconn();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
469 lisp_pgconn->pgconn = P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
470 return make_pgconn (lisp_pgconn);
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 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
473 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
474 /* Connection failed. Destroy the connection and signal an error. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
475 char buf[BLCKSZ];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
476 strcpy (buf, error_message);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
477 if (P)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
478 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
479 /* storage for the error message gets erased when call PQfinish */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
480 /* so we must temporarily stash it somewhere */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
481 strncpy (buf, PQerrorMessage (P), sizeof (buf));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
482 buf[sizeof (buf) - 1] = '\0';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
483 PQfinish (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
484 }
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
485 signal_ferror (Qprocess_error, "libpq: %s", buf);
442
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 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
488
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
489 /* PQconnectStart Makes a new asynchronous connection to a backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
490 PGconn *PQconnectStart(const char *conninfo)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
491 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
492
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
493 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
494 DEFUN ("pq-connect-start", Fpq_connect_start, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
495 Make a new asynchronous connection to a PostgreSQL backend.
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 (conninfo))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
498 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
499 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
500 Lisp_PGconn *lisp_pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
501 char *error_message = "Out of Memory?";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
502 char *c_conninfo;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
503
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
504 CHECK_STRING (conninfo);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
505 TO_EXTERNAL_FORMAT (LISP_STRING, conninfo,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
506 C_STRING_ALLOCA, c_conninfo, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
507 P = PQconnectStart (c_conninfo);
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 if (P && (PQstatus (P) != CONNECTION_BAD))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
510 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
511 (void)PQsetNoticeProcessor (P, xemacs_notice_processor, NULL);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
512 lisp_pgconn = allocate_pgconn();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
513 lisp_pgconn->pgconn = P;
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 return make_pgconn (lisp_pgconn);
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 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
518 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
519 /* capture the error message before destroying the object */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
520 char buf[BLCKSZ];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
521 strcpy (buf, error_message);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
522 if (P)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
523 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
524 strncpy (buf, PQerrorMessage (P), sizeof (buf));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
525 buf[sizeof (buf) - 1] = '\0';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
526 PQfinish (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
527 }
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
528 signal_ferror (Qprocess_error, "libpq: %s", buf);
442
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 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
531
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
532 DEFUN ("pq-connect-poll", Fpq_connect_poll, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
533 Poll an asynchronous connection for completion
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 (conn))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
536 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
537 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
538 PostgresPollingStatusType polling_status;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
541
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
542 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
543 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
544
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
545 polling_status = PQconnectPoll (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
546 switch (polling_status)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
547 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
548 case PGRES_POLLING_FAILED:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
549 /* Something Bad has happened */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
550 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
551 char *e = PQerrorMessage (P);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
552 signal_ferror (Qprocess_error, "libpq: %s", e);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
553 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
554 case PGRES_POLLING_OK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
555 return Qpgres_polling_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
556 case PGRES_POLLING_READING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
557 return Qpgres_polling_reading;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
558 case PGRES_POLLING_WRITING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
559 return Qpgres_polling_writing;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
560 case PGRES_POLLING_ACTIVE:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
561 return Qpgres_polling_active;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
562 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
563 /* 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
564 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
565 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
566 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
567
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
568 #ifdef MULE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
569 DEFUN ("pq-client-encoding", Fpq_client_encoding, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
570 Return client coding system.
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 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
575
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
576 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
577 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
578 CHECK_LIVE_CONNECTION (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 return make_int (PQclientEncoding (P));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
581 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
582
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
583 DEFUN ("pq-set-client-encoding", Fpq_set_client_encoding, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
584 Set client coding system.
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 (conn, encoding))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
587 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
588 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
589 int rc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
590 char *c_encoding;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
591
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
592 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
593 CHECK_STRING (encoding);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
594
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
595 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
596 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
597
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
598 TO_EXTERNAL_FORMAT (LISP_STRING, encoding,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
599 C_STRING_ALLOCA, c_encoding, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
600
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
601 if ((rc = PQsetClientEncoding (P, c_encoding)) < 0)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
602 signal_error (Qinvalid_argument, "bad encoding", Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
603 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
604 return make_int (rc);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
605 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
606
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
607 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
608 #endif /* HAVE_POSTGRESQLV7 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
609
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
610 /* PQfinish Close the connection to the backend. Also frees memory
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
611 used by the PGconn object.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
612 void PQfinish(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
613 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
614 DEFUN ("pq-finish", Fpq_finish, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
615 Close the connection to the backend.
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 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
620
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
621 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
622 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
623 PUKE_IF_NULL (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
624
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
625 PQfinish (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
626 /* #### PQfinish deallocates the PGconn structure, so we now have a
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
627 dangling pointer. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
628 /* Genocided all @'s ... */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
629 (XPGCONN (conn))->pgconn = (PGconn *)NULL; /* You feel DEAD inside */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
630 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
631 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
632
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
633 DEFUN ("pq-clear", Fpq_clear, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
634 Forcibly erase a PGresult object.
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 (res))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
639
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
640 CHECK_PGRESULT (res);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
641 R = (XPGRESULT (res))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
642 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
643
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
644 PQclear (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
645 /* Genocided all @'s ... */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
646 (XPGRESULT (res))->pgresult = (PGresult *)NULL; /* You feel DEAD inside */
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 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
649 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
650
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
651 DEFUN ("pq-is-busy", Fpq_is_busy, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
652 Return t if PQgetResult would block waiting for input.
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 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
657
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
658 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
659 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
660 CHECK_LIVE_CONNECTION (P);
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 return PQisBusy (P) ? Qt : Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
663 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
664
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
665 DEFUN ("pq-consume-input", Fpq_consume_input, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
666 Consume any available input from the backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
667 Returns nil if something bad happened.
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 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
672
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
673 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
674 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
675 CHECK_LIVE_CONNECTION (P);
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 return PQconsumeInput (P) ? Qt : Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
678 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
679
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
680 /* PQreset Reset the communication port with the backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
681 void PQreset(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
682 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
683 DEFUN ("pq-reset", Fpq_reset, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
684 Reset the connection to the backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
685 This function will close the connection to the backend and attempt to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
686 reestablish a new connection to the same postmaster, using all the same
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
687 parameters previously used. This may be useful for error recovery if a
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
688 working connection is lost.
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 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
693
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
694 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
695 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
696 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
697
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
698 PQreset (P);
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 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
701 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
702
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
703 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
704 DEFUN ("pq-reset-start", Fpq_reset_start, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
705 Reset connection to the backend asynchronously.
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 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
710
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
711 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
712 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
713 CHECK_LIVE_CONNECTION (P);
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 if (PQresetStart (P)) return Qt;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
716 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
717 char *e = PQerrorMessage (P);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
718 signal_ferror (Qprocess_error, "libpq: %s", e);
442
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 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
721
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
722 DEFUN ("pq-reset-poll", Fpq_reset_poll, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
723 Poll an asynchronous reset for completion.
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 (conn))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
726 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
727 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
728 PostgresPollingStatusType polling_status;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
731
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
732 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
733 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
734
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
735 polling_status = PQresetPoll (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
736 switch (polling_status)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
737 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
738 case PGRES_POLLING_FAILED:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
739 /* Something Bad has happened */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
740 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
741 char *e = PQerrorMessage (P);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
742 signal_ferror (Qprocess_error, "libpq: %s", e);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
743 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
744 case PGRES_POLLING_OK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
745 return Qpgres_polling_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
746 case PGRES_POLLING_READING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
747 return Qpgres_polling_reading;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
748 case PGRES_POLLING_WRITING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
749 return Qpgres_polling_writing;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
750 case PGRES_POLLING_ACTIVE:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
751 return Qpgres_polling_active;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
752 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
753 /* 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
754 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
755 }
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 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
758
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
759 DEFUN ("pq-request-cancel", Fpq_request_cancel, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
760 Attempt to request cancellation of the current operation.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
761
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
762 The return value is t if the cancel request was successfully
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
763 dispatched, nil if not (in which case conn->errorMessage is set).
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
764 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
765 the backend. The application must read the operation result as usual.
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 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
770
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
771 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
772 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
773 CHECK_LIVE_CONNECTION (P);
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 return PQrequestCancel (P) ? Qt : Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
776 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
777
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 DEFUN ("pq-pgconn", Fpq_pgconn, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
780 Accessor function for the PGconn object.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
781 Currently recognized symbols for the field:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
782 pq::db Database name
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
783 pq::user Database user name
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
784 pq::pass Database user's password
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
785 pq::host Hostname of PostgreSQL backend connected to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
786 pq::port TCP port number of connection
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
787 pq::tty Debugging TTY (not used in Emacs)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
788 pq::options Additional backend options
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
789 pq::status Connection status (either OK or BAD)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
790 pq::error-message Last error message from the backend
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
791 pq::backend-pid Process ID of backend process
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 (conn, field))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
796
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
797 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
798 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
799 PUKE_IF_NULL (P); /* BAD connections still have state to query */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
800
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
801 if (EQ(field, Qpqdb))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
802 /* PQdb Returns the database name of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
803 char *PQdb(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
804 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
805 return build_ext_string (PQdb(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
806 else if (EQ (field, Qpquser))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
807 /* PQuser Returns the user name of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
808 char *PQuser(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
809 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
810 return build_ext_string (PQuser(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
811 else if (EQ (field, Qpqpass))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
812 /* PQpass Returns the password of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
813 char *PQpass(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
814 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
815 return build_ext_string (PQpass(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
816 else if (EQ (field, Qpqhost))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
817 /* PQhost Returns the server host name of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
818 char *PQhost(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
819 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
820 return build_ext_string (PQhost(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
821 else if (EQ (field, Qpqport))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
822 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
823 char *p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
824 /* PQport Returns the port of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
825 char *PQport(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
826 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
827 if ((p = PQport(P)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
828 return make_int(atoi(p));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
829 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
830 return make_int(-1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
831 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
832 else if (EQ (field, Qpqtty))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
833 /* PQtty Returns the debug tty of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
834 char *PQtty(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
835 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
836 return build_ext_string (PQtty(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
837 else if (EQ (field, Qpqoptions))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
838 /* PQoptions Returns the backend options used in the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
839 char *PQoptions(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
840 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
841 return build_ext_string (PQoptions(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
842 else if (EQ (field, Qpqstatus))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
843 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
844 ConnStatusType cst;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
845 /* PQstatus Returns the status of the connection. The status can be
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
846 CONNECTION_OK or CONNECTION_BAD.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
847 ConnStatusType PQstatus(PGconn *conn)
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 switch ((cst = PQstatus (P)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
850 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
851 case CONNECTION_OK: return Qpg_connection_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
852 case CONNECTION_BAD: return Qpg_connection_bad;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
853 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
854 case CONNECTION_STARTED: return Qpg_connection_started;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
855 case CONNECTION_MADE: return Qpg_connection_made;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
856 case CONNECTION_AWAITING_RESPONSE: return Qpg_connection_awaiting_response;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
857 case CONNECTION_AUTH_OK: return Qpg_connection_auth_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
858 case CONNECTION_SETENV: return Qpg_connection_setenv;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
859 #endif /* HAVE_POSTGRESQLV7 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
860 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
861 /* 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
862 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
863 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
864 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
865 else if (EQ (field, Qpqerrormessage))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
866 /* PQerrorMessage Returns the error message most recently generated
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
867 by an operation on the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
868 char *PQerrorMessage(PGconn* conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
869 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
870 return build_ext_string (PQerrorMessage(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
871 else if (EQ (field, Qpqbackendpid))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
872 /* PQbackendPID Returns the process ID of the backend server handling
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
873 this connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
874 int PQbackendPID(PGconn *conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
875 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
876 return make_int (PQbackendPID(P));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
877 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
878 signal_error (Qinvalid_argument, "bad PGconn accessor", Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
879 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
880
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
881 /* Query functions */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
882 DEFUN ("pq-exec", Fpq_exec, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
883 Submit a query to Postgres and wait for the result.
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 (conn, query))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
886 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
887 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
888 Lisp_PGresult *lisp_pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
889 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
890 char *c_query;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
891
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
892 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
893 CHECK_STRING (query);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
894
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
895 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
896 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
897
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
898 TO_EXTERNAL_FORMAT (LISP_STRING, query,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
899 C_STRING_ALLOCA, c_query, Qnative);
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 R = PQexec (P, c_query);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
902 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
903 char *tag, buf[BLCKSZ];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
904
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
905 if (!R) out_of_memory ("query: out of memory", Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
906 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
907 switch (PQresultStatus (R))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
908 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
909 case PGRES_BAD_RESPONSE:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
910 tag = "bad response [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
911 goto err;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
912 case PGRES_NONFATAL_ERROR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
913 tag = "non-fatal error [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
914 goto err;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
915 case PGRES_FATAL_ERROR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
916 tag = "fatal error [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
917 err:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
918 strncpy (buf, PQresultErrorMessage (R), sizeof (buf));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
919 buf [sizeof (buf) - 1] = '\0';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
920 PQclear (R);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
921 signal_ferror (Qprocess_error, tag, buf);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
922 /*NOTREACHED*/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
923 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
924 break;
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 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
927
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
928 lisp_pgresult = allocate_pgresult ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
929 lisp_pgresult->pgresult = R;
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 return make_pgresult (lisp_pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
932 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
933
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
934 DEFUN ("pq-send-query", Fpq_send_query, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
935 Submit a query to Postgres and don't wait for the result.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
936 Returns: t if successfully submitted
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
937 nil if error (conn->errorMessage is set)
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 (conn, query))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
940 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
941 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
942 char *c_query;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
943
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
944 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
945 CHECK_STRING (query);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
946
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
947 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
948 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
949
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
950 TO_EXTERNAL_FORMAT (LISP_STRING, query,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
951 C_STRING_ALLOCA, c_query, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
952
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
953 if (PQsendQuery (P, c_query)) return Qt;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
954 else signal_ferror (Qprocess_error, "async query: %s", PQerrorMessage (P));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
955 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
956
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
957 DEFUN ("pq-get-result", Fpq_get_result, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
958 Retrieve an asynchronous result from a query.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
959 NIL is returned when no more query work remains.
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 (conn))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
962 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
963 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
964 Lisp_PGresult *lisp_pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
965 PGresult *R;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
968
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
969 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
970 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
971
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
972 R = PQgetResult (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
973 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
974
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 char *tag, buf[BLCKSZ];
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 switch (PQresultStatus (R))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
979 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
980 case PGRES_BAD_RESPONSE:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
981 tag = "bad response [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
982 goto err;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
983 case PGRES_NONFATAL_ERROR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
984 tag = "non-fatal error [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
985 goto err;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
986 case PGRES_FATAL_ERROR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
987 tag = "fatal error [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
988 err:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
989 strncpy (buf, PQresultErrorMessage (R), sizeof (buf));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
990 buf[sizeof (buf) - 1] = '\0';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
991 PQclear (R);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
992 signal_ferror (Qprocess_error, tag, buf);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
993 /*NOTREACHED*/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
994 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
995 break;
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 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
998
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
999 lisp_pgresult = allocate_pgresult();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1000 lisp_pgresult->pgresult = R;
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 return make_pgresult (lisp_pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1003 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1004
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1005 DEFUN ("pq-result-status", Fpq_result_status, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1006 Return result status of the query.
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 (result))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1009 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1010 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1011 ExecStatusType est;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1012
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1013 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1014 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1015 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1016
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1017 switch ((est = PQresultStatus (R))) {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1018 case PGRES_EMPTY_QUERY: return Qpgres_empty_query;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1019 case PGRES_COMMAND_OK: return Qpgres_command_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1020 case PGRES_TUPLES_OK: return Qpgres_tuples_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1021 case PGRES_COPY_OUT: return Qpgres_copy_out;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1022 case PGRES_COPY_IN: return Qpgres_copy_in;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1023 case PGRES_BAD_RESPONSE: return Qpgres_bad_response;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1024 case PGRES_NONFATAL_ERROR: return Qpgres_nonfatal_error;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1025 case PGRES_FATAL_ERROR: return Qpgres_fatal_error;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1026 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1027 /* 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
1028 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
1029 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1030 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1031
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1032 DEFUN ("pq-res-status", Fpq_res_status, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1033 Return stringified result status of the query.
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 (result))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1038
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1039 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1040 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1041 PUKE_IF_NULL (R);
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 return build_ext_string (PQresStatus (PQresultStatus (R)), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1044 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1045
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1046 /* Sundry PGresult accessor functions */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1047 DEFUN ("pq-result-error-message", Fpq_result_error_message, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1048 Return last message associated with the query.
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 (result))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1053
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1054 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1055 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1056 PUKE_IF_NULL (R);
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 return build_ext_string (PQresultErrorMessage (R), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1059 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1060
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1061 DEFUN ("pq-ntuples", Fpq_ntuples, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1062 Return the number of tuples (instances) in the query 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 (result))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1067
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1068 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1069 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1070 PUKE_IF_NULL (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 return make_int (PQntuples (R));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1073 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1074
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1075 DEFUN ("pq-nfields", Fpq_nfields, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1076 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
1077 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1078 (result))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1081
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1082 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1083 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1084 PUKE_IF_NULL (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 return make_int (PQnfields (R));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1087 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1088
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1089 DEFUN ("pq-binary-tuples", Fpq_binary_tuples, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1090 Return t if the query result contains binary data, nil otherwise.
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 (result))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1095
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1096 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1097 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1098 PUKE_IF_NULL (R);
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 return (PQbinaryTuples (R)) ? Qt : Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1101 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1102
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1103 DEFUN ("pq-fname", Fpq_fname, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1104 Return the field (attribute) name associated with the given field index.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1105 Field indices start at 0.
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 (result, field_index))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1110
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1111 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1112 CHECK_INT (field_index);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1113 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1114 PUKE_IF_NULL (R);
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 return build_ext_string (PQfname (R, XINT (field_index)), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1117 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1118
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1119 DEFUN ("pq-fnumber", Fpq_fnumber, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1120 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
1121 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1122 (result, field_name))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1123 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1124 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1125 char *c_field_name;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1126
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1127 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1128 CHECK_STRING (field_name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1129 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1130 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1131
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1132 TO_EXTERNAL_FORMAT (LISP_STRING, field_name,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1133 C_STRING_ALLOCA, c_field_name, Qnative);
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 return make_int (PQfnumber (R, c_field_name));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1136 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1137
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1138 DEFUN ("pq-ftype", Fpq_ftype, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1139 Return the field type associated with the given field index.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1140 The integer returned is the internal coding of the type. Field indices
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1141 start at 0.
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 (result, field_num))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1146
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1147 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1148 CHECK_INT (field_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1149 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1150 PUKE_IF_NULL (R);
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 return make_int (PQftype (R, XINT (field_num)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1153 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1154
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1155 DEFUN ("pq-fsize", Fpq_fsize, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1156 Return the field size in bytes associated with the given field index.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1157 Field indices start at 0.
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 (result, field_index))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1162
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1163 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1164 CHECK_INT (field_index);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1165 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1166 PUKE_IF_NULL (R);
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 return make_int (PQftype (R, XINT (field_index)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1169 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1170
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1171 DEFUN ("pq-fmod", Fpq_fmod, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1172 Return the type modifier associated with a field.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1173 Field indices start at 0.
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 (result, field_index))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1178
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1179 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1180 CHECK_INT (field_index);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1181 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1182 PUKE_IF_NULL (R);
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 return make_int (PQfmod (R, XINT (field_index)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1185 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1186
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1187 DEFUN ("pq-get-value", Fpq_get_value, 3, 3, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1188 Return a single field (attribute) value of one tuple of a PGresult.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1189 Tuple and field indices start at 0.
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 (result, tup_num, field_num))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1194
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1195 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1196 CHECK_INT (tup_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1197 CHECK_INT (field_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1198 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1199 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1200
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1201 return build_ext_string (PQgetvalue (R, XINT (tup_num), XINT (field_num)),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1202 PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1203 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1204
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1205 DEFUN ("pq-get-length", Fpq_get_length, 3, 3, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1206 Returns the length of a field value in bytes.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1207 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
1208 length returned does NOT include the size field of the varlena. (The
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1209 data returned by PQgetvalue doesn't either.)
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 (result, tup_num, field_num))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1214
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1215 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1216 CHECK_INT (tup_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1217 CHECK_INT (field_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1218 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1219 PUKE_IF_NULL (R);
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 return make_int (PQgetlength (R, XINT (tup_num), XINT (field_num)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1222 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1223
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1224 DEFUN ("pq-get-is-null", Fpq_get_is_null, 3, 3, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1225 Returns the null status of a field value.
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 (result, tup_num, field_num))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1230
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1231 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1232 CHECK_INT (tup_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1233 CHECK_INT (field_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1234 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1235 PUKE_IF_NULL (R);
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 return PQgetisnull (R, XINT (tup_num), XINT (field_num)) ? Qt : Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1238 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1239
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1240 DEFUN ("pq-cmd-status", Fpq_cmd_status, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1241 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
1242 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1243 (result))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1246
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1247 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1248 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1249 PUKE_IF_NULL (R);
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 return build_ext_string (PQcmdStatus (R), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1252 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1253
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1254 DEFUN ("pq-cmd-tuples", Fpq_cmd_tuples, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1255 Returns the number of rows affected by the SQL command.
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 (result))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1260
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1261 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1262 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1263 PUKE_IF_NULL (R);
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 return build_ext_string (PQcmdTuples (R), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1266 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1267
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1268 DEFUN ("pq-oid-value", Fpq_oid_value, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1269 Returns the object id of the tuple inserted.
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 (result))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1274
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1275 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1276 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1277 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1278
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1279 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1280 return make_int (PQoidValue (R));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1281 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1282 /* Use the old interface */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1283 return make_int (atoi (PQoidStatus (R)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1284 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1285 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1286
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1287 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1288 DEFUN ("pq-set-nonblocking", Fpq_set_nonblocking, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1289 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
1290 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
1291 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
1292
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1293 Needs to be called only on a connected database connection.
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 (conn, arg))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1298
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1299 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1300 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1301 CHECK_LIVE_CONNECTION (P);
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 return make_int (PQsetnonblocking (P, !NILP (arg)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1304 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1305
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1306 DEFUN ("pq-is-nonblocking", Fpq_is_nonblocking, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1307 Return the blocking status of the database connection.
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 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1312
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1313 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1314 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1315 CHECK_LIVE_CONNECTION (P);
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 return PQisnonblocking (P) ? Qt : Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1318 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1319
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1320 DEFUN ("pq-flush", Fpq_flush, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1321 Force the write buffer to be written (or at least try).
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 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1326
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1327 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1328 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1329 CHECK_LIVE_CONNECTION (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 return make_int (PQflush (P));
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 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1334
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1335 DEFUN ("pq-notifies", Fpq_notifies, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1336 Return the latest async notification that has not yet been handled.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1337 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
1338 The first element contains the relation name being notified, the second
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1339 element contains the backend process ID number. nil is returned if there
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1340 aren't any notifications to process.
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 (conn))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1343 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1344 /* This function cannot GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1345 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1346 PGnotify *PGN;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1347
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1348 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1349 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1350 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1351
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1352 PGN = PQnotifies (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1353 if (!PGN)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1354 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1355 else
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 Lisp_Object temp;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1358
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1359 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
1360 free ((void *)PGN);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1361 return temp;
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 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1364
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1365 #if defined (HAVE_POSTGRESQLV7) && defined(MULE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1366 DEFUN ("pq-env-2-encoding", Fpq_env_2_encoding, 0, 0, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1367 Get encoding id from environment variable PGCLIENTENCODING.
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 ())
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 return make_int (PQenv2encoding ());
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 #endif /* MULE */
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 DEFUN ("pq-lo-import", Fpq_lo_import, 2, 2, 0, /*
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 (conn, filename))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1378 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1379 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1380 char *c_filename;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1381
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1382 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1383 CHECK_STRING (filename);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1384
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1385 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1386 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1387
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1388 TO_EXTERNAL_FORMAT (LISP_STRING, filename,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1389 C_STRING_ALLOCA, c_filename,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1390 Qfile_name);
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 return make_int ((int)lo_import (P, c_filename));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1393 }
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 DEFUN ("pq-lo-export", Fpq_lo_export, 3, 3, 0, /*
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 (conn, oid, filename))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1398 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1399 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1400 char *c_filename;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1401
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1402 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1403 CHECK_INT (oid);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1404 CHECK_STRING (filename);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1405
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1406 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1407 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1408
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1409 TO_EXTERNAL_FORMAT (LISP_STRING, filename,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1410 C_STRING_ALLOCA, c_filename, Qfile_name);
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 return make_int ((int)lo_export (P, XINT (oid), c_filename));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1413 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1414
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1415 DEFUN ("pq-make-empty-pgresult", Fpq_make_empty_pgresult, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1416 Make an empty PGresult object with the given 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 (conn, status))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1419 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1420 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1421 Lisp_PGresult *lpgr;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1422 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1423 ExecStatusType est;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1424
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1425 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1426 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1427 CHECK_LIVE_CONNECTION (P); /* needed here? */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1428
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1429 if (EQ (status, Qpgres_empty_query)) est = PGRES_EMPTY_QUERY;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1430 else if (EQ (status, Qpgres_command_ok)) est = PGRES_COMMAND_OK;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1431 else if (EQ (status, Qpgres_tuples_ok)) est = PGRES_TUPLES_OK;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1432 else if (EQ (status, Qpgres_copy_out)) est = PGRES_COPY_OUT;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1433 else if (EQ (status, Qpgres_copy_in)) est = PGRES_COPY_IN;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1434 else if (EQ (status, Qpgres_bad_response)) est = PGRES_BAD_RESPONSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1435 else if (EQ (status, Qpgres_nonfatal_error)) est = PGRES_NONFATAL_ERROR;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1436 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
1437 else invalid_constant ("bad status symbol", status);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1438
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1439 R = PQmakeEmptyPGresult (P, est);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
1440 if (!R) out_of_memory (0, Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1441
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1442 lpgr = allocate_pgresult ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1443 lpgr->pgresult = R;
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 return make_pgresult (lpgr);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1446 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1447
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1448 DEFUN ("pq-get-line", Fpq_get_line, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1449 Retrieve a line from server in copy in operation.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1450 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
1451 -1: Copying is complete
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1452 0: A record is complete
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1453 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
1454 operation.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1455 and the cdr cell is returned string data.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1456
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1457 The copy operation is complete when the value `\.' (backslash dot) is
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1458 returned.
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 (conn))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1461 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1462 char buffer[BLCKSZ]; /* size of a Postgres disk block */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1463 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1464 int ret;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1465
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1466 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1467 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1468 CHECK_LIVE_CONNECTION (P);
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 ret = PQgetline (P, buffer, sizeof (buffer));
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 return Fcons (make_int (ret), build_ext_string (buffer, PG_OS_CODING));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1473 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1474
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1475 DEFUN ("pq-put-line", Fpq_put_line, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1476 Send a line to the server in copy out operation.
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 Returns t if the operation succeeded, nil otherwise.
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 (conn, string))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1481 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1482 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1483 char *c_string;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1484
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1485 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1486 CHECK_STRING (string);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1487
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1488 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1489 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1490 TO_EXTERNAL_FORMAT (LISP_STRING, string,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1491 C_STRING_ALLOCA, c_string, Qnative);
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 return !PQputline (P, c_string) ? Qt : Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1494 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1495
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1496 DEFUN ("pq-get-line-async", Fpq_get_line_async, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1497 Get a line from the server in copy in operation asynchronously.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1498
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1499 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
1500 asynchronously, that is without blocking. Having issued the COPY command
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1501 and gotten a PGRES_COPY_OUT response, the app should call PQconsumeInput
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1502 and this routine until the end-of-data signal is detected. Unlike
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1503 PQgetline, this routine takes responsibility for detecting end-of-data.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1504
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1505 On each call, PQgetlineAsync will return data if a complete newline-
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1506 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
1507 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
1508 Otherwise, no data is returned until the rest of the line arrives.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1509
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1510 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
1511 from libpq's input buffer). The caller *must* next call PQendcopy and
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1512 then return to normal processing.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1513
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1514 RETURNS:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1515 -1 if the end-of-copy-data marker has been recognized
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1516 0 if no data is available
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1517 >0 the number of bytes returned.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1518 The data returned will not extend beyond a newline character. If possible
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1519 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
1520 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
1521 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
1522 last returned byte is '\n' or not.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1523 The returned string is *not* null-terminated.
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 (conn))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1526 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1527 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1528 char buffer[BLCKSZ];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1529 int ret;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1532
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1533 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1534 CHECK_LIVE_CONNECTION (P);
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 ret = PQgetlineAsync (P, buffer, sizeof (buffer));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1537
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1538 if (ret == -1) return Qt; /* done! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1539 else if (!ret) return Qnil; /* no data yet */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1540 else return Fcons (make_int (ret),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1541 make_ext_string ((Extbyte *) buffer, ret, PG_OS_CODING));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1542 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1543
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1544 DEFUN ("pq-put-nbytes", Fpq_put_nbytes, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1545 Asynchronous copy out.
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 (conn, data))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1548 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1549 /* 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
1550 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1551 char *c_data;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1552
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1553 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1554 CHECK_STRING (data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1555
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1556 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1557 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1558 TO_EXTERNAL_FORMAT (LISP_STRING, data,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1559 C_STRING_ALLOCA, c_data, Qnative);
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 return !PQputnbytes (P, c_data, strlen (c_data)) ? Qt : Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1562 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1563
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1564 DEFUN ("pq-end-copy", Fpq_end_copy, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1565 End a copying operation.
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 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1570
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1571 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1572 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1573 CHECK_LIVE_CONNECTION (P);
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 return PQendcopy (P) ? Qt : Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1576 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1577
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1578 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1579 syms_of_postgresql(void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1580 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1581 #ifndef RUNNING_XEMACS_21_1
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1582 INIT_LRECORD_IMPLEMENTATION (pgconn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1583 INIT_LRECORD_IMPLEMENTATION (pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1584 #endif
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
1585 DEFSYMBOL (Qpostgresql);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1586
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1587 /* opaque exported types */
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
1588 DEFSYMBOL (Qpgconnp);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
1589 DEFSYMBOL (Qpgresultp);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1590
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1591 /* connection status types */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1592 defsymbol (&Qpg_connection_ok, "pg::connection-ok");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1593 defsymbol (&Qpg_connection_bad, "pg::connection-bad");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1594 defsymbol (&Qpg_connection_started, "pg::connection-started");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1595 defsymbol (&Qpg_connection_made, "pg::connection-made");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1596 defsymbol (&Qpg_connection_awaiting_response, "pg::connection-awaiting-response");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1597 defsymbol (&Qpg_connection_auth_ok, "pg::connection-auth-ok");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1598 defsymbol (&Qpg_connection_setenv, "pg::connection-setenv");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1599
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1600 /* Fields of PGconn */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1601 defsymbol (&Qpqdb, "pq::db");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1602 defsymbol (&Qpquser, "pq::user");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1603 defsymbol (&Qpqpass, "pq::pass");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1604 defsymbol (&Qpqhost, "pq::host");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1605 defsymbol (&Qpqport, "pq::port");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1606 defsymbol (&Qpqtty, "pq::tty");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1607 defsymbol (&Qpqoptions, "pq::options");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1608 defsymbol (&Qpqstatus, "pq::status");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1609 defsymbol (&Qpqerrormessage, "pq::error-message");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1610 defsymbol (&Qpqbackendpid, "pq::backend-pid");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1611
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1612 /* Query status results */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1613 defsymbol (&Qpgres_empty_query, "pgres::empty-query");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1614 defsymbol (&Qpgres_command_ok, "pgres::command-ok");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1615 defsymbol (&Qpgres_tuples_ok, "pgres::tuples-ok");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1616 defsymbol (&Qpgres_copy_out, "pgres::copy-out");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1617 defsymbol (&Qpgres_copy_in, "pgres::copy-in");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1618 defsymbol (&Qpgres_bad_response, "pgres::bad-response");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1619 defsymbol (&Qpgres_nonfatal_error, "pgres::nonfatal-error");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1620 defsymbol (&Qpgres_fatal_error, "pgres::fatal-error");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1621
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1622 /* Poll status results */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1623 defsymbol (&Qpgres_polling_failed, "pgres::polling-failed");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1624 defsymbol (&Qpgres_polling_reading, "pgres::polling-reading");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1625 defsymbol (&Qpgres_polling_writing, "pgres::polling-writing");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1626 defsymbol (&Qpgres_polling_ok, "pgres::polling-ok");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1627 defsymbol (&Qpgres_polling_active, "pgres::polling-active");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1628
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1629 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1630 DEFSUBR (Fpq_connect_start);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1631 DEFSUBR (Fpq_connect_poll);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1632 #ifdef MULE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1633 DEFSUBR (Fpq_client_encoding);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1634 DEFSUBR (Fpq_set_client_encoding);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1635 #endif /* MULE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1636 #endif /* HAVE_POSTGRESQLV7 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1637 DEFSUBR (Fpq_conn_defaults);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1638 DEFSUBR (Fpq_connectdb);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1639 DEFSUBR (Fpq_finish);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1640 DEFSUBR (Fpq_clear);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1641 DEFSUBR (Fpq_is_busy);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1642 DEFSUBR (Fpq_consume_input);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1643
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1644 DEFSUBR (Fpq_reset);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1645 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1646 DEFSUBR (Fpq_reset_start);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1647 DEFSUBR (Fpq_reset_poll);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1648 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1649 DEFSUBR (Fpq_request_cancel);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1650 DEFSUBR (Fpq_pgconn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1651
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1652 DEFSUBR (Fpq_exec);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1653 DEFSUBR (Fpq_send_query);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1654 DEFSUBR (Fpq_get_result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1655 DEFSUBR (Fpq_result_status);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1656 DEFSUBR (Fpq_res_status);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1657 DEFSUBR (Fpq_result_error_message);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1658 DEFSUBR (Fpq_ntuples);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1659 DEFSUBR (Fpq_nfields);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1660 DEFSUBR (Fpq_binary_tuples);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1661 DEFSUBR (Fpq_fname);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1662 DEFSUBR (Fpq_fnumber);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1663 DEFSUBR (Fpq_ftype);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1664 DEFSUBR (Fpq_fsize);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1665 DEFSUBR (Fpq_fmod);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1666 /***/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1667 DEFSUBR (Fpq_get_value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1668 DEFSUBR (Fpq_get_length);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1669 DEFSUBR (Fpq_get_is_null);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1670 DEFSUBR (Fpq_cmd_status);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1671 DEFSUBR (Fpq_cmd_tuples);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1672 DEFSUBR (Fpq_oid_value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1673
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1674 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1675 DEFSUBR (Fpq_set_nonblocking);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1676 DEFSUBR (Fpq_is_nonblocking);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1677 DEFSUBR (Fpq_flush);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1678 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1679 DEFSUBR (Fpq_notifies);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1680
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1681 #if defined (HAVE_POSTGRESQLV7) && defined(MULE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1682 DEFSUBR (Fpq_env_2_encoding);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1683 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1684
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1685 DEFSUBR (Fpq_lo_import);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1686 DEFSUBR (Fpq_lo_export);
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 DEFSUBR (Fpq_make_empty_pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1689
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1690 /* copy in/out functions */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1691 DEFSUBR (Fpq_get_line);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1692 DEFSUBR (Fpq_put_line);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1693 DEFSUBR (Fpq_get_line_async);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1694 DEFSUBR (Fpq_put_nbytes);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1695 DEFSUBR (Fpq_end_copy);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1696 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1697
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1698 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1699 vars_of_postgresql(void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1700 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1701 Fprovide (Qpostgresql);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1702 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1703 Fprovide (intern ("postgresqlv7"));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1704 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1705 #ifndef RUNNING_XEMACS_21_1
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1706 Vpg_coding_system = Qnative;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1707 DEFVAR_LISP ("pg-coding-system", &Vpg_coding_system /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1708 Default Postgres client coding system.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1709 */ );
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1710 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1711
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1712 DEFVAR_LISP ("pg:host", &VXPGHOST /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1713 Default PostgreSQL server name.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1714 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
1715 initial value is set from the PGHOST environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1716 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1717
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1718 DEFVAR_LISP ("pg:user", &VXPGUSER /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1719 Default PostgreSQL user name.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1720 This value is used when connecting to a database for authentication.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1721 The initial value is set from the PGUSER environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1722 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1723
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1724 DEFVAR_LISP ("pg:options", &VXPGOPTIONS /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1725 Default PostgreSQL user name.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1726 This value is used when connecting to a database for authentication.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1727 The initial value is set from the PGUSER environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1728 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1729
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1730 DEFVAR_LISP ("pg:port", &VXPGPORT /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1731 Default port to connect to PostgreSQL backend.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1732 This value is used when connecting to a database.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1733 The initial value is set from the PGPORT environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1734 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1735
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1736 DEFVAR_LISP ("pg:tty", &VXPGTTY /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1737 Default debugging TTY.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1738 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
1739 The initial value is set from the PGTTY environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1740 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1741
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1742 DEFVAR_LISP ("pg:database", &VXPGDATABASE /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1743 Default database to connect to.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1744 The initial value is set from the PGDATABASE environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1745 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1746
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1747 DEFVAR_LISP ("pg:realm", &VXPGREALM /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1748 Default kerberos realm to use for authentication.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1749 The initial value is set from the PGREALM environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1750 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1751
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1752 #ifdef MULE
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1753 /* 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
1754 autodetect the coding system from the database. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1755 DEFVAR_LISP ("pg:client-encoding", &VXPGCLIENTENCODING /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1756 Default client encoding to use.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1757 The initial value is set from the PGCLIENTENCODING environment variable.
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 #endif
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1760
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1761 #if !defined(HAVE_POSTGRESQLV7)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1762 DEFVAR_LISP ("pg:authtype", &VXPGAUTHTYPE /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1763 Default authentication to use.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1764 The initial value is set from the PGAUTHTYPE environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1765
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1766 WARNING: This variable has gone away in versions of PostgreSQL newer
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1767 than 6.5.
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 #endif
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1770
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1771 DEFVAR_LISP ("pg:geqo", &VXPGGEQO /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1772 Genetic Query Optimizer options.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1773 The initial value is set from the PGGEQO environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1774 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1775
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1776 DEFVAR_LISP ("pg:cost-index", &VXPGCOSTINDEX /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1777 Default cost index options.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1778 The initial value is set from the PGCOSTINDEX environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1779 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1780
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1781 DEFVAR_LISP ("pg:cost-heap", &VXPGCOSTHEAP /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1782 Default cost heap options.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1783 The initial value is set from the PGCOSTHEAP environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1784 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1785
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1786 DEFVAR_LISP ("pg:tz", &VXPGTZ /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1787 Default timezone to use.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1788 The initial value is set from the PGTZ environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1789 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1790
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1791 DEFVAR_LISP ("pg:date-style", &VXPGDATESTYLE /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1792 Default date style to use.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1793 The initial value is set from the PGDATESTYLE environment variable.
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 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1796
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1797 /* These initializations should not be done at dump-time. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1798 void
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1799 init_postgresql_from_environment (void)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1800 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1801 Intbyte *p;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1802
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1803 #define FROB(envvar, var) \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1804 if ((p = egetenv (envvar))) \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1805 var = build_intstring (p); \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1806 else \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1807 var = Qnil
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 if (initialized)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1810 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1811 FROB ("PGHOST", VXPGHOST);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1812 FROB ("PGUSER", VXPGUSER);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1813 FROB ("PGOPTIONS", VXPGOPTIONS);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1814
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1815 if ((p = egetenv ("PGPORT")))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1816 VXPGPORT = make_int (atoi ((char *) p));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1817 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1818 VXPGPORT = Qnil;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1819
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1820 FROB ("PGTTY", VXPGTTY);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1821 FROB ("PGDATABASE", VXPGDATABASE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1822 FROB ("PGREALM", VXPGREALM);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1823 #ifdef MULE
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1824 /* 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
1825 autodetect the coding system from the database. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1826 FROB ("PGCLIENTENCODING", VXPGCLIENTENCODING);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1827 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1828
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1829 #if !defined(HAVE_POSTGRESQLV7)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1830 FROB ("PGAUTHTYPE", VXPGAUTHTYPE);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1831 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1832
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1833 FROB ("PGGEQO", VXPGGEQO);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1834 FROB ("PGCOSTINDEX", VXPGCOSTINDEX);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1835 FROB ("PGCOSTHEAP", VXPGCOSTHEAP);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1836 FROB ("PGTZ", VXPGTZ);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1837 FROB ("PGDATESTYLE", VXPGDATESTYLE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1838 #undef FROB
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1839 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1840 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1841