annotate src/postgresql.c @ 981:0205cafe98ff

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