Copyright (C) 2000 Electrotechnical Laboratory, JAPAN.
Licensed to the Free Software Foundation.
- Author: SL Baur <steve@beopen.com>
- Maintainer: SL Baur <steve@beopen.com>
+ Author: SL Baur <steve@xemacs.org>
+ Maintainer: SL Baur <steve@xemacs.org>
Please send patches to this file to me first before submitting them to
xemacs-patches.
*/
#if (EMACS_MAJOR_VERSION == 21) && (EMACS_MINOR_VERSION < 2)
#define RUNNING_XEMACS_21_1 1
-#define POSTGRES_INCLUDE(file) <file>
#endif
/* #define POSTGRES_LO_IMPORT_IS_VOID 1 */
#include "lisp.h"
#include "sysdep.h"
#include "buffer.h"
-
-#include POSTGRES_INCLUDE (libpq-fe.h)
#include "postgresql.h"
#ifdef RUNNING_XEMACS_21_1 /* handle interface changes */
-#define I_HATE_CONST CONST
#define PG_OS_CODING FORMAT_FILENAME
#define TO_EXTERNAL_FORMAT(a,from,b,to,c) GET_C_STRING_EXT_DATA_ALLOCA(from,FORMAT_FILENAME,to)
#else
-#define I_HATE_CONST const
#ifdef MULE
#define PG_OS_CODING Fget_coding_system(Vpg_coding_system)
#else
/* notices */
static void
-xemacs_notice_processor (void *arg, I_HATE_CONST char *msg)
+xemacs_notice_processor (void *arg, const char *msg)
{
warn_when_safe (Qpostgresql, Qnotice, "%s", msg);
}
(conn))
{
PGconn *P;
- PostgresPollingStatusType PS;
+ PostgresPollingStatusType polling_status;
CHECK_PGCONN (conn);
P = (XPGCONN (conn))->pgconn;
CHECK_LIVE_CONNECTION (P);
- PS = PQconnectPoll (P);
- switch (PS)
+ polling_status = PQconnectPoll (P);
+ switch (polling_status)
{
case PGRES_POLLING_FAILED:
/* Something Bad has happened */
return Qpgres_polling_active;
default:
/* they've added a new field we don't know about */
- error ("Help! Unknown status code %08x from backend!", PS);
+ error ("Help! Unknown status code %08x from backend!", polling_status);
}
}
}
DEFUN ("pq-reset-poll", Fpq_reset_poll, 1, 1, 0, /*
-Poll an asynchronous reset for completion
+Poll an asynchronous reset for completion.
*/
(conn))
{
PGconn *P;
- PostgresPollingStatusType PS;
+ PostgresPollingStatusType polling_status;
CHECK_PGCONN (conn);
P = (XPGCONN (conn))->pgconn;
CHECK_LIVE_CONNECTION (P);
- PS = PQresetPoll (P);
- switch (PS)
+ polling_status = PQresetPoll (P);
+ switch (polling_status)
{
case PGRES_POLLING_FAILED:
/* Something Bad has happened */
return Qpgres_polling_active;
default:
/* they've added a new field we don't know about */
- error ("Help! Unknown status code %08x from backend!", PS);
+ error ("Help! Unknown status code %08x from backend!", polling_status);
}
}
#endif
return build_ext_string (PQoptions(P), PG_OS_CODING);
else if (EQ (field, Qpqstatus))
{
- ExecStatusType est;
+ ConnStatusType cst;
/* PQstatus Returns the status of the connection. The status can be
CONNECTION_OK or CONNECTION_BAD.
ConnStatusType PQstatus(PGconn *conn)
*/
- switch ((est = PQstatus (P)))
+ switch ((cst = PQstatus (P)))
{
case CONNECTION_OK: return Qpg_connection_ok;
case CONNECTION_BAD: return Qpg_connection_bad;
#endif /* HAVE_POSTGRESQLV7 */
default:
/* they've added a new field we don't know about */
- error ("Help! Unknown exec status code %08x from backend!", est);
+ error ("Help! Unknown connection status code %08x from backend!", cst);
}
}
else if (EQ (field, Qpqerrormessage))
}
DEFUN ("pq-cmd-tuples", Fpq_cmd_tuples, 1, 1, 0, /*
-Returns the number of rows affected by the SQL command
+Returns the number of rows affected by the SQL command.
*/
(result))
{
}
DEFUN ("pq-is-nonblocking", Fpq_is_nonblocking, 1, 1, 0, /*
-Return the blocking status of the database connection
+Return the blocking status of the database connection.
*/
(conn))
{
}
DEFUN ("pq-flush", Fpq_flush, 1, 1, 0, /*
-Force the write buffer to be written (or at least try)
+Force the write buffer to be written (or at least try).
*/
(conn))
{
if (ret == -1) return Qt; /* done! */
else if (!ret) return Qnil; /* no data yet */
else return Fcons (make_int (ret),
- make_ext_string (buffer, ret, PG_OS_CODING));
+ make_ext_string ((Extbyte *) buffer, ret, PG_OS_CODING));
}
DEFUN ("pq-put-nbytes", Fpq_put_nbytes, 2, 2, 0, /*
void
vars_of_postgresql(void)
{
- char *p;
-
Fprovide (Qpostgresql);
#ifdef HAVE_POSTGRESQLV7
Fprovide (intern ("postgresqlv7"));
*/ );
#endif
+ DEFVAR_LISP ("pg:host", &VXPGHOST /*
+Default PostgreSQL server name.
+If not set, the server running on the local host is used. The
+initial value is set from the PGHOST environment variable.
+*/ );
+
+ DEFVAR_LISP ("pg:user", &VXPGUSER /*
+Default PostgreSQL user name.
+This value is used when connecting to a database for authentication.
+The initial value is set from the PGUSER environment variable.
+*/ );
+
+ DEFVAR_LISP ("pg:options", &VXPGOPTIONS /*
+Default PostgreSQL user name.
+This value is used when connecting to a database for authentication.
+The initial value is set from the PGUSER environment variable.
+*/ );
+
+ DEFVAR_LISP ("pg:port", &VXPGPORT /*
+Default port to connect to PostgreSQL backend.
+This value is used when connecting to a database.
+The initial value is set from the PGPORT environment variable.
+*/ );
+
+ DEFVAR_LISP ("pg:tty", &VXPGTTY /*
+Default debugging TTY.
+There is no useful setting of this variable in the XEmacs Lisp API.
+The initial value is set from the PGTTY environment variable.
+*/ );
+
+ DEFVAR_LISP ("pg:database", &VXPGDATABASE /*
+Default database to connect to.
+The initial value is set from the PGDATABASE environment variable.
+*/ );
+
+ DEFVAR_LISP ("pg:realm", &VXPGREALM /*
+Default kerberos realm to use for authentication.
+The initial value is set from the PGREALM environment variable.
+*/ );
+
+#ifdef MULE
+ /* It's not clear whether this is any use. My intent is to
+ autodetect the coding system from the database. */
+ DEFVAR_LISP ("pg:client-encoding", &VXPGCLIENTENCODING /*
+Default client encoding to use.
+The initial value is set from the PGCLIENTENCODING environment variable.
+*/ );
+#endif
+
+#if !defined(HAVE_POSTGRESQLV7)
+ DEFVAR_LISP ("pg:authtype", &VXPGAUTHTYPE /*
+Default authentication to use.
+The initial value is set from the PGAUTHTYPE environment variable.
+
+WARNING: This variable has gone away in versions of PostgreSQL newer
+than 6.5.
+*/ );
+#endif
+
+ DEFVAR_LISP ("pg:geqo", &VXPGGEQO /*
+Genetic Query Optimizer options.
+The initial value is set from the PGGEQO environment variable.
+*/ );
+
+ DEFVAR_LISP ("pg:cost-index", &VXPGCOSTINDEX /*
+Default cost index options.
+The initial value is set from the PGCOSTINDEX environment variable.
+*/ );
+
+ DEFVAR_LISP ("pg:cost-heap", &VXPGCOSTHEAP /*
+Default cost heap options.
+The initial value is set from the PGCOSTHEAP environment variable.
+*/ );
+
+ DEFVAR_LISP ("pg:tz", &VXPGTZ /*
+Default timezone to use.
+The initial value is set from the PGTZ environment variable.
+*/ );
+
+ DEFVAR_LISP ("pg:date-style", &VXPGDATESTYLE /*
+Default date style to use.
+The initial value is set from the PGDATESTYLE environment variable.
+*/ );
+}
+
+/* These initializations should not be done at dump-time. */
+void
+init_postgresql_from_environment(void)
+{
+ char *p;
+
if ((p = getenv ("PGHOST")))
{
VXPGHOST = build_ext_string (p, PG_OS_CODING);
{
VXPGHOST = Qnil;
}
- DEFVAR_LISP ("pg:host", &VXPGHOST /*
-Default PostgreSQL server name.
-If not set, the server running on the local host is used. The
-initial value is set from the PGHOST environment variable.
-*/ );
if ((p = getenv ("PGUSER")))
{
{
VXPGUSER = Qnil;
}
- DEFVAR_LISP ("pg:user", &VXPGUSER /*
-Default PostgreSQL user name.
-This value is used when connecting to a database for authentication.
-The initial value is set from the PGUSER environment variable.
-*/ );
if ((p = getenv ("PGOPTIONS")))
{
{
VXPGOPTIONS = Qnil;
}
- DEFVAR_LISP ("pg:options", &VXPGOPTIONS /*
-Default PostgreSQL user name.
-This value is used when connecting to a database for authentication.
-The initial value is set from the PGUSER environment variable.
-*/ );
if ((p = getenv ("PGPORT")))
{
{
VXPGPORT = Qnil;
}
- DEFVAR_LISP ("pg:port", &VXPGPORT /*
-Default port to connect to PostgreSQL backend.
-This value is used when connecting to a database.
-The initial value is set from the PGPORT environment variable.
-*/ );
if ((p = getenv ("PGTTY")))
{
{
VXPGTTY = Qnil;
}
- DEFVAR_LISP ("pg:tty", &VXPGTTY /*
-Default debugging TTY.
-There is no useful setting of this variable in the XEmacs Lisp API.
-The initial value is set from the PGTTY environment variable.
-*/ );
if ((p = getenv ("PGDATABASE")))
{
{
VXPGDATABASE = Qnil;
}
- DEFVAR_LISP ("pg:database", &VXPGDATABASE /*
-Default database to connect to.
-The initial value is set from the PGDATABASE environment variable.
-*/ );
if ((p = getenv ("PGREALM")))
{
{
VXPGREALM = Qnil;
}
- DEFVAR_LISP ("pg:realm", &VXPGREALM /*
-Default kerberos realm to use for authentication.
-The initial value is set from the PGREALM environment variable.
-*/ );
#ifdef MULE
/* It's not clear whether this is any use. My intent is to
{
VXPGCLIENTENCODING = Qnil;
}
- DEFVAR_LISP ("pg:client-encoding", &VXPGCLIENTENCODING /*
-Default client encoding to use.
-The initial value is set from the PGCLIENTENCODING environment variable.
-*/ );
#endif
#if !defined(HAVE_POSTGRESQLV7)
{
VXPGAUTHTYPE = Qnil;
}
- DEFVAR_LISP ("pg:authtype", &VXPGAUTHTYPE /*
-Default authentication to use.
-The initial value is set from the PGAUTHTYPE environment variable.
-
-WARNING: This variable has gone away in versions of PostgreSQL newer
-than 6.5.
-*/ );
#endif
if ((p = getenv ("PGGEQO")))
{
VXPGGEQO = Qnil;
}
- DEFVAR_LISP ("pg:geqo", &VXPGGEQO /*
-Genetic Query Optimizer options.
-The initial value is set from the PGGEQO environment variable.
-*/ );
if ((p = getenv ("PGCOSTINDEX")))
{
{
VXPGCOSTINDEX = Qnil;
}
- DEFVAR_LISP ("pg:cost-index", &VXPGCOSTINDEX /*
-Default cost index options.
-The initial value is set from the PGCOSTINDEX environment variable.
-*/ );
if ((p = getenv ("PGCOSTHEAP")))
{
{
VXPGCOSTHEAP = Qnil;
}
- DEFVAR_LISP ("pg:cost-heap", &VXPGCOSTHEAP /*
-Default cost heap options.
-The initial value is set from the PGCOSTHEAP environment variable.
-*/ );
if ((p = getenv ("PGTZ")))
{
{
VXPGTZ = Qnil;
}
- DEFVAR_LISP ("pg:tz", &VXPGTZ /*
-Default timezone to use.
-The initial value is set from the PGTZ environment variable.
-*/ );
if ((p = getenv ("PGDATESTYLE")))
{
{
VXPGDATESTYLE = Qnil;
}
- DEFVAR_LISP ("pg:date-style", &VXPGDATESTYLE /*
-Default date style to use.
-The initial value is set from the PGDATESTYLE environment variable.
-*/ );
}
+