annotate src/postgresql.c @ 934:c925bacdda60

[xemacs-hg @ 2002-07-29 09:21:12 by michaels] 2002-07-17 Marcus Crestani <crestani@informatik.uni-tuebingen.de> Markus Kaltenbach <makalten@informatik.uni-tuebingen.de> Mike Sperber <mike@xemacs.org> configure flag to turn these changes on: --use-kkcc First we added a dumpable flag to lrecord_implementation. It shows, if the object is dumpable and should be processed by the dumper. * lrecord.h (struct lrecord_implementation): added dumpable flag (MAKE_LRECORD_IMPLEMENTATION): fitted the different makro definitions to the new lrecord_implementation and their calls. Then we changed mark_object, that it no longer needs a mark method for those types that have pdump descritions. * alloc.c: (mark_object): If the object has a description, the new mark algorithm is called, and the object is marked according to its description. Otherwise it uses the mark method like before. These procedures mark objects according to their descriptions. They are modeled on the corresponding pdumper procedures. (mark_with_description): (get_indirect_count): (structure_size): (mark_struct_contents): These procedures still call mark_object, this is needed while there are Lisp_Objects without descriptions left. We added pdump descriptions for many Lisp_Objects: * extents.c: extent_auxiliary_description * database.c: database_description * gui.c: gui_item_description * scrollbar.c: scrollbar_instance_description * toolbar.c: toolbar_button_description * event-stream.c: command_builder_description * mule-charset.c: charset_description * device-msw.c: devmode_description * dialog-msw.c: mswindows_dialog_id_description * eldap.c: ldap_description * postgresql.c: pgconn_description pgresult_description * tooltalk.c: tooltalk_message_description tooltalk_pattern_description * ui-gtk.c: emacs_ffi_description emacs_gtk_object_description * events.c: * events.h: * event-stream.c: * event-Xt.c: * event-gtk.c: * event-tty.c: To write a pdump description for Lisp_Event, we converted every struct in the union event to a Lisp_Object. So we created nine new Lisp_Objects: Lisp_Key_Data, Lisp_Button_Data, Lisp_Motion_Data, Lisp_Process_Data, Lisp_Timeout_Data, Lisp_Eval_Data, Lisp_Misc_User_Data, Lisp_Magic_Data, Lisp_Magic_Eval_Data. We also wrote makro selectors and mutators for the fields of the new designed Lisp_Event and added everywhere these new abstractions. We implemented XD_UNION support in (mark_with_description), so we can describe exspecially console/device specific data with XD_UNION. To describe with XD_UNION, we added a field to these objects, which holds the variant type of the object. This field is initialized in the appendant constructor. The variant is an integer, it has also to be described in an description, if XD_UNION is used. XD_UNION is used in following descriptions: * console.c: console_description (get_console_variant): returns the variant (create_console): added variant initialization * console.h (console_variant): the different console types * console-impl.h (struct console): added enum console_variant contype * device.c: device_description (Fmake_device): added variant initialization * device-impl.h (struct device): added enum console_variant devtype * objects.c: image_instance_description font_instance_description (Fmake_color_instance): added variant initialization (Fmake_font_instance): added variant initialization * objects-impl.h (struct Lisp_Color_Instance): added color_instance_type * objects-impl.h (struct Lisp_Font_Instance): added font_instance_type * process.c: process_description (make_process_internal): added variant initialization * process.h (process_variant): the different process types
author michaels
date Mon, 29 Jul 2002 09:21:25 +0000
parents 79c6ff3eef26
children a9077bb4dbf1
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,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
272 mark_pgconn, print_pgconn, finalize_pgconn,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
273 NULL, NULL,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
274 pgconn_description,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
275 Lisp_PGconn);
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
276 #else /* not USE_KKCC */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
277 DEFINE_LRECORD_IMPLEMENTATION ("pgconn", pgconn,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
278 mark_pgconn, print_pgconn, finalize_pgconn,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
279 NULL, NULL,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
280 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
281 Lisp_PGconn);
934
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
282 #endif /* not USE_KKCC */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
283 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
284 /****/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
285
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
286 /* 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
287 Lisp code.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
288 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
289 Lisp_Object Qpgresultp;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
290
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
291 static Lisp_Object
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
292 make_pgresult (Lisp_PGresult *pgresult)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
293 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
294 return wrap_pgresult (pgresult);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
295 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
296
934
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
297 #ifdef USE_KKCC
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
298 static const struct lrecord_description pgresult_description [] = {
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
299 { XD_END }
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
300 };
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
301 #endif /* USE_KKCC */
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
302
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
303
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
304 static Lisp_Object
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
305 #ifdef RUNNING_XEMACS_21_1
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
306 mark_pgresult (Lisp_Object obj, void (*markobj) (Lisp_Object))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
307 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
308 mark_pgresult (Lisp_Object obj)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
309 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
310 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
311 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
312 }
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 #define RESULT_TUPLES_FMT "#<PGresult %s[%d] - %s>"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
315 #define RESULT_CMD_TUPLES_FMT "#<PGresult %s[%s] - %s>"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
316 #define RESULT_DEFAULT_FMT "#<PGresult %s - %s>"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
317 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
318 print_pgresult (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
319 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
320 char buf[1024];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
321 PGresult *res;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
322
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
323 res = (XPGRESULT (obj))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
324
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
325 if (res)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
326 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
327 switch (PQresultStatus (res))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
328 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
329 case PGRES_TUPLES_OK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
330 /* Add number of tuples of result to output */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
331 sprintf (buf, RESULT_TUPLES_FMT, /* evil! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
332 PQresStatus (PQresultStatus (res)),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
333 PQntuples (res),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
334 PQcmdStatus (res));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
335 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
336 case PGRES_COMMAND_OK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
337 /* Add number of tuples affected by output-less command */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
338 if (!strlen (PQcmdTuples (res))) goto notuples;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
339 sprintf (buf, RESULT_CMD_TUPLES_FMT, /* evil! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
340 PQresStatus (PQresultStatus (res)),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
341 PQcmdTuples (res),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
342 PQcmdStatus (res));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
343 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
344 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
345 notuples:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
346 /* No counts to print */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
347 sprintf (buf, RESULT_DEFAULT_FMT, /* evil! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
348 PQresStatus (PQresultStatus (res)),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
349 PQcmdStatus (res));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
350 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
351 }
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 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
354 strcpy (buf, "#<PGresult DEAD>"); /* evil! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
355
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
356 if (print_readably)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
357 printing_unreadable_object ("%s", buf);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
358 else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
359 write_c_string (printcharfun, buf);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
360 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
361
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
362 #undef RESULT_TUPLES_FMT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
363 #undef RESULT_CMD_TUPLES_FMT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
364 #undef RESULT_DEFAULT_FMT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
365
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
366 static Lisp_PGresult *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
367 allocate_pgresult (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
368 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
369 #ifdef RUNNING_XEMACS_21_1
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
370 Lisp_PGresult *pgresult = alloc_lcrecord_type (Lisp_PGresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
371 lrecord_pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
372 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
373 Lisp_PGresult *pgresult = alloc_lcrecord_type (Lisp_PGresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
374 &lrecord_pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
375 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
376 pgresult->pgresult = (PGresult *)NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
377 return pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
378 }
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 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
381 finalize_pgresult (void *header, int for_disksave)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
382 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
383 Lisp_PGresult *pgresult = (Lisp_PGresult *)header;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
384
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
385 if (for_disksave)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
386 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
387 make_pgresult (pgresult));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
388
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
389 if (pgresult->pgresult)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
390 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
391 PQclear (pgresult->pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
392 pgresult->pgresult = (PGresult *)NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
393 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
394 }
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 #ifdef RUNNING_XEMACS_21_1
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
397 DEFINE_LRECORD_IMPLEMENTATION ("pgresult", pgresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
398 mark_pgresult, print_pgresult, finalize_pgresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
399 NULL, NULL,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
400 Lisp_PGresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
401 #else
934
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
402 #ifdef USE_KKCC
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
403 DEFINE_LRECORD_IMPLEMENTATION ("pgresult", pgresult,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
404 mark_pgresult, print_pgresult, finalize_pgresult,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
405 NULL, NULL,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
406 pgresult_description,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
407 Lisp_PGresult);
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
408 #else /* not USE_KKCC */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
409 DEFINE_LRECORD_IMPLEMENTATION ("pgresult", pgresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
410 mark_pgresult, print_pgresult, finalize_pgresult,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
411 NULL, NULL,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
412 0,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
413 Lisp_PGresult);
934
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 872
diff changeset
414 #endif /* not USE_KKCC */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
415 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
416
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
417 /***********************/
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 /* notices */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
420 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
421 xemacs_notice_processor (void *arg, const char *msg)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
422 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
423 warn_when_safe (Qpostgresql, Qnotice, "%s", 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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
426 /* 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
427 Two of them, PQsetdb and PQsetdbLogin, are deprecated. Both of those
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
428 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
429 Note that PQconnectStart does not exist prior to v7.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
430 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
431
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
432 DEFUN ("pq-conn-defaults", Fpq_conn_defaults, 0, 0, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
433 Return a connection default structure.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
434 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
435 ())
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 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
438 PQconninfoOption *pcio;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
439 Lisp_Object temp, temp1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
440 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
441
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
442 pcio = PQconndefaults();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
443 if (!pcio) return Qnil; /* can never happen in libpq-7.0 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
444 temp = list1 (Fcons (build_ext_string (pcio[0].keyword, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
445 Fcons (build_ext_string (pcio[0].envvar, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
446 Fcons (build_ext_string (pcio[0].compiled, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
447 Fcons (build_ext_string (pcio[0].val, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
448 Fcons (build_ext_string (pcio[0].label, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
449 Fcons (build_ext_string (pcio[0].dispchar, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
450 Fcons (make_int (pcio[0].dispsize), Qnil))))))));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
451
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
452 for (i = 1; pcio[i].keyword; i++)
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 temp1 = list1 (Fcons (build_ext_string (pcio[i].keyword, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
455 Fcons (build_ext_string (pcio[i].envvar, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
456 Fcons (build_ext_string (pcio[i].compiled, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
457 Fcons (build_ext_string (pcio[i].val, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
458 Fcons (build_ext_string (pcio[i].label, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
459 Fcons (build_ext_string (pcio[i].dispchar, PG_OS_CODING),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
460 Fcons (make_int (pcio[i].dispsize), Qnil))))))));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
461 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
462 Lisp_Object args[2];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
463 args[0] = temp;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
464 args[1] = temp1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
465 /* Fappend GCPROs its arguments */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
466 temp = Fappend (2, args);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
467 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
468 }
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 return temp;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
473 /* PQconnectdb Makes a new connection to a backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
474 PGconn *PQconnectdb(const char *conninfo)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
475 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
476
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
477 DEFUN ("pq-connectdb", Fpq_connectdb, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
478 Make a new connection to a PostgreSQL backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
479 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
480 (conninfo))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
483 Lisp_PGconn *lisp_pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
484 char *error_message = "Out of Memory?";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
485 char *c_conninfo;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
486
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
487 CHECK_STRING (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 TO_EXTERNAL_FORMAT(LISP_STRING, conninfo,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
490 C_STRING_ALLOCA, c_conninfo, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
491 P = PQconnectdb (c_conninfo);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
492 if (P && (PQstatus (P) == CONNECTION_OK))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
493 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
494 (void)PQsetNoticeProcessor (P, xemacs_notice_processor, NULL);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
495 lisp_pgconn = allocate_pgconn();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
496 lisp_pgconn->pgconn = P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
497 return make_pgconn (lisp_pgconn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
498 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
499 else
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 /* Connection failed. Destroy the connection and signal an error. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
502 char buf[BLCKSZ];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
503 strcpy (buf, error_message);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
504 if (P)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
505 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
506 /* storage for the error message gets erased when call PQfinish */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
507 /* so we must temporarily stash it somewhere */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
508 strncpy (buf, PQerrorMessage (P), sizeof (buf));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
509 buf[sizeof (buf) - 1] = '\0';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
510 PQfinish (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
511 }
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
512 signal_ferror (Qprocess_error, "libpq: %s", buf);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
513 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
514 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
515
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
516 /* PQconnectStart Makes a new asynchronous connection to a backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
517 PGconn *PQconnectStart(const char *conninfo)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
518 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
519
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
520 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
521 DEFUN ("pq-connect-start", Fpq_connect_start, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
522 Make a new asynchronous connection to a PostgreSQL backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
523 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
524 (conninfo))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
527 Lisp_PGconn *lisp_pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
528 char *error_message = "Out of Memory?";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
529 char *c_conninfo;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
530
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
531 CHECK_STRING (conninfo);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
532 TO_EXTERNAL_FORMAT (LISP_STRING, conninfo,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
533 C_STRING_ALLOCA, c_conninfo, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
534 P = PQconnectStart (c_conninfo);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
535
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
536 if (P && (PQstatus (P) != CONNECTION_BAD))
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 (void)PQsetNoticeProcessor (P, xemacs_notice_processor, NULL);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
539 lisp_pgconn = allocate_pgconn();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
540 lisp_pgconn->pgconn = P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
541
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
542 return make_pgconn (lisp_pgconn);
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 else
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 /* capture the error message before destroying the object */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
547 char buf[BLCKSZ];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
548 strcpy (buf, error_message);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
549 if (P)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
550 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
551 strncpy (buf, PQerrorMessage (P), sizeof (buf));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
552 buf[sizeof (buf) - 1] = '\0';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
553 PQfinish (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
554 }
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
555 signal_ferror (Qprocess_error, "libpq: %s", buf);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
556 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
557 }
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 DEFUN ("pq-connect-poll", Fpq_connect_poll, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
560 Poll an asynchronous connection for completion
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
561 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
562 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
565 PostgresPollingStatusType polling_status;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
566
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
567 CHECK_PGCONN (conn);
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 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
570 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
571
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
572 polling_status = PQconnectPoll (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
573 switch (polling_status)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
574 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
575 case PGRES_POLLING_FAILED:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
576 /* Something Bad has happened */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
577 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
578 char *e = PQerrorMessage (P);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
579 signal_ferror (Qprocess_error, "libpq: %s", e);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
580 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
581 case PGRES_POLLING_OK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
582 return Qpgres_polling_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
583 case PGRES_POLLING_READING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
584 return Qpgres_polling_reading;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
585 case PGRES_POLLING_WRITING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
586 return Qpgres_polling_writing;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
587 case PGRES_POLLING_ACTIVE:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
588 return Qpgres_polling_active;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
589 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
590 /* 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
591 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
592 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
593 }
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 #ifdef MULE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
596 DEFUN ("pq-client-encoding", Fpq_client_encoding, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
597 Return client coding system.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
598 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
599 (conn))
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 PGconn *P;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
604 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
605 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
606
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
607 return make_int (PQclientEncoding (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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
610 DEFUN ("pq-set-client-encoding", Fpq_set_client_encoding, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
611 Set client coding system.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
612 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
613 (conn, encoding))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
616 int rc;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
617 char *c_encoding;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
618
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
619 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
620 CHECK_STRING (encoding);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
621
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
622 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
623 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
624
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
625 TO_EXTERNAL_FORMAT (LISP_STRING, encoding,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
626 C_STRING_ALLOCA, c_encoding, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
627
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
628 if ((rc = PQsetClientEncoding (P, c_encoding)) < 0)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
629 signal_error (Qinvalid_argument, "bad encoding", Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
630 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
631 return make_int (rc);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
632 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
633
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
634 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
635 #endif /* HAVE_POSTGRESQLV7 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
636
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
637 /* PQfinish Close the connection to the backend. Also frees memory
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
638 used by the PGconn object.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
639 void PQfinish(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
640 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
641 DEFUN ("pq-finish", Fpq_finish, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
642 Close the connection to the backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
643 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
644 (conn))
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 PGconn *P;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
649 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
650 PUKE_IF_NULL (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
651
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
652 PQfinish (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
653 /* #### PQfinish deallocates the PGconn structure, so we now have a
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
654 dangling pointer. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
655 /* Genocided all @'s ... */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
656 (XPGCONN (conn))->pgconn = (PGconn *)NULL; /* You feel DEAD inside */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
657 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
658 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
659
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
660 DEFUN ("pq-clear", Fpq_clear, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
661 Forcibly erase a PGresult object.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
662 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
663 (res))
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 PGresult *R;
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 CHECK_PGRESULT (res);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
668 R = (XPGRESULT (res))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
669 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
670
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
671 PQclear (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
672 /* Genocided all @'s ... */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
673 (XPGRESULT (res))->pgresult = (PGresult *)NULL; /* You feel DEAD inside */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
674
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
675 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
676 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
677
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
678 DEFUN ("pq-is-busy", Fpq_is_busy, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
679 Return t if PQgetResult would block waiting for input.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
680 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
681 (conn))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
682 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
683 PGconn *P;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
686 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
687 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
688
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
689 return PQisBusy (P) ? Qt : Qnil;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
692 DEFUN ("pq-consume-input", Fpq_consume_input, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
693 Consume any available input from the backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
694 Returns nil if something bad happened.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
695 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
696 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
699
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
700 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
701 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
702 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
703
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
704 return PQconsumeInput (P) ? Qt : Qnil;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
707 /* PQreset Reset the communication port with the backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
708 void PQreset(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
709 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
710 DEFUN ("pq-reset", Fpq_reset, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
711 Reset the connection to the backend.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
712 This function will close the connection to the backend and attempt to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
713 reestablish a new connection to the same postmaster, using all the same
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
714 parameters previously used. This may be useful for error recovery if a
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
715 working connection is lost.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
716 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
717 (conn))
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 PGconn *P;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
722 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
723 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
724
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
725 PQreset (P);
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 return Qnil;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
730 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
731 DEFUN ("pq-reset-start", Fpq_reset_start, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
732 Reset connection to the backend asynchronously.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
733 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
734 (conn))
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 PGconn *P;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
739 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
740 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
741
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
742 if (PQresetStart (P)) return Qt;
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 char *e = PQerrorMessage (P);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
745 signal_ferror (Qprocess_error, "libpq: %s", e);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
746 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
747 }
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 DEFUN ("pq-reset-poll", Fpq_reset_poll, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
750 Poll an asynchronous reset for completion.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
751 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
752 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
755 PostgresPollingStatusType polling_status;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
756
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
757 CHECK_PGCONN (conn);
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 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
760 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
761
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
762 polling_status = PQresetPoll (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
763 switch (polling_status)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
764 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
765 case PGRES_POLLING_FAILED:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
766 /* Something Bad has happened */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
767 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
768 char *e = PQerrorMessage (P);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
769 signal_ferror (Qprocess_error, "libpq: %s", e);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
770 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
771 case PGRES_POLLING_OK:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
772 return Qpgres_polling_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
773 case PGRES_POLLING_READING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
774 return Qpgres_polling_reading;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
775 case PGRES_POLLING_WRITING:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
776 return Qpgres_polling_writing;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
777 case PGRES_POLLING_ACTIVE:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
778 return Qpgres_polling_active;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
779 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
780 /* 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
781 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
782 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
783 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
784 #endif
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 DEFUN ("pq-request-cancel", Fpq_request_cancel, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
787 Attempt to request cancellation of the current operation.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
788
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
789 The return value is t if the cancel request was successfully
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
790 dispatched, nil if not (in which case conn->errorMessage is set).
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
791 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
792 the backend. The application must read the operation result as usual.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
793 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
794 (conn))
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 PGconn *P;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
799 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
800 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
801
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
802 return PQrequestCancel (P) ? Qt : Qnil;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
805 /* accessor function for the PGconn object */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
806 DEFUN ("pq-pgconn", Fpq_pgconn, 2, 2, 0, /*
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 Currently recognized symbols for the field:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
809 pq::db Database name
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
810 pq::user Database user name
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
811 pq::pass Database user's password
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
812 pq::host Hostname of PostgreSQL backend connected to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
813 pq::port TCP port number of connection
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
814 pq::tty Debugging TTY (not used in Emacs)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
815 pq::options Additional backend options
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
816 pq::status Connection status (either OK or BAD)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
817 pq::error-message Last error message from the backend
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
818 pq::backend-pid Process ID of backend process
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
819 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
820 (conn, field))
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 PGconn *P;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
825 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
826 PUKE_IF_NULL (P); /* BAD connections still have state to query */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
827
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
828 if (EQ(field, Qpqdb))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
829 /* PQdb Returns the database name of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
830 char *PQdb(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
831 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
832 return build_ext_string (PQdb(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
833 else if (EQ (field, Qpquser))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
834 /* PQuser Returns the user name of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
835 char *PQuser(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
836 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
837 return build_ext_string (PQuser(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
838 else if (EQ (field, Qpqpass))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
839 /* PQpass Returns the password of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
840 char *PQpass(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
841 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
842 return build_ext_string (PQpass(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
843 else if (EQ (field, Qpqhost))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
844 /* PQhost Returns the server host name of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
845 char *PQhost(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
846 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
847 return build_ext_string (PQhost(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
848 else if (EQ (field, Qpqport))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
849 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
850 char *p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
851 /* PQport Returns the port of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
852 char *PQport(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
853 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
854 if ((p = PQport(P)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
855 return make_int(atoi(p));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
856 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
857 return make_int(-1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
858 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
859 else if (EQ (field, Qpqtty))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
860 /* PQtty Returns the debug tty of the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
861 char *PQtty(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
862 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
863 return build_ext_string (PQtty(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
864 else if (EQ (field, Qpqoptions))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
865 /* PQoptions Returns the backend options used in the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
866 char *PQoptions(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
867 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
868 return build_ext_string (PQoptions(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
869 else if (EQ (field, Qpqstatus))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
870 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
871 ConnStatusType cst;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
872 /* PQstatus Returns the status of the connection. The status can be
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
873 CONNECTION_OK or CONNECTION_BAD.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
874 ConnStatusType PQstatus(PGconn *conn)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
875 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
876 switch ((cst = PQstatus (P)))
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 case CONNECTION_OK: return Qpg_connection_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
879 case CONNECTION_BAD: return Qpg_connection_bad;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
880 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
881 case CONNECTION_STARTED: return Qpg_connection_started;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
882 case CONNECTION_MADE: return Qpg_connection_made;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
883 case CONNECTION_AWAITING_RESPONSE: return Qpg_connection_awaiting_response;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
884 case CONNECTION_AUTH_OK: return Qpg_connection_auth_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
885 case CONNECTION_SETENV: return Qpg_connection_setenv;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
886 #endif /* HAVE_POSTGRESQLV7 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
887 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
888 /* 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
889 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
890 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
891 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
892 else if (EQ (field, Qpqerrormessage))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
893 /* PQerrorMessage Returns the error message most recently generated
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
894 by an operation on the connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
895 char *PQerrorMessage(PGconn* conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
896 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
897 return build_ext_string (PQerrorMessage(P), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
898 else if (EQ (field, Qpqbackendpid))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
899 /* PQbackendPID Returns the process ID of the backend server handling
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
900 this connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
901 int PQbackendPID(PGconn *conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
902 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
903 return make_int (PQbackendPID(P));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
904 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
905 signal_error (Qinvalid_argument, "bad PGconn accessor", Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
906 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
907
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
908 /* Query functions */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
909 DEFUN ("pq-exec", Fpq_exec, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
910 Submit a query to Postgres and wait for the result.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
911 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
912 (conn, query))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
915 Lisp_PGresult *lisp_pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
916 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
917 char *c_query;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
918
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
919 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
920 CHECK_STRING (query);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
921
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
922 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
923 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
924
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
925 TO_EXTERNAL_FORMAT (LISP_STRING, query,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
926 C_STRING_ALLOCA, c_query, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
927
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
928 R = PQexec (P, c_query);
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 char *tag, buf[BLCKSZ];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
931
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
932 if (!R) out_of_memory ("query: out of memory", Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
933 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
934 switch (PQresultStatus (R))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
935 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
936 case PGRES_BAD_RESPONSE:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
937 tag = "bad response [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
938 goto err;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
939 case PGRES_NONFATAL_ERROR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
940 tag = "non-fatal error [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
941 goto err;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
942 case PGRES_FATAL_ERROR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
943 tag = "fatal error [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
944 err:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
945 strncpy (buf, PQresultErrorMessage (R), sizeof (buf));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
946 buf [sizeof (buf) - 1] = '\0';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
947 PQclear (R);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
948 signal_ferror (Qprocess_error, tag, buf);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
949 /*NOTREACHED*/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
950 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
951 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
952 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
953 }
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 lisp_pgresult = allocate_pgresult ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
956 lisp_pgresult->pgresult = R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
957
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
958 return make_pgresult (lisp_pgresult);
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
961 DEFUN ("pq-send-query", Fpq_send_query, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
962 Submit a query to Postgres and don't wait for the result.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
963 Returns: t if successfully submitted
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
964 nil if error (conn->errorMessage is set)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
965 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
966 (conn, query))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
969 char *c_query;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
970
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
971 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
972 CHECK_STRING (query);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
973
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
974 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
975 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
976
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
977 TO_EXTERNAL_FORMAT (LISP_STRING, query,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
978 C_STRING_ALLOCA, c_query, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
979
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
980 if (PQsendQuery (P, c_query)) return Qt;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
981 else signal_ferror (Qprocess_error, "async query: %s", PQerrorMessage (P));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
982 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
983
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
984 DEFUN ("pq-get-result", Fpq_get_result, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
985 Retrieve an asynchronous result from a query.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
986 NIL is returned when no more query work remains.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
987 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
988 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
991 Lisp_PGresult *lisp_pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
992 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
993
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
994 CHECK_PGCONN (conn);
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 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
997 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
998
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
999 R = PQgetResult (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1000 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
1001
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1002 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1003 char *tag, buf[BLCKSZ];
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 switch (PQresultStatus (R))
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 case PGRES_BAD_RESPONSE:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1008 tag = "bad response [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1009 goto err;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1010 case PGRES_NONFATAL_ERROR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1011 tag = "non-fatal error [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1012 goto err;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1013 case PGRES_FATAL_ERROR:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1014 tag = "fatal error [%s]";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1015 err:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1016 strncpy (buf, PQresultErrorMessage (R), sizeof (buf));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1017 buf[sizeof (buf) - 1] = '\0';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1018 PQclear (R);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
1019 signal_ferror (Qprocess_error, tag, buf);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1020 /*NOTREACHED*/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1021 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1022 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1023 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1024 }
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 lisp_pgresult = allocate_pgresult();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1027 lisp_pgresult->pgresult = R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1028
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1029 return make_pgresult (lisp_pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1030 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1031
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1032 DEFUN ("pq-result-status", Fpq_result_status, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1033 Return result status of the query.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1034 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1035 (result))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1036 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1037 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1038 ExecStatusType est;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1039
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1040 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1041 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1042 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1043
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1044 switch ((est = PQresultStatus (R))) {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1045 case PGRES_EMPTY_QUERY: return Qpgres_empty_query;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1046 case PGRES_COMMAND_OK: return Qpgres_command_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1047 case PGRES_TUPLES_OK: return Qpgres_tuples_ok;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1048 case PGRES_COPY_OUT: return Qpgres_copy_out;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1049 case PGRES_COPY_IN: return Qpgres_copy_in;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1050 case PGRES_BAD_RESPONSE: return Qpgres_bad_response;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1051 case PGRES_NONFATAL_ERROR: return Qpgres_nonfatal_error;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1052 case PGRES_FATAL_ERROR: return Qpgres_fatal_error;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1053 default:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1054 /* 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
1055 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
1056 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1057 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1058
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1059 DEFUN ("pq-res-status", Fpq_res_status, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1060 Return stringified result status of the query.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1061 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1062 (result))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1063 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1064 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1065
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1066 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1067 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1068 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1069
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1070 return build_ext_string (PQresStatus (PQresultStatus (R)), PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1071 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1072
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1073 /* Sundry PGresult accessor functions */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1074 DEFUN ("pq-result-error-message", Fpq_result_error_message, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1075 Return last message associated with the query.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1076 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1077 (result))
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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1082 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1083 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1084
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1085 return build_ext_string (PQresultErrorMessage (R), PG_OS_CODING);
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1088 DEFUN ("pq-ntuples", Fpq_ntuples, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1089 Return the number of tuples (instances) in the query result.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1090 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1091 (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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1096 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1097 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1098
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1099 return make_int (PQntuples (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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1102 DEFUN ("pq-nfields", Fpq_nfields, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1103 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
1104 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1105 (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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1108
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1109 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1110 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1111 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1112
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1113 return make_int (PQnfields (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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1116 DEFUN ("pq-binary-tuples", Fpq_binary_tuples, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1117 Return t if the query result contains binary data, nil otherwise.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1118 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1119 (result))
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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1124 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1125 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1126
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1127 return (PQbinaryTuples (R)) ? Qt : Qnil;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1130 DEFUN ("pq-fname", Fpq_fname, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1131 Return the field (attribute) name associated with the given field index.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1132 Field indices start at 0.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1133 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1134 (result, field_index))
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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1139 CHECK_INT (field_index);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1140 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1141 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1142
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1143 return build_ext_string (PQfname (R, XINT (field_index)), PG_OS_CODING);
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1146 DEFUN ("pq-fnumber", Fpq_fnumber, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1147 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
1148 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1149 (result, field_name))
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 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1152 char *c_field_name;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1153
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1154 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1155 CHECK_STRING (field_name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1156 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1157 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1158
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1159 TO_EXTERNAL_FORMAT (LISP_STRING, field_name,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1160 C_STRING_ALLOCA, c_field_name, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1161
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1162 return make_int (PQfnumber (R, c_field_name));
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1165 DEFUN ("pq-ftype", Fpq_ftype, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1166 Return the field type associated with the given field index.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1167 The integer returned is the internal coding of the type. Field indices
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1168 start at 0.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1169 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1170 (result, field_num))
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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1175 CHECK_INT (field_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1176 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1177 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1178
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1179 return make_int (PQftype (R, XINT (field_num)));
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1182 DEFUN ("pq-fsize", Fpq_fsize, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1183 Return the field size in bytes associated with the given field index.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1184 Field indices start at 0.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1185 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1186 (result, field_index))
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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1191 CHECK_INT (field_index);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1192 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1193 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1194
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1195 return make_int (PQftype (R, XINT (field_index)));
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1198 DEFUN ("pq-fmod", Fpq_fmod, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1199 Return the type modifier associated with a field.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1200 Field indices start at 0.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1201 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1202 (result, field_index))
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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1207 CHECK_INT (field_index);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1208 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1209 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1210
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1211 return make_int (PQfmod (R, XINT (field_index)));
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1214 DEFUN ("pq-get-value", Fpq_get_value, 3, 3, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1215 Return a single field (attribute) value of one tuple of a PGresult.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1216 Tuple and field indices start at 0.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1217 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1218 (result, tup_num, field_num))
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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1223 CHECK_INT (tup_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1224 CHECK_INT (field_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1225 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1226 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1227
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1228 return build_ext_string (PQgetvalue (R, XINT (tup_num), XINT (field_num)),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1229 PG_OS_CODING);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1230 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1231
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1232 DEFUN ("pq-get-length", Fpq_get_length, 3, 3, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1233 Returns the length of a field value in bytes.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1234 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
1235 length returned does NOT include the size field of the varlena. (The
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1236 data returned by PQgetvalue doesn't either.)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1237 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1238 (result, tup_num, field_num))
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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1243 CHECK_INT (tup_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1244 CHECK_INT (field_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1245 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1246 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1247
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1248 return make_int (PQgetlength (R, XINT (tup_num), XINT (field_num)));
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1251 DEFUN ("pq-get-is-null", Fpq_get_is_null, 3, 3, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1252 Returns the null status of a field value.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1253 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1254 (result, tup_num, field_num))
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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1259 CHECK_INT (tup_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1260 CHECK_INT (field_num);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1261 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1262 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1263
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1264 return PQgetisnull (R, XINT (tup_num), XINT (field_num)) ? Qt : Qnil;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1267 DEFUN ("pq-cmd-status", Fpq_cmd_status, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1268 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
1269 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1270 (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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1275 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1276 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1277
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1278 return build_ext_string (PQcmdStatus (R), PG_OS_CODING);
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1281 DEFUN ("pq-cmd-tuples", Fpq_cmd_tuples, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1282 Returns the number of rows affected by the SQL command.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1283 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1284 (result))
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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1289 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1290 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1291
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1292 return build_ext_string (PQcmdTuples (R), PG_OS_CODING);
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1295 DEFUN ("pq-oid-value", Fpq_oid_value, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1296 Returns the object id of the tuple inserted.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1297 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1298 (result))
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 PGresult *R;
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 CHECK_PGRESULT (result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1303 R = (XPGRESULT (result))->pgresult;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1304 PUKE_IF_NULL (R);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1305
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1306 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1307 return make_int (PQoidValue (R));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1308 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1309 /* Use the old interface */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1310 return make_int (atoi (PQoidStatus (R)));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1311 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1312 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1313
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1314 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1315 DEFUN ("pq-set-nonblocking", Fpq_set_nonblocking, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1316 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
1317 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
1318 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
1319
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1320 Needs to be called only on a connected database connection.
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 (conn, arg))
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 PGconn *P;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1327 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1328 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1329
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1330 return make_int (PQsetnonblocking (P, !NILP (arg)));
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1333 DEFUN ("pq-is-nonblocking", Fpq_is_nonblocking, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1334 Return the blocking status of the database connection.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1335 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1336 (conn))
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 PGconn *P;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1341 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1342 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1343
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1344 return PQisnonblocking (P) ? Qt : Qnil;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1347 DEFUN ("pq-flush", Fpq_flush, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1348 Force the write buffer to be written (or at least try).
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1349 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1350 (conn))
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 PGconn *P;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1355 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1356 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1357
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1358 return make_int (PQflush (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 #endif
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 DEFUN ("pq-notifies", Fpq_notifies, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1363 Return the latest async notification that has not yet been handled.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1364 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
1365 The first element contains the relation name being notified, the second
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1366 element contains the backend process ID number. nil is returned if there
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1367 aren't any notifications to process.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1368 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1369 (conn))
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 /* This function cannot GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1372 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1373 PGnotify *PGN;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1374
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1375 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1376 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1377 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1378
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1379 PGN = PQnotifies (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1380 if (!PGN)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1381 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1382 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1383 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1384 Lisp_Object temp;
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 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
1387 free ((void *)PGN);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1388 return temp;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1389 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1390 }
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 #if defined (HAVE_POSTGRESQLV7) && defined(MULE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1393 DEFUN ("pq-env-2-encoding", Fpq_env_2_encoding, 0, 0, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1394 Get encoding id from environment variable PGCLIENTENCODING.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1395 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1396 ())
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1397 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1398 return make_int (PQenv2encoding ());
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 #endif /* MULE */
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 DEFUN ("pq-lo-import", Fpq_lo_import, 2, 2, 0, /*
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 (conn, filename))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1405 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1406 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1407 char *c_filename;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1408
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1409 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1410 CHECK_STRING (filename);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1411
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1412 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1413 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1414
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1415 TO_EXTERNAL_FORMAT (LISP_STRING, filename,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1416 C_STRING_ALLOCA, c_filename,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1417 Qfile_name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1418
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1419 return make_int ((int)lo_import (P, c_filename));
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1422 DEFUN ("pq-lo-export", Fpq_lo_export, 3, 3, 0, /*
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 (conn, oid, filename))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1427 char *c_filename;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1428
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1429 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1430 CHECK_INT (oid);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1431 CHECK_STRING (filename);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1432
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1433 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1434 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1435
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1436 TO_EXTERNAL_FORMAT (LISP_STRING, filename,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1437 C_STRING_ALLOCA, c_filename, Qfile_name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1438
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1439 return make_int ((int)lo_export (P, XINT (oid), c_filename));
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1442 DEFUN ("pq-make-empty-pgresult", Fpq_make_empty_pgresult, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1443 Make an empty PGresult object with the given status.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1444 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1445 (conn, 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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1448 Lisp_PGresult *lpgr;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1449 PGresult *R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1450 ExecStatusType est;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1451
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1452 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1453 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1454 CHECK_LIVE_CONNECTION (P); /* needed here? */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1455
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1456 if (EQ (status, Qpgres_empty_query)) est = PGRES_EMPTY_QUERY;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1457 else if (EQ (status, Qpgres_command_ok)) est = PGRES_COMMAND_OK;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1458 else if (EQ (status, Qpgres_tuples_ok)) est = PGRES_TUPLES_OK;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1459 else if (EQ (status, Qpgres_copy_out)) est = PGRES_COPY_OUT;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1460 else if (EQ (status, Qpgres_copy_in)) est = PGRES_COPY_IN;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1461 else if (EQ (status, Qpgres_bad_response)) est = PGRES_BAD_RESPONSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1462 else if (EQ (status, Qpgres_nonfatal_error)) est = PGRES_NONFATAL_ERROR;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1463 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
1464 else invalid_constant ("bad status symbol", status);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1465
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1466 R = PQmakeEmptyPGresult (P, est);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
1467 if (!R) out_of_memory (0, Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1468
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1469 lpgr = allocate_pgresult ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1470 lpgr->pgresult = R;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1471
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1472 return make_pgresult (lpgr);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1473 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1474
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1475 DEFUN ("pq-get-line", Fpq_get_line, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1476 Retrieve a line from server in copy in operation.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1477 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
1478 -1: Copying is complete
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1479 0: A record is complete
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1480 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
1481 operation.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1482 and the cdr cell is returned string data.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1483
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1484 The copy operation is complete when the value `\.' (backslash dot) is
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1485 returned.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1486 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1487 (conn))
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 char buffer[BLCKSZ]; /* size of a Postgres disk block */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1490 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1491 int ret;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1492
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1493 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1494 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1495 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1496
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1497 ret = PQgetline (P, buffer, sizeof (buffer));
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 return Fcons (make_int (ret), build_ext_string (buffer, PG_OS_CODING));
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1502 DEFUN ("pq-put-line", Fpq_put_line, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1503 Send a line to the server in copy out operation.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1504
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1505 Returns t if the operation succeeded, nil otherwise.
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 (conn, string))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1510 char *c_string;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1511
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1512 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1513 CHECK_STRING (string);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1514
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1515 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1516 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1517 TO_EXTERNAL_FORMAT (LISP_STRING, string,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1518 C_STRING_ALLOCA, c_string, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1519
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1520 return !PQputline (P, c_string) ? Qt : Qnil;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1523 DEFUN ("pq-get-line-async", Fpq_get_line_async, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1524 Get a line from the server in copy in operation asynchronously.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1525
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1526 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
1527 asynchronously, that is without blocking. Having issued the COPY command
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1528 and gotten a PGRES_COPY_OUT response, the app should call PQconsumeInput
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1529 and this routine until the end-of-data signal is detected. Unlike
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1530 PQgetline, this routine takes responsibility for detecting end-of-data.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1531
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1532 On each call, PQgetlineAsync will return data if a complete newline-
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1533 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
1534 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
1535 Otherwise, no data is returned until the rest of the line arrives.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1536
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1537 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
1538 from libpq's input buffer). The caller *must* next call PQendcopy and
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1539 then return to normal processing.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1540
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1541 RETURNS:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1542 -1 if the end-of-copy-data marker has been recognized
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1543 0 if no data is available
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1544 >0 the number of bytes returned.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1545 The data returned will not extend beyond a newline character. If possible
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1546 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
1547 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
1548 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
1549 last returned byte is '\n' or not.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1550 The returned string is *not* null-terminated.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1551 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1552 (conn))
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 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1555 char buffer[BLCKSZ];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1556 int ret;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1557
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1558 CHECK_PGCONN (conn);
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 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1561 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1562
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1563 ret = PQgetlineAsync (P, buffer, sizeof (buffer));
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 if (ret == -1) return Qt; /* done! */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1566 else if (!ret) return Qnil; /* no data yet */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1567 else return Fcons (make_int (ret),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1568 make_ext_string ((Extbyte *) buffer, ret, PG_OS_CODING));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1569 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1570
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1571 DEFUN ("pq-put-nbytes", Fpq_put_nbytes, 2, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1572 Asynchronous copy out.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1573 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1574 (conn, data))
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 /* 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
1577 PGconn *P;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1578 char *c_data;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1579
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1580 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1581 CHECK_STRING (data);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1582
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1583 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1584 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1585 TO_EXTERNAL_FORMAT (LISP_STRING, data,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1586 C_STRING_ALLOCA, c_data, Qnative);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1587
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1588 return !PQputnbytes (P, c_data, strlen (c_data)) ? Qt : Qnil;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1591 DEFUN ("pq-end-copy", Fpq_end_copy, 1, 1, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1592 End a copying operation.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1593 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1594 (conn))
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 PGconn *P;
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 CHECK_PGCONN (conn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1599 P = (XPGCONN (conn))->pgconn;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1600 CHECK_LIVE_CONNECTION (P);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1601
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1602 return PQendcopy (P) ? Qt : Qnil;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1605 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1606 syms_of_postgresql(void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1607 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1608 #ifndef RUNNING_XEMACS_21_1
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1609 INIT_LRECORD_IMPLEMENTATION (pgconn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1610 INIT_LRECORD_IMPLEMENTATION (pgresult);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1611 #endif
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
1612 DEFSYMBOL (Qpostgresql);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1613
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1614 /* opaque exported types */
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
1615 DEFSYMBOL (Qpgconnp);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 446
diff changeset
1616 DEFSYMBOL (Qpgresultp);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1617
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1618 /* connection status types */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1619 defsymbol (&Qpg_connection_ok, "pg::connection-ok");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1620 defsymbol (&Qpg_connection_bad, "pg::connection-bad");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1621 defsymbol (&Qpg_connection_started, "pg::connection-started");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1622 defsymbol (&Qpg_connection_made, "pg::connection-made");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1623 defsymbol (&Qpg_connection_awaiting_response, "pg::connection-awaiting-response");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1624 defsymbol (&Qpg_connection_auth_ok, "pg::connection-auth-ok");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1625 defsymbol (&Qpg_connection_setenv, "pg::connection-setenv");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1626
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1627 /* Fields of PGconn */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1628 defsymbol (&Qpqdb, "pq::db");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1629 defsymbol (&Qpquser, "pq::user");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1630 defsymbol (&Qpqpass, "pq::pass");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1631 defsymbol (&Qpqhost, "pq::host");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1632 defsymbol (&Qpqport, "pq::port");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1633 defsymbol (&Qpqtty, "pq::tty");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1634 defsymbol (&Qpqoptions, "pq::options");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1635 defsymbol (&Qpqstatus, "pq::status");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1636 defsymbol (&Qpqerrormessage, "pq::error-message");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1637 defsymbol (&Qpqbackendpid, "pq::backend-pid");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1638
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1639 /* Query status results */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1640 defsymbol (&Qpgres_empty_query, "pgres::empty-query");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1641 defsymbol (&Qpgres_command_ok, "pgres::command-ok");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1642 defsymbol (&Qpgres_tuples_ok, "pgres::tuples-ok");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1643 defsymbol (&Qpgres_copy_out, "pgres::copy-out");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1644 defsymbol (&Qpgres_copy_in, "pgres::copy-in");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1645 defsymbol (&Qpgres_bad_response, "pgres::bad-response");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1646 defsymbol (&Qpgres_nonfatal_error, "pgres::nonfatal-error");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1647 defsymbol (&Qpgres_fatal_error, "pgres::fatal-error");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1648
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1649 /* Poll status results */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1650 defsymbol (&Qpgres_polling_failed, "pgres::polling-failed");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1651 defsymbol (&Qpgres_polling_reading, "pgres::polling-reading");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1652 defsymbol (&Qpgres_polling_writing, "pgres::polling-writing");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1653 defsymbol (&Qpgres_polling_ok, "pgres::polling-ok");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1654 defsymbol (&Qpgres_polling_active, "pgres::polling-active");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1655
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1656 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1657 DEFSUBR (Fpq_connect_start);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1658 DEFSUBR (Fpq_connect_poll);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1659 #ifdef MULE
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1660 DEFSUBR (Fpq_client_encoding);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1661 DEFSUBR (Fpq_set_client_encoding);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1662 #endif /* MULE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1663 #endif /* HAVE_POSTGRESQLV7 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1664 DEFSUBR (Fpq_conn_defaults);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1665 DEFSUBR (Fpq_connectdb);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1666 DEFSUBR (Fpq_finish);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1667 DEFSUBR (Fpq_clear);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1668 DEFSUBR (Fpq_is_busy);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1669 DEFSUBR (Fpq_consume_input);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1670
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1671 DEFSUBR (Fpq_reset);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1672 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1673 DEFSUBR (Fpq_reset_start);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1674 DEFSUBR (Fpq_reset_poll);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1675 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1676 DEFSUBR (Fpq_request_cancel);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1677 DEFSUBR (Fpq_pgconn);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1678
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1679 DEFSUBR (Fpq_exec);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1680 DEFSUBR (Fpq_send_query);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1681 DEFSUBR (Fpq_get_result);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1682 DEFSUBR (Fpq_result_status);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1683 DEFSUBR (Fpq_res_status);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1684 DEFSUBR (Fpq_result_error_message);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1685 DEFSUBR (Fpq_ntuples);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1686 DEFSUBR (Fpq_nfields);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1687 DEFSUBR (Fpq_binary_tuples);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1688 DEFSUBR (Fpq_fname);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1689 DEFSUBR (Fpq_fnumber);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1690 DEFSUBR (Fpq_ftype);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1691 DEFSUBR (Fpq_fsize);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1692 DEFSUBR (Fpq_fmod);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1693 /***/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1694 DEFSUBR (Fpq_get_value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1695 DEFSUBR (Fpq_get_length);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1696 DEFSUBR (Fpq_get_is_null);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1697 DEFSUBR (Fpq_cmd_status);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1698 DEFSUBR (Fpq_cmd_tuples);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1699 DEFSUBR (Fpq_oid_value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1700
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1701 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1702 DEFSUBR (Fpq_set_nonblocking);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1703 DEFSUBR (Fpq_is_nonblocking);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1704 DEFSUBR (Fpq_flush);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1705 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1706 DEFSUBR (Fpq_notifies);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1707
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1708 #if defined (HAVE_POSTGRESQLV7) && defined(MULE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1709 DEFSUBR (Fpq_env_2_encoding);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1710 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1711
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1712 DEFSUBR (Fpq_lo_import);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1713 DEFSUBR (Fpq_lo_export);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1714
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1715 DEFSUBR (Fpq_make_empty_pgresult);
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 /* copy in/out functions */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1718 DEFSUBR (Fpq_get_line);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1719 DEFSUBR (Fpq_put_line);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1720 DEFSUBR (Fpq_get_line_async);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1721 DEFSUBR (Fpq_put_nbytes);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1722 DEFSUBR (Fpq_end_copy);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1723 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1724
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1725 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1726 vars_of_postgresql(void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1727 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1728 Fprovide (Qpostgresql);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1729 #ifdef HAVE_POSTGRESQLV7
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1730 Fprovide (intern ("postgresqlv7"));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1731 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1732 #ifndef RUNNING_XEMACS_21_1
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1733 Vpg_coding_system = Qnative;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1734 DEFVAR_LISP ("pg-coding-system", &Vpg_coding_system /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1735 Default Postgres client coding system.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1736 */ );
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1737 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1738
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1739 DEFVAR_LISP ("pg:host", &VXPGHOST /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1740 Default PostgreSQL server name.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1741 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
1742 initial value is set from the PGHOST environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1743 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1744
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1745 DEFVAR_LISP ("pg:user", &VXPGUSER /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1746 Default PostgreSQL user name.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1747 This value is used when connecting to a database for authentication.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1748 The initial value is set from the PGUSER environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1749 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1750
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1751 DEFVAR_LISP ("pg:options", &VXPGOPTIONS /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1752 Default PostgreSQL user name.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1753 This value is used when connecting to a database for authentication.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1754 The initial value is set from the PGUSER environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1755 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1756
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1757 DEFVAR_LISP ("pg:port", &VXPGPORT /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1758 Default port to connect to PostgreSQL backend.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1759 This value is used when connecting to a database.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1760 The initial value is set from the PGPORT environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1761 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1762
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1763 DEFVAR_LISP ("pg:tty", &VXPGTTY /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1764 Default debugging TTY.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1765 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
1766 The initial value is set from the PGTTY environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1767 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1768
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1769 DEFVAR_LISP ("pg:database", &VXPGDATABASE /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1770 Default database to connect to.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1771 The initial value is set from the PGDATABASE environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1772 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1773
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1774 DEFVAR_LISP ("pg:realm", &VXPGREALM /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1775 Default kerberos realm to use for authentication.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1776 The initial value is set from the PGREALM environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1777 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1778
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1779 #ifdef MULE
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1780 /* 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
1781 autodetect the coding system from the database. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1782 DEFVAR_LISP ("pg:client-encoding", &VXPGCLIENTENCODING /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1783 Default client encoding to use.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1784 The initial value is set from the PGCLIENTENCODING environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1785 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1786 #endif
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 #if !defined(HAVE_POSTGRESQLV7)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1789 DEFVAR_LISP ("pg:authtype", &VXPGAUTHTYPE /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1790 Default authentication to use.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1791 The initial value is set from the PGAUTHTYPE environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1792
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1793 WARNING: This variable has gone away in versions of PostgreSQL newer
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1794 than 6.5.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1795 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1796 #endif
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 DEFVAR_LISP ("pg:geqo", &VXPGGEQO /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1799 Genetic Query Optimizer options.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1800 The initial value is set from the PGGEQO environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1801 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1802
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1803 DEFVAR_LISP ("pg:cost-index", &VXPGCOSTINDEX /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1804 Default cost index options.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1805 The initial value is set from the PGCOSTINDEX environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1806 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1807
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1808 DEFVAR_LISP ("pg:cost-heap", &VXPGCOSTHEAP /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1809 Default cost heap options.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1810 The initial value is set from the PGCOSTHEAP environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1811 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1812
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1813 DEFVAR_LISP ("pg:tz", &VXPGTZ /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1814 Default timezone to use.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1815 The initial value is set from the PGTZ environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1816 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1817
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1818 DEFVAR_LISP ("pg:date-style", &VXPGDATESTYLE /*
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1819 Default date style to use.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1820 The initial value is set from the PGDATESTYLE environment variable.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1821 */ );
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1822 }
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 /* These initializations should not be done at dump-time. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1825 void
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1826 init_postgresql_from_environment (void)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1827 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1828 Ibyte *p;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1829
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1830 #define FROB(envvar, var) \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1831 if ((p = egetenv (envvar))) \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1832 var = build_intstring (p); \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1833 else \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1834 var = Qnil
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1835
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1836 if (initialized)
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 FROB ("PGHOST", VXPGHOST);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1839 FROB ("PGUSER", VXPGUSER);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1840 FROB ("PGOPTIONS", VXPGOPTIONS);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1841
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1842 if ((p = egetenv ("PGPORT")))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1843 VXPGPORT = make_int (atoi ((char *) p));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1844 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1845 VXPGPORT = Qnil;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1846
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1847 FROB ("PGTTY", VXPGTTY);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1848 FROB ("PGDATABASE", VXPGDATABASE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1849 FROB ("PGREALM", VXPGREALM);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1850 #ifdef MULE
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1851 /* 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
1852 autodetect the coding system from the database. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1853 FROB ("PGCLIENTENCODING", VXPGCLIENTENCODING);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1854 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1855
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1856 #if !defined(HAVE_POSTGRESQLV7)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1857 FROB ("PGAUTHTYPE", VXPGAUTHTYPE);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1858 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1859
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1860 FROB ("PGGEQO", VXPGGEQO);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1861 FROB ("PGCOSTINDEX", VXPGCOSTINDEX);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1862 FROB ("PGCOSTHEAP", VXPGCOSTHEAP);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1863 FROB ("PGTZ", VXPGTZ);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1864 FROB ("PGDATESTYLE", VXPGDATESTYLE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
1865 #undef FROB
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1866 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1867 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
1868