annotate man/lispref/postgresql.texi @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents
children de805c49cfc1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1 @c -*-texinfo-*-
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
2 @c This is part of the XEmacs Lisp Reference Manual.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
3 @c Copyright (C) 2000 Electrotechnical Laboratory, JAPAN
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
4 @c Licensed to the Free Software Foundation
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
5 @c See the file lispref.texi for copying conditions.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
6 @c Thank you Oscar Figueiredo! This file was shamelessly cloned from
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
7 @c ldap.texi.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
8 @setfilename ../../info/postgresql.info
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
9 @node PostgreSQL Support, Internationalization, LDAP Support, top
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
10 @chapter PostgreSQL Support
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
11 @cindex PostgreSQL
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
12
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
13 XEmacs can be linked with PostgreSQL libpq run-time support to provide
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
14 relational database access from Emacs Lisp code.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
15
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
16 @menu
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
17 * Building XEmacs with PostgreSQL support::
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
18 * XEmacs PostgreSQL libpq API::
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
19 * XEmacs PostgreSQL libpq Examples::
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
20 @end menu
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
21
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
22 @node Building XEmacs with PostgreSQL support, XEmacs PostgreSQL libpq API, ,PostgreSQL Support
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
23 @comment node-name, next, previous, up
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
24 @section Building XEmacs with PostgreSQL support
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
25
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
26 XEmacs PostgreSQL support requires linking to the PostgreSQL libpq.so
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
27 library. Describing how to build and install PostgreSQL is beyond the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
28 scope of this document, see the PostgreSQL manual for details.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
29
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
30 If you have installed XEmacs from one of the binary kits on
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
31 (@url{ftp://ftp.xemacs.org/}), or are using an XEmacs binary from a CD
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
32 ROM, you should have XEmacs PostgreSQL support by default. If you are
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
33 building XEmacs from source on a Linux system with PostgreSQL installed
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
34 into the default location, it should be autodetected when you run
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
35 configure. If you have installed PostgreSQL into its non-Linux default
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
36 location, @file{/usr/local/pgsql}, you must specify
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
37 @code{--site-prefixes=/usr/local/pgsql} when you run configure. If
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
38 you installed PostgreSQL into another location, use that instead of
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
39 @file{/usr/local/pgsql} when specifying @code{--site-prefixes}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
40
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
41 As of XEmacs 21.2, PostgreSQL versions 6.5.3 and 7.0 are supported.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
42 XEmacs Lisp support for V7.0 is somewhat more extensive than support for
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
43 V6.5. In particular, asynchronous queries are supported.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
44
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
45 @node XEmacs PostgreSQL libpq API, XEmacs PostgreSQL libpq Examples, Building XEmacs with PostgreSQL support, PostgreSQL Support
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
46 @comment node-name, next, previous, up
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
47 @section XEmacs PostgreSQL libpq API
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
48
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
49 XEmacs PostgreSQL API is intended to be a policy-free, low-level binding
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
50 to libpq. The intent is to provide all the basic functionality and then
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
51 let high level Lisp code decide its own policies.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
52
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
53 This documentation assumes that the reader has knowledge of SQL, but
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
54 requires no prior knowledge of libpq.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
55
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
56 There are many examples in this manual and some setup will be required.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
57 In order to run most of the following examples, the following code needs
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
58 to be executed. In addition to the data is in this table, nearly all of
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
59 the examples will assume that the free variable @code{P} refers to this
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
60 database connection. The examples in the original edition of this
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
61 manual were run against Postgres 7.0beta1.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
62
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
63 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
64 (progn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
65 (setq P (pq-connectdb ""))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
66 ;; id is the primary key, shikona is a Japanese word that
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
67 ;; means `the professional name of a Sumo wrestler', and
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
68 ;; rank is the Sumo rank name.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
69 (pq-exec P (concat "CREATE TABLE xemacs_test"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
70 " (id int, shikona text, rank text);"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
71 (pq-exec P "COPY xemacs_test FROM stdin;")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
72 (pq-put-line P "1\tMusashimaru\tYokuzuna\n")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
73 (pq-put-line P "2\tDejima\tOozeki\n")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
74 (pq-put-line P "3\tMusoyama\tSekiwake\n")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
75 (pq-put-line P "4\tMiyabiyama\tSekiwake\n")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
76 (pq-put-line P "5\tWakanoyama\tMaegashira\n")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
77 (pq-put-line P "\\.\n")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
78 (pq-end-copy P))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
79 @result{} nil
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
80 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
81
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
82 @menu
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
83 * libpq Lisp Variables::
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
84 * libpq Lisp Symbols and DataTypes::
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
85 * Synchronous Interface Functions::
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
86 * Asynchronous Interface Functions::
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
87 * Large Object Support::
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
88 * Other libpq Functions::
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
89 * Unimplemented libpq Functions::
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
90 @end menu
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
91
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
92 @node libpq Lisp Variables, libpq Lisp Symbols and DataTypes, XEmacs PostgreSQL libpq API, XEmacs PostgreSQL libpq API
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
93 @comment node-name, next, previous, up
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
94 @subsection libpq Lisp Variables
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
95
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
96 Various Unix environment variables are used by libpq to provide defaults
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
97 to the many different parameters. In the XEmacs Lisp API, these
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
98 environment variables are bound to Lisp variables to provide more
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
99 convenient access to Lisp Code. These variables are passed to the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
100 backend database server during the establishment of a database
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
101 connection and when the @code{pq-setenv} call is made.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
102
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
103 @defvar pg:host
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
104 Initialized from the @var{PGHOST} environment variable. The default
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
105 host to connect to.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
106 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
107
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
108 @defvar pg:user
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
109 Initialized from the @var{PGUSER} environment variable. The default
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
110 database user name.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
111 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
112
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
113 @defvar pg:options
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
114 Initialized from the @var{PGOPTIONS} environment variable. Default
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
115 additional server options.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
116 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
117
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
118 @defvar pg:port
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
119 Initialized from the @var{PGPORT} environment variable. The default TCP
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
120 port to connect to.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
121 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
122
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
123 @defvar pg:tty
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
124 Initialized from the @var{PGTTY} environment variable. The default
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
125 debugging TTY.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
126
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
127 Compatibility note: Debugging TTYs are turned off in the XEmacs Lisp
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
128 binding.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
129 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
130
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
131 @defvar pg:database
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
132 Initialized from the @var{PGDATABASE} environment variable. The default
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
133 database to connect to.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
134 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
135
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
136 @defvar pg:realm
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
137 Initialized from the @var{PGREALM} environment variable. The default
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
138 Kerberos realm.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
139 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
140
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
141 @defvar pg:client-encoding
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
142 Initialized from the @var{PGCLIENTENCODING} environment variable. The
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
143 default client encoding.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
144
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
145 Compatibility note: This variable is not present in non-Mule XEmacsen.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
146 This variable is not present in versions of libpq prior to 7.0.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
147 In the current implementation, client encoding is equivalent to the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
148 @code{file-name-coding-system} format.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
149 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
150
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
151 @c unused
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
152 @defvar pg:authtype
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
153 Initialized from the @var{PGAUTHTYPE} environment variable. The default
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
154 authentication scheme used.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
155
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
156 Compatibility note: This variable is unused in versions of libpq after
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
157 6.5. It is not implemented at all in the XEmacs Lisp binding.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
158 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
159
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
160 @defvar pg:geqo
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
161 Initialized from the @var{PGGEQO} environment variable. Genetic
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
162 optimizer options.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
163 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
164
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
165 @defvar pg:cost-index
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
166 Initialized from the @var{PGCOSTINDEX} environment variable. Cost index
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
167 options.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
168 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
169
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
170 @defvar pg:cost-heap
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
171 Initialized from the @var{PGCOSTHEAP} environment variable. Cost heap
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
172 options.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
173 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
174
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
175 @defvar pg:tz
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
176 Initialized from the @var{PGTZ} environment variable. Default
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
177 timezone.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
178 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
179
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
180 @defvar pg:date-style
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
181 Initialized from the @var{PGDATESTYLE} environment variable. Default
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
182 date style in returned date objects.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
183 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
184
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
185 @defvar pg-coding-system
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
186 This is a variable controlling which coding system is used to encode
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
187 non-ASCII strings sent to the database.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
188
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
189 Compatibility Note: This variable is not present in InfoDock.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
190 @end defvar
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
191
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
192 @node libpq Lisp Symbols and DataTypes, Synchronous Interface Functions, libpq Lisp Variables, XEmacs PostgreSQL libpq API
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
193 @comment node-name, next, previous, up
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
194 @subsection libpq Lisp Symbols and Datatypes
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
195
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
196 The following set of symbols are used to represent the intermediate
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
197 states involved in the asynchronous interface.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
198
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
199 @defvr {Symbol} pgres::polling-failed
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
200 Undocumented. A fatal error has occurred during processing of an
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
201 asynchronous operation.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
202 @end defvr
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
203
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
204 @defvr {Symbol} pgres::polling-reading
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
205 An intermediate status return during an asynchronous operation. It
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
206 indicates that one may use @code{select} before polling again.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
207 @end defvr
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
208
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
209 @defvr {Symbol} pgres::polling-writing
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
210 An intermediate status return during an asynchronous operation. It
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
211 indicates that one may use @code{select} before polling again.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
212 @end defvr
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
213
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
214 @defvr {Symbol} pgres::polling-ok
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
215 An asynchronous operation has successfully completed.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
216 @end defvr
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
217
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
218 @defvr {Symbol} pgres::polling-active
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
219 An intermediate status return during an asynchronous operation. One can
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
220 call the poll function again immediately.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
221 @end defvr
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
222
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
223 @defun pq-pgconn conn field
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
224 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
225 @var{field} A symbol indicating which field of PGconn to fetch. Possible
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
226 values are shown in the following table.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
227 @table @code
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
228 @item pq::db
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
229 Database name
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
230 @item pq::user
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
231 Database user name
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
232 @item pq::pass
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
233 Database user's password
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
234 @item pq::host
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
235 Hostname database server is running on
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
236 @item pq::port
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
237 TCP port number used in the connection
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
238 @item pq::tty
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
239 Debugging TTY
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
240
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
241 Compatibility note: Debugging TTYs are not used in the XEmacs Lisp API.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
242 @item pq::options
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
243 Additional server options
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
244 @item pq::status
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
245 Connection status. Possible return values are shown in the following
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
246 table.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
247 @table @code
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
248 @item pg::connection-ok
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
249 The normal, connected status.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
250 @item pg::connection-bad
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
251 The connection is not open and the PGconn object needs to be deleted by
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
252 @code{pq-finish}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
253 @item pg::connection-started
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
254 An asynchronous connection has been started, but is not yet complete.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
255 @item pg::connection-made
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
256 An asynchronous connect has been made, and there is data waiting to be sent.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
257 @item pg::connection-awaiting-response
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
258 Awaiting data from the backend during an asynchronous connection.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
259 @item pg::connection-auth-ok
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
260 Received authentication, waiting for the backend to start up.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
261 @item pg::connection-setenv
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
262 Negotiating environment during an asynchronous connection.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
263 @end table
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
264 @item pq::error-message
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
265 The last error message that was delivered to this connection.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
266 @item pq::backend-pid
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
267 The process ID of the backend database server.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
268 @end table
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
269 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
270
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
271 The @code{PGresult} object is used by libpq to encapsulate the results
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
272 of queries. The printed representation takes on four forms. When the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
273 PGresult object contains tuples from an SQL @code{SELECT} it will look
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
274 like:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
275
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
276 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
277 (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
278 @result{} #<PGresult PGRES_TUPLES_OK[5] - SELECT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
279 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
280
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
281 The number in brackets indicates how many rows of data are available.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
282 When the PGresult object is the result of a command query that doesn't
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
283 return anything, it will look like:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
284
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
285 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
286 (pq-exec P "CREATE TABLE a_new_table (i int);")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
287 @result{} #<PGresult PGRES_COMMAND_OK - CREATE>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
288 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
289
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
290 When either the query is a command-type query that can affect a number
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
291 of different rows, but doesn't return any of them it will look like:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
292
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
293 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
294 (progn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
295 (pq-exec P "INSERT INTO a_new_table VALUES (1);")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
296 (pq-exec P "INSERT INTO a_new_table VALUES (2);")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
297 (pq-exec P "INSERT INTO a_new_table VALUES (3);")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
298 (setq R (pq-exec P "DELETE FROM a_new_table;")))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
299 @result{} #<PGresult PGRES_COMMAND_OK[3] - DELETE 3>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
300 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
301
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
302 Lastly, when the underlying PGresult object has been deallocated
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
303 directly by @code{pq-clear} the printed representation will look like:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
304
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
305 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
306 (progn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
307 (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
308 (pq-clear R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
309 R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
310 @result{} #<PGresult DEAD>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
311 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
312
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
313 The following set of functions are accessors to various data in the PGresult
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
314 object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
315
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
316 @defun pq-result-status result
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
317 Return status of a query result.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
318 @var{result} is a PGresult object. The return value is one of the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
319 symbols in the following table.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
320 @table @code
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
321 @item pgres::empty-query
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
322 A query contained no text. This is usually the result of a recoverable
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
323 error, or a minor programming error.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
324 @item pgres::command-ok
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
325 A query command that doesn't return anything was executed properly by
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
326 the backend.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
327 @item pgres::tuples-ok
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
328 A query command that returns tuples was executed properly by the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
329 backend.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
330 @item pgres::copy-out
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
331 Copy Out data transfer is in progress.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
332 @item pgres::copy-in
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
333 Copy In data transfer is in progress.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
334 @item pgres::bad-response
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
335 An unexpected response was received from the backend.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
336 @item pgres::nonfatal-error
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
337 Undocumented. This value is returned when the libpq function
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
338 @code{PQresultStatus} is called with a @var{NULL} pointer.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
339 @item pgres::fatal-error
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
340 Undocumented. An error has occurred in processing the query and the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
341 operation was not completed.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
342 @end table
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
343 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
344
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
345 @defun pq-res-status result
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
346 Return the query result status as a string, not a symbol.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
347 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
348
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
349 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
350 (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
351 @result{} #<PGresult PGRES_TUPLES_OK[5] - SELECT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
352 (pq-res-status R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
353 @result{} "PGRES_TUPLES_OK"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
354 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
355 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
356
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
357 @defun pq-result-error-message result
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
358 Return an error message generated by the query, if any.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
359 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
360
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
361 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
362 (setq R (pq-exec P "SELECT * FROM xemacs-test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
363 @result{} <A fatal error is signaled in the echo area>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
364 (pq-result-error-message R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
365 @result{} "ERROR: parser: parse error at or near \"-\"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
366 "
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
367 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
368 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
369
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
370 @defun pq-ntuples result
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
371 Return the number of tuples in the query result.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
372 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
373
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
374 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
375 (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
376 @result{} #<PGresult PGRES_TUPLES_OK[5] - SELECT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
377 (pq-ntuples R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
378 @result{} 5
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
379 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
380 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
381
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
382 @defun pq-nfields result
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
383 Return the number of fields in each tuple of the query result.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
384 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
385
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
386 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
387 (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
388 @result{} #<PGresult PGRES_TUPLES_OK[5] - SELECT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
389 (pq-nfields R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
390 @result{} 3
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
391 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
392 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
393
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
394 @defun pq-binary-tuples result
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
395 Returns t if binary tuples are present in the results, nil otherwise.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
396 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
397
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
398 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
399 (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
400 @result{} #<PGresult PGRES_TUPLES_OK[5] - SELECT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
401 (pq-binary-tuples R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
402 @result{} nil
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
403 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
404 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
405
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
406 @defun pq-fname result field-index
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
407 Returns the name of a specific field.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
408 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
409 @var{field-index} is the number of the column to select from. The first
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
410 column is number zero.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
411
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
412 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
413 (let (i l)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
414 (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
415 (setq i (pq-nfields R))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
416 (while (>= (decf i) 0)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
417 (push (pq-fname R i) l))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
418 l)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
419 @result{} ("id" "shikona" "rank")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
420 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
421 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
422
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
423 @defun pq-fnumber result field-name
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
424 Return the field number corresponding to the given field name.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
425 -1 is returned on a bad field name.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
426 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
427 @var{field-name} is a string representing the field name to find.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
428 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
429 (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
430 @result{} #<PGresult PGRES_TUPLES_OK[5] - SELECT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
431 (pq-fnumber R "id")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
432 @result{} 0
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
433 (pq-fnumber R "Not a field")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
434 @result{} -1
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
435 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
436 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
437
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
438 @defun pq-ftype result field-num
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
439 Return an integer code representing the data type of the specified column.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
440 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
441 @var{field-num} is the field number.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
442
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
443 The return value of this function is the Object ID (Oid) in the database
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
444 of the type. Further queries need to be made to various system tables
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
445 in order to convert this value into something useful.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
446 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
447
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
448 @defun pq-fmod result field-num
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
449 Return the type modifier code associated with a field. Field numbers
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
450 start at zero.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
451 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
452 @var{field-index} selects which field to use.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
453 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
454
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
455 @defun pq-fsize result field-index
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
456 Return size of the given field.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
457 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
458 @var{field-index} selects which field to use.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
459
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
460 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
461 (let (i l)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
462 (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
463 (setq i (pq-nfields R))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
464 (while (>= (decf i) 0)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
465 (push (list (pq-ftype R i) (pq-fsize R i)) l))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
466 l)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
467 @result{} ((23 23) (25 25) (25 25))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
468 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
469 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
470
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
471 @defun pq-get-value result tup-num field-num
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
472 Retrieve a return value.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
473 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
474 @var{tup-num} selects which tuple to fetch from.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
475 @var{field-num} selects which field to fetch from.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
476
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
477 Both tuples and fields are numbered from zero.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
478
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
479 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
480 (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
481 @result{} #<PGresult PGRES_TUPLES_OK[5] - SELECT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
482 (pq-get-value R 0 1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
483 @result{} "Musashimaru"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
484 (pq-get-value R 1 1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
485 @result{} "Dejima"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
486 (pq-get-value R 2 1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
487 @result{} "Musoyama"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
488 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
489 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
490
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
491 @defun pq-get-length result tup-num field-num
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
492 Return the length of a specific value.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
493 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
494 @var{tup-num} selects which tuple to fetch from.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
495 @var{field-num} selects which field to fetch from.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
496
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
497 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
498 (setq R (pq-exec P "SELECT * FROM xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
499 @result{} #<PGresult PGRES_TUPLES_OK[5] - SELECT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
500 (pq-get-length R 0 1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
501 @result{} 11
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
502 (pq-get-length R 1 1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
503 @result{} 6
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
504 (pq-get-length R 2 1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
505 @result{} 8
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
506 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
507 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
508
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
509 @defun pq-get-is-null result tup-num field-num
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
510 Return t if the specific value is the SQL @var{NULL}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
511 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
512 @var{tup-num} selects which tuple to fetch from.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
513 @var{field-num} selects which field to fetch from.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
514 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
515
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
516 @defun pq-cmd-status result
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
517 Return a summary string from the query.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
518 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
519 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
520 @comment This example was written on day 3 of the 2000 Haru Basho.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
521 (pq-exec P "INSERT INTO xemacs_test
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
522 VALUES (6, 'Wakanohana', 'Yokozuna');")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
523 @result{} #<PGresult PGRES_COMMAND_OK[1] - INSERT 542086 1>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
524 (pq-cmd-status R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
525 @result{} "INSERT 542086 1"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
526 (setq R (pq-exec P "UPDATE xemacs_test SET rank='retired'
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
527 WHERE shikona='Wakanohana';"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
528 @result{} #<PGresult PGRES_COMMAND_OK[1] - UPDATE 1>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
529 (pq-cmd-status R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
530 @result{} "UPDATE 1"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
531 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
532
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
533 Note that the first number returned from an insertion, like in the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
534 example, is an object ID number and will almost certainly vary from
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
535 system to system since object ID numbers in Postgres must be unique
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
536 across all databases.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
537 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
538
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
539 @defun pq-cmd-tuples result
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
540 Return the number of tuples if the last command was an INSERT/UPDATE/DELETE.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
541 If the last command was something else, the empty string is returned.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
542 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
543
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
544 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
545 (setq R (pq-exec P "INSERT INTO xemacs_test VALUES
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
546 (7, 'Takanohana', 'Yokuzuna');"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
547 @result{} #<PGresult PGRES_COMMAND_OK[1] - INSERT 38688 1>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
548 (pq-cmd-tuples R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
549 @result{} "1"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
550 (setq R (pq-exec P "SELECT * from xemacs_test;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
551 @result{} #<PGresult PGRES_TUPLES_OK[7] - SELECT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
552 (pq-cmd-tuples R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
553 @result{} ""
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
554 (setq R (pq-exec P "DELETE FROM xemacs_test
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
555 WHERE shikona LIKE '%hana';"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
556 @result{} #<PGresult PGRES_COMMAND_OK[2] - DELETE 2>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
557 (pq-cmd-tuples R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
558 @result{} "2"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
559 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
560 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
561
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
562 @defun pq-oid-value result
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
563 Return the object id of the insertion if the last command was an INSERT.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
564 0 is returned if the last command was not an insertion.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
565 @var{result} is a PGresult object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
566
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
567 In the first example, the numbers you will see on your local system will
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
568 almost certainly be different, however the second number from the right
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
569 in the unprintable PGresult object and the number returned by
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
570 @code{pq-oid-value} should match.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
571 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
572 (setq R (pq-exec P "INSERT INTO xemacs_test VALUES
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
573 (8, 'Terao', 'Maegashira');"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
574 @result{} #<PGresult PGRES_COMMAND_OK[1] - INSERT 542089 1>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
575 (pq-oid-value R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
576 @result{} 542089
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
577 (setq R (pq-exec P "SELECT shikona FROM xemacs_test
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
578 WHERE rank='Maegashira';"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
579 @result{} #<PGresult PGRES_TUPLES_OK[2] - SELECT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
580 (pq-oid-value R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
581 @result{} 0
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
582 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
583 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
584
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
585 @defun pq-make-empty-pgresult conn status
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
586 Create an empty pgresult with the given status.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
587 @var{conn} a database connection object
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
588 @var{status} a value that can be returned by @code{pq-result-status}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
589
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
590 The caller is responsible for making sure the return value gets properly
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
591 freed.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
592 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
593
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
594 @node Synchronous Interface Functions, Asynchronous Interface Functions, libpq Lisp Symbols and DataTypes, XEmacs PostgreSQL libpq API
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
595 @comment node-name, next, previous, up
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
596 @subsection Synchronous Interface Functions
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
597
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
598 @defun pq-connectdb conninfo
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
599 Establish a (synchronous) database connection.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
600 @var{conninfo} A string of blank separated options. Options are of the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
601 form ``@var{option} = @var{value}''. If @var{value} contains blanks, it
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
602 must be single quoted. Blanks around the equal sign are optional.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
603 Multiple option assignments are blank separated.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
604 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
605 (pq-connectdb "dbname=japanese port = 25432")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
606 @result{} #<PGconn localhost:25432 steve/japanese>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
607 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
608 The printed representation of a database connection object has four
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
609 fields. The first field is the hostname where the database server is
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
610 running (in this case localhost), the second field is the port number,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
611 the third field is the database user name, and the fourth field is the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
612 name of the database.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
613
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
614 Database connection objects which have been disconnected and will
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
615 generate an immediate error if they are used look like:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
616 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
617 #<PGconn BAD>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
618 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
619 Bad connections can be reestablished with @code{pq-reset}, or deleted
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
620 entirely with @code{pq-finish}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
621
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
622 A database connection object that has been deleted looks like:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
623 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
624 (let ((P1 (pq-connectdb "")))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
625 (pq-finish P1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
626 P1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
627 @result{} #<PGconn DEAD>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
628 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
629
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
630 Note that database connection objects are the most heavy weight objects
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
631 in XEmacs Lisp at this writing, usually representing as much as several
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
632 megabytes of virtual memory on the machine the database server is
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
633 running on. It is wisest to explicitly delete them when you are
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
634 finished with them, rather than letting garbage collection do it. An
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
635 example idiom is:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
636
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
637 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
638 (let ((P (pq-connectiondb "")))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
639 (unwind-protect
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
640 (progn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
641 (...)) ; access database here
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
642 (pq-finish P)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
643 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
644
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
645 The following options are available in the options string:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
646 @table @code
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
647 @item authtype
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
648 Authentication type. Same as @var{PGAUTHTYPE}. This is no longer used.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
649 @item user
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
650 Database user name. Same as @var{PGUSER}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
651 @item password
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
652 Database password.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
653 @item dbname
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
654 Database name. Same as @var{PGDATABASE}
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
655 @item host
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
656 Symbolic hostname. Same as @var{PGHOST}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
657 @item hostaddr
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
658 Host address as four octets (eg. like 192.168.1.1).
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
659 @item port
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
660 TCP port to connect to. Same as @var{PGPORT}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
661 @item tty
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
662 Debugging TTY. Same as @var{PGTTY}. This value is suppressed in the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
663 XEmacs Lisp API.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
664 @item options
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
665 Extra backend database options. Same as @var{PGOPTIONS}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
666 @end table
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
667 A database connection object is returned regardless of whether a
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
668 connection was established or not.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
669 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
670
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
671 @defun pq-reset conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
672 Reestablish database connection.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
673 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
674
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
675 This function reestablishes a database connection using the original
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
676 connection parameters. This is useful if something has happened to the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
677 TCP link and it has become broken.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
678 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
679
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
680 @defun pq-exec conn query
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
681 Make a synchronous database query.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
682 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
683 @var{query} A string containing an SQL query.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
684 A PGresult object is returned, which in turn may be queried by its many
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
685 accessor functions to retrieve state out of it. If the query string
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
686 contains multiple SQL commands, only results from the final command are
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
687 returned.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
688
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
689 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
690 (setq R (pq-exec P "SELECT * FROM xemacs_test;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
691 DELETE FROM xemacs_test WHERE id=8;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
692 @result{} #<PGresult PGRES_COMMAND_OK[1] - DELETE 1>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
693 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
694 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
695
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
696 @defun pq-notifies conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
697 Return the latest async notification that has not yet been handled.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
698 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
699 If there has been a notification, then a list of two elements will be returned.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
700 The first element contains the relation name being notified, the second
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
701 element contains the backend process ID number. nil is returned if there
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
702 aren't any notifications to process.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
703 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
704
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
705 @defun PQsetenv conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
706 Synchronous transfer of environment variables to a backend
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
707 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
708
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
709 Environment variable transfer is done as a normal part of database
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
710 connection.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
711
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
712 Compatibility note: This function was present but not documented in versions
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
713 of libpq prior to 7.0.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
714 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
715
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
716 @node Asynchronous Interface Functions, Large Object Support, Synchronous Interface Functions, XEmacs PostgreSQL libpq API
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
717 @comment node-name, next, previous, up
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
718 @subsection Asynchronous Interface Functions
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
719
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
720 Making command by command examples is too complex with the asynchronous
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
721 interface functions. See the examples section for complete calling
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
722 sequences.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
723
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
724 @defun pq-connect-start conninfo
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
725 Begin establishing an asynchronous database connection.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
726 @var{conninfo} A string containing the connection options. See the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
727 documentation of @code{pq-connectdb} for a listing of all the available
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
728 flags.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
729 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
730
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
731 @defun pq-connect-poll conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
732 An intermediate function to be called during an asynchronous database
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
733 connection.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
734 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
735 The result codes are documented in a previous section.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
736 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
737
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
738 @defun pq-is-busy conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
739 Returns t if @code{pq-get-result} would block waiting for input.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
740 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
741 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
742
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
743 @defun pq-consume-input conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
744 Consume any available input from the backend.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
745 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
746
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
747 Nil is returned if anything bad happens.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
748 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
749
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
750 @defun pq-reset-start conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
751 Reset connection to the backend asynchronously.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
752 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
753 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
754
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
755 @defun pq-reset-poll conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
756 Poll an asynchronous reset for completion
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
757 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
758 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
759
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
760 @defun pq-reset-cancel conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
761 Attempt to request cancellation of the current operation.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
762 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
763
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
764 The return value is t if the cancel request was successfully
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
765 dispatched, nil if not (in which case conn->errorMessage is set).
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
766 Note: successful dispatch is no guarantee that there will be any effect at
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
767 the backend. The application must read the operation result as usual.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
768 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
769
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
770 @defun pq-send-query conn query
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
771 Submit a query to Postgres and don't wait for the result.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
772 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
773 Returns: t if successfully submitted
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
774 nil if error (conn->errorMessage is set)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
775 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
776
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
777 @defun pq-get-result conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
778 Retrieve an asynchronous result from a query.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
779 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
780
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
781 NIL is returned when no more query work remains.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
782 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
783
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
784 @defun pq-set-nonblocking conn arg
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
785 Sets the PGconn's database connection non-blocking if the arg is TRUE
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
786 or makes it non-blocking if the arg is FALSE, this will not protect
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
787 you from PQexec(), you'll only be safe when using the non-blocking API.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
788 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
789 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
790
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
791 @defun pq-is-nonblocking conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
792 Return the blocking status of the database connection
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
793 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
794 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
795
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
796 @defun pq-flush conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
797 Force the write buffer to be written (or at least try)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
798 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
799 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
800
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
801 @defun PQsetenvStart conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
802 Start asynchronously passing environment variables to a backend.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
803 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
804
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
805 Compatibility note: this function is only available with libpq-7.0.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
806 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
807
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
808 @defun PQsetenvPoll conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
809 Check an asynchronous enviroment variables transfer for completion.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
810 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
811
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
812 Compatibility note: this function is only available with libpq-7.0.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
813 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
814
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
815 @defun PQsetenvAbort conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
816 Attempt to terminate an asynchronous environment variables transfer.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
817 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
818
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
819 Compatibility note: this function is only available with libpq-7.0.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
820 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
821
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
822 @node Large Object Support, Other libpq Functions, Asynchronous Interface Functions, XEmacs PostgreSQL libpq API
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
823 @comment node-name, next, previous, up
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
824 @subsection Large Object Support
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
825
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
826 @defun pq-lo-import conn filename
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
827 Import a file as a large object into the database.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
828 @var{conn} a database connection object
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
829 @var{filename} filename to import
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
830
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
831 On success, the object id is returned.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
832 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
833
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
834 @defun pq-lo-export conn oid filename
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
835 Copy a large object in the database into a file.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
836 @var{conn} a database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
837 @var{oid} object id number of a large object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
838 @var{filename} filename to export to.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
839 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
840
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
841 @node Other libpq Functions, Unimplemented libpq Functions, Large Object Support, XEmacs PostgreSQL libpq API
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
842 @comment node-name, next, previous, up
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
843 @subsection Other libpq Functions
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
844
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
845 @defun pq-finish conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
846 Destroy a database connection object by calling free on it.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
847 @var{conn} a database connection object
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
848
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
849 It is possible to not call this routine because the usual XEmacs garbage
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
850 collection mechanism will call the underlying libpq routine whenever it
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
851 is releasing stale @code{PGconn} objects. However, this routine is
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
852 useful in @code{unwind-protect} clauses to make connections go away
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
853 quickly when unrecoverable errors have occurred.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
854
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
855 After calling this routine, the printed representation of the XEmacs
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
856 wrapper object will contain the string ``DEAD''.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
857 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
858
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
859 @defun pq-client-encoding conn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
860 Return the client encoding as an integer code.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
861 @var{conn} a database connection object
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
862
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
863 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
864 (pq-client-encoding P)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
865 @result{} 1
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
866 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
867
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
868 Compatibility note: This function did not exist prior to libpq-7.0 and
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
869 does not exist in a non-Mule XEmacs.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
870 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
871
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
872 @defun pq-set-client-encoding conn encoding
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
873 Set client coding system.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
874 @var{conn} a database connection object
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
875 @var{encoding} a string representing the desired coding system
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
876
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
877 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
878 (pq-set-client-encoding P "EUC_JP")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
879 @result{} 0
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
880 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
881
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
882 The current idiom for ensuring proper coding system conversion is the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
883 following (illustrated for EUC Japanese encoding):
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
884 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
885 (setq P (pq-connectdb "..."))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
886 (let ((file-name-coding-system 'euc-jp)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
887 (pg-coding-system 'euc-jp))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
888 (pq-set-client-encoding "EUC_JP")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
889 ...)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
890 (pq-finish P)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
891 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
892 Compatibility note: This function did not exist prior to libpq-7.0 and
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
893 does not exist in a non-Mule XEmacs.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
894 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
895
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
896 @defun pq-env-2-encoding
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
897 Return the integer code representing the coding system in @var{PGCLIENTENCODING}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
898
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
899 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
900 (pq-env-2-encoding)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
901 @result{} 0
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
902 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
903 Compatibility note: This function did not exist prior to libpq-7.0 and
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
904 does not exist in a non-Mule XEmacs.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
905 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
906
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
907 @defun pq-clear res
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
908 Destroy a query result object by calling free() on it.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
909 @var{res} a query result object
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
910
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
911 Note: The memory allocation systems of libpq and XEmacs are different.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
912 The XEmacs representation of a query result object will have both the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
913 XEmacs version and the libpq version freed at the next garbage collection
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
914 when the object is no longer being referenced. Calling this function does
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
915 not release the XEmacs object, it is still subject to the usual rules for
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
916 Lisp objects. The printed representation of the XEmacs object will contain
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
917 the string ``DEAD'' after this routine is called indicating that it is no
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
918 longer useful for anything.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
919 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
920
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
921 @defun pq-conn-defaults
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
922 Return a data structure that represents the connection defaults.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
923 The data is returned as a list of lists, where each sublist contains
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
924 info regarding a single option.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
925 @end defun
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
926
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
927 @node Unimplemented libpq Functions, , Other libpq Functions, XEmacs PostgreSQL libpq API
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
928 @comment node-name, next, previous, up
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
929 @subsection Unimplemented libpq Functions
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
930
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
931 @deftypefn {Unimplemented Function} PGconn *PQsetdbLogin (char *pghost, char *pgport, char *pgoptions, char *pgtty, char *dbName, char *login, char *pwd)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
932 Synchronous database connection.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
933 @var{pghost} is the hostname of the PostgreSQL backend to connect to.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
934 @var{pgport} is the TCP port number to use.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
935 @var{pgoptions} specifies other backend options.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
936 @var{pgtty} specifies the debugging tty to use.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
937 @var{dbName} specifies the database name to use.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
938 @var{login} specifies the database user name.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
939 @var{pwd} specifies the database user's password.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
940
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
941 This routine is deprecated as of libpq-7.0, and its functionality can be
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
942 replaced by external Lisp code if needed.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
943 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
944
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
945 @deftypefn {Unimplemented Function} PGconn *PQsetdb (char *pghost, char *pgport, char *pgoptions, char *pgtty, char *dbName)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
946 Synchronous database connection.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
947 @var{pghost} is the hostname of the PostgreSQL backend to connect to.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
948 @var{pgport} is the TCP port number to use.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
949 @var{pgoptions} specifies other backend options.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
950 @var{pgtty} specifies the debugging tty to use.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
951 @var{dbName} specifies the database name to use.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
952
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
953 This routine was deprecated in libpq-6.5.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
954 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
955
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
956 @deftypefn {Unimplemented Function} int PQsocket (PGconn *conn)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
957 Return socket file descriptor to a backend database process.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
958 @var{conn} database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
959 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
960
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
961 @deftypefn {Unimplemented Function} void PQprint (FILE *fout, PGresult *res, PGprintOpt *ps)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
962 Print out the results of a query to a designated C stream.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
963 @var{fout} C stream to print to
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
964 @var{res} the query result object to print
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
965 @var{ps} the print options structure.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
966
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
967 This routine is deprecated as of libpq-7.0 and cannot be sensibly exported
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
968 to XEmacs Lisp.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
969 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
970
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
971 @deftypefn {Unimplemented Function} void PQdisplayTuples (PGresult *res, FILE *fp, int fillAlign, char *fieldSep, int printHeader, int quiet)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
972 @var{res} query result object to print
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
973 @var{fp} C stream to print to
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
974 @var{fillAlign} pad the fields with spaces
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
975 @var{fieldSep} field separator
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
976 @var{printHeader} display headers?
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
977 @var{quiet}
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
978
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
979 This routine was deprecated in libpq-6.5.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
980 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
981
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
982 @deftypefn {Unimplemented Function} void PQprintTuples (PGresult *res, FILE *fout, int printAttName, int terseOutput, int width)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
983 @var{res} query result object to print
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
984 @var{fout} C stream to print to
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
985 @var{printAttName} print attribute names
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
986 @var{terseOutput} delimiter bars
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
987 @var{width} width of column, if 0, use variable width
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
988
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
989 This routine was deprecated in libpq-6.5.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
990 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
991
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
992 @deftypefn {Unimplemented Function} int PQmblen (char *s, int encoding)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
993 Determine length of a multibyte encoded char at @code{*s}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
994 @var{s} encoded string
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
995 @var{encoding} type of encoding
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
996
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
997 Compatibility note: This function was introduced in libpq-7.0.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
998 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
999
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1000 @deftypefn {Unimplemented Function} void PQtrace (PGconn *conn, FILE *debug_port)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1001 Enable tracing on @code{debug_port}.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1002 @var{conn} database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1003 @var{debug_port} C output stream to use.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1004 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1005
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1006 @deftypefn {Unimplemented Function} void PQuntrace (PGconn *conn)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1007 Disable tracing.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1008 @var{conn} database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1009 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1010
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1011 @deftypefn {Unimplemented Function} char *PQoidStatus (PGconn *conn)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1012 Return the object id as a string of the last tuple inserted.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1013 @var{conn} database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1014
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1015 Compatibility note: This function is deprecated in libpq-7.0, however it
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1016 is used internally by the XEmacs binding code when linked against versions
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1017 prior to 7.0.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1018 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1019
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1020 @deftypefn {Unimplemented Function} PGresult *PQfn (PGconn *conn, int fnid, int *result_buf, int *result_len, int result_is_int, PQArgBlock *args, int nargs)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1021 ``Fast path'' interface --- not really recommended for application use
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1022 @var{conn} A database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1023 @var{fnid}
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1024 @var{result_buf}
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1025 @var{result_len}
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1026 @var{result_is_int}
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1027 @var{args}
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1028 @var{nargs}
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1029 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1030
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1031 The following set of very low level large object functions aren't
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1032 appropriate to be exported to Lisp.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1033
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1034 @deftypefn {Unimplemented Function} int pq-lo-open (PGconn *conn, int lobjid, int mode)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1035 @var{conn} a database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1036 @var{lobjid} a large object ID.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1037 @var{mode} opening modes.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1038 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1039
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1040 @deftypefn {Unimplemented Function} int pq-lo-close (PGconn *conn, int fd)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1041 @var{conn} a database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1042 @var{fd} a large object file descriptor
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1043 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1044
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1045 @deftypefn {Unimplemented Function} int pq-lo-read (PGconn *conn, int fd, char *buf, int len)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1046 @var{conn} a database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1047 @var{fd} a large object file descriptor.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1048 @var{buf} buffer to read into.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1049 @var{len} size of buffer.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1050 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1051
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1052 @deftypefn {Unimplemented Function} int pq-lo-write (PGconn *conn, int fd, char *buf, size_t len)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1053 @var{conn} a database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1054 @var{fd} a large object file descriptor.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1055 @var{buf} buffer to write from.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1056 @var{len} size of buffer.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1057 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1058
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1059 @deftypefn {Unimplemented Function} int pq-lo-lseek (PGconn *conn, int fd, int offset, int whence)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1060 @var{conn} a database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1061 @var{fd} a large object file descriptor.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1062 @var{offset}
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1063 @var{whence}
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1064 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1065
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1066 @deftypefn {Unimplemented Function} int pq-lo-creat (PGconn *conn, int mode)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1067 @var{conn} a database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1068 @var{mode} opening modes.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1069 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1070
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1071 @deftypefn {Unimplemented Function} int pq-lo-tell (PGconn *conn, int fd)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1072 @var{conn} a database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1073 @var{fd} a large object file descriptor.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1074 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1075
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1076 @deftypefn {Unimplemented Function} int pq-lo-unlink (PGconn *conn, int lobjid)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1077 @var{conn} a database connection object.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1078 @var{lbojid} a large object ID.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1079 @end deftypefn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1080
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1081 @node XEmacs PostgreSQL libpq Examples, , XEmacs PostgreSQL libpq API, PostgreSQL Support
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1082 @comment node-name, next, previous, up
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1083 @section XEmacs PostgreSQL libpq Examples
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1084
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1085 This is an example of one method of establishing an asynchronous
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1086 connection.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1087
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1088 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1089 (defun database-poller (P)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1090 (message "%S before poll" (pq-pgconn P 'pq::status))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1091 (pq-connect-poll P)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1092 (message "%S after poll" (pq-pgconn P 'pq::status))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1093 (if (eq (pq-pgconn P 'pq::status) 'pg::connection-ok)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1094 (message "Done!")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1095 (add-timeout .1 'database-poller P)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1096 @result{} database-poller
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1097 (progn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1098 (setq P (pq-connect-start ""))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1099 (add-timeout .1 'database-poller P))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1100 @result{} pg::connection-started before poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1101 @result{} pg::connection-made after poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1102 @result{} pg::connection-made before poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1103 @result{} pg::connection-awaiting-response after poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1104 @result{} pg::connection-awaiting-response before poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1105 @result{} pg::connection-auth-ok after poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1106 @result{} pg::connection-auth-ok before poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1107 @result{} pg::connection-setenv after poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1108 @result{} pg::connection-setenv before poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1109 @result{} pg::connection-ok after poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1110 @result{} Done!
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1111 P
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1112 @result{} #<PGconn localhost:25432 steve/steve>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1113 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1114
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1115 Here is an example of one method of doing an asynchronous reset.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1116
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1117 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1118 (defun database-poller (P)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1119 (let (PS)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1120 (message "%S before poll" (pq-pgconn P 'pq::status))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1121 (setq PS (pq-reset-poll P))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1122 (message "%S after poll [%S]" (pq-pgconn P 'pq::status) PS)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1123 (if (eq (pq-pgconn P 'pq::status) 'pg::connection-ok)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1124 (message "Done!")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1125 (add-timeout .1 'database-poller P))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1126 @result{} database-poller
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1127 (progn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1128 (pq-reset-start P)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1129 (add-timeout .1 'database-poller P))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1130 @result{} pg::connection-started before poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1131 @result{} pg::connection-made after poll [pgres::polling-writing]
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1132 @result{} pg::connection-made before poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1133 @result{} pg::connection-awaiting-response after poll [pgres::polling-reading]
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1134 @result{} pg::connection-awaiting-response before poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1135 @result{} pg::connection-setenv after poll [pgres::polling-reading]
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1136 @result{} pg::connection-setenv before poll
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1137 @result{} pg::connection-ok after poll [pgres::polling-ok]
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1138 @result{} Done!
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1139 P
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1140 @result{} #<PGconn localhost:25432 steve/steve>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1141 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1142
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1143 And finally, an asynchronous query.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1144
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1145 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1146 (defun database-poller (P)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1147 (let (R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1148 (pq-consume-input P)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1149 (if (pq-is-busy P)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1150 (add-timeout .1 'database-poller P)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1151 (setq R (pq-get-result P))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1152 (if R
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1153 (progn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1154 (push R result-list)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1155 (add-timeout .1 'database-poller P))))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1156 @result{} database-poller
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1157 (when (pq-send-query P "SELECT * FROM xemacs_test;")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1158 (setq result-list nil)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1159 (add-timeout .1 'database-poller P))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1160 @result{} 885
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1161 ;; wait a moment
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1162 result-list
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1163 @result{} (#<PGresult PGRES_TUPLES_OK - SELECT>)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1164 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1165
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1166 Here is an example showing how multiple SQL statements in a single query
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1167 can have all their results collected.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1168 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1169 ;; Using the same @code{database-poller} function from the previous example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1170 (when (pq-send-query P "SELECT * FROM xemacs_test;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1171 SELECT * FROM pg_database;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1172 SELECT * FROM pg_user;")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1173 (setq result-list nil)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1174 (add-timeout .1 'database-poller P))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1175 @result{} 1782
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1176 ;; wait a moment
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1177 result-list
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1178 @result{} (#<PGresult PGRES_TUPLES_OK - SELECT> #<PGresult PGRES_TUPLES_OK - SELECT> #<PGresult PGRES_TUPLES_OK - SELECT>)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1179 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1180
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1181 Here is an example which illustrates collecting all data from a query,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1182 including the field names.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1183
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1184 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1185 (defun pg-util-query-results (results)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1186 "Retrieve results of last SQL query into a list structure."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1187 (let ((i (1- (pq-ntuples R)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1188 j l1 l2)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1189 (while (>= i 0)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1190 (setq j (1- (pq-nfields R)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1191 (setq l2 nil)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1192 (while (>= j 0)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1193 (push (pq-get-value R i j) l2)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1194 (decf j))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1195 (push l2 l1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1196 (decf i))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1197 (setq j (1- (pq-nfields R)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1198 (setq l2 nil)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1199 (while (>= j 0)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1200 (push (pq-fname R j) l2)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1201 (decf j))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1202 (push l2 l1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1203 l1))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1204 @result{} pg-util-query-results
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1205 (setq R (pq-exec P "SELECT * FROM xemacs_test ORDER BY field2 DESC;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1206 @result{} #<PGresult PGRES_TUPLES_OK - SELECT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1207 (pg-util-query-results R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1208 @result{} (("f1" "field2") ("a" "97") ("b" "97") ("stuff" "42") ("a string" "12") ("foo" "10") ("string" "2") ("text" "1"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1209 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1210
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1211 Here is an example of a query that uses a database cursor.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1212
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1213 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1214 (let (data R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1215 (setq R (pq-exec P "BEGIN;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1216 (setq R (pq-exec P "DECLARE k_cursor CURSOR FOR SELECT * FROM xemacs_test ORDER BY f1 DESC;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1217
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1218 (setq R (pq-exec P "FETCH k_cursor;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1219 (while (eq (pq-ntuples R) 1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1220 (push (list (pq-get-value R 0 0) (pq-get-value R 0 1)) data)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1221 (setq R (pq-exec P "FETCH k_cursor;")))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1222 (setq R (pq-exec P "END;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1223 data)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1224 @result{} (("a" "97") ("a string" "12") ("b" "97") ("foo" "10") ("string" "2") ("stuff" "42") ("text" "1"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1225 @end example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1226
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1227 Here's another example of cursors, this time with a Lisp macro to
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1228 implement a mapping function over a table.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1229
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1230 @example
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1231 (defmacro map-db (P table condition callout)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1232 `(let (R)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1233 (pq-exec ,P "BEGIN;")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1234 (pq-exec ,P (concat "DECLARE k_cursor CURSOR FOR SELECT * FROM "
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1235 ,table
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1236 " "
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1237 ,condition
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1238 " ORDER BY f1 DESC;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1239 (setq R (pq-exec P "FETCH k_cursor;"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1240 (while (eq (pq-ntuples R) 1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1241 (,callout (pq-get-value R 0 0) (pq-get-value R 0 1))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1242 (setq R (pq-exec P "FETCH k_cursor;")))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1243 (pq-exec P "END;")))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1244 @result{} map-db
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1245 (defun callback (arg1 arg2)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1246 (message "arg1 = %s, arg2 = %s" arg1 arg2))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1247 @result{} callback
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1248 (map-db P "xemacs_test" "WHERE field2 > 10" callback)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1249 @result{} arg1 = stuff, arg2 = 42
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1250 @result{} arg1 = b, arg2 = 97
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1251 @result{} arg1 = a string, arg2 = 12
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1252 @result{} arg1 = a, arg2 = 97
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1253 @result{} #<PGresult PGRES_COMMAND_OK - COMMIT>
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents:
diff changeset
1254 @end example