Attached are patches to XEmacs 21.1.10 to add runtime support for the
PostgreSQL relational database. I've tested it against both 6.5.3 and
7.0beta1. Mulish database stuffs are known to cause crashes, however
anything US-ASCII based seems to be O.K. Multiple and networked
connections work, as do connecting to a version of the postmaster
different from the version of the library linked to. I will be adding
support for asynchronous queries, non-US ASCII character sets and
documentation before merging into the 21.2 source tree.
If you installed Postgres from source RPMs, it will be automatically
autodetected. If you installed into the default location
(/usr/local/pgsql), or somewhere else, you will need to add the base
directory to --site-prefixes (eg. --site-prefixes=/usr/local/pgsql).
sample session:
(setq P (pq-connectdb "host=zaizen.m17n.org port=25432"))
#<PGconn zaizen.m17n.org:25432 steve/steve>
(setq R (pq-exec P "SELECT * FROM pg_database;"))
#<PGresult PGRES_TUPLES_OK - SELECT>
(require 'pg-util)
pg-util
(pg-util-query-results R)
(("datname" "datdba" "encoding" "datpath")
("template1" "128" "1" "template1")
("steve" "129" "1" "steve")
("japanese" "129" "1" "japanese")
("plpgsql_test" "128" "1" "plpgsql_test")
("postgres" "128" "1" "postgres")
("pltcl_test" "128" "1" "pltcl_test"))
(setq R (pq-exec P "This is a bad query;"))
#<PGresult PGRES_FATAL_ERROR - >
(pq-pgconn P 'pq::ERROR-MESSAGE)
"ERROR: parser: parse error at or near \"this\"
"
(setq R (pq-exec P "CREATE TABLE test_table (f1 text, f2 int4);"))
#<PGresult PGRES_COMMAND_OK - CREATE>
(setq R (pq-exec P "INSERT INTO test_table VALUES ('string', 42);"))
#<PGresult PGRES_COMMAND_OK - INSERT 38570 1>
Questions, comments are welcome.
There are three new files:
src/postgresql.h, src/postgresql.c, and lisp/pg-util.el.
ChangeLog:
2000-03-06 SL Baur <steve(a)musashimaru.m17n.org>
* configure.in: add autodetection of PostgreSQL runtime libraries
src/ChangeLog:
2000-03-06 SL Baur <steve(a)musashimaru.m17n.org>
* config.h.in: Add symbols HAVE_POSTGRESQL and HAVE_POSTGRESQLV7
* inline.c: Include postgresql.h lrecord stuffs to placate buggy
GCCs.
* emacs.c (main_1): Call postgres initialization code.
* postgresql.h: New file. PostgreSQL RDBMS support.
* postgresql.c: New file.
Index: configure.in
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/configure.in,v
retrieving revision 1.138
diff -u -r1.138 configure.in
--- configure.in 2000/02/09 01:40:53 1.138
+++ configure.in 2000/03/06 03:51:59
@@ -497,6 +497,7 @@
with_sparcworks | \
with_tooltalk | \
with_ldap | \
+ with_postgresql | \
with_pop | \
with_kerberos | \
with_hesiod | \
@@ -2698,6 +2699,55 @@
fi
fi
+dnl Autodetect PostgreSQL
+dnl The default installation location (non-Linux) is /usr/local/pgsql;
+dnl a different prefix can be selected at build/install time. If PostgreSQL
+dnl is installed into a different prefix, that prefix must be specified in
+dnl in the --site-prefixes flag.
+dnl The default RPM-based Linux installation location is /usr.
+AC_CHECKING(for PostgreSQL)
+postgres_includes_found=no
+save_c_switch_site="$c_switch_site"
+dnl First check site prefixes
+if test "$with_postgresql" != "no"; then
+ AC_CHECK_HEADER(libpq-fe.h,postgres_includes_found=yes)
+fi
+dnl test for Linux-style installation in /usr
+if test "$postgres_includes_found" = "no" -a
"$with_postgresql" != "no" -a \
+ -d "/usr/include/pgsql"; then
+ c_switch_site="$c_switch_site -I/usr/include/pgsql"
+ AC_CHECK_HEADER(libpq-fe.h,postgres_includes_found=yes)
+ if test "$postgres_includes_found" != "yes"; then
+ c_switch_site="$save_c_switch_site"
+ fi
+fi
+if test "$postgres_includes_found" = "no" -a
"$with_postgresql" != "no" -a \
+ -d "/usr/local/pgsql/include"; then
+ c_switch_site="$c_switch_site -I/usr/local/pgsql/include"
+ AC_CHECK_HEADER(libpq-fe.h,postgres_includes_found=yes)
+ if test "$postgres_includes_found" != "yes"; then
+ c_switch_site="$save_c_switch_site"
+ fi
+fi
+
+dnl last check -- can we link against libpq?
+if test "$postgres_includes_found" = "yes"; then
+ AC_CHECK_LIB(pq,PQconnectdb,with_postgresql=yes,with_postgresql=no)
+fi
+if test "$with_postgresql" = "yes"; then
+ AC_CHECK_LIB(pq,PQconnectStart,with_postgresqlv7=yes,with_postgresqlv7=no)
+fi
+if test "$with_postgresql" = "yes"; then
+ AC_DEFINE(HAVE_POSTGRESQL)
+ if test "$with_postgresqlv7" = "yes"; then
+ AC_DEFINE(HAVE_POSTGRESQLV7)
+ fi
+ XE_PREPEND(-lpq, LIBS)
+ XE_ADD_OBJS(postgresql.o)
+else
+ c_switch_site=$save_c_switch_site
+fi
+
dnl ----------------------
dnl Graphics libraries
dnl ----------------------
@@ -4060,6 +4110,7 @@
test "$with_ns_ldap" = yes && echo " Compiling in support
for LDAP (Netscape SDK)."
test "$with_ldap" = yes -a "$with_umich_ldap" = no -a
"$with_ns_ldap" = no && echo " Compiling in support for LDAP
(Generic)."
+test "$with_postgresql" = yes && echo " Compiling in support for
PostgreSQL."
test "$with_ncurses" = yes && echo " Compiling in support for
ncurses."
test "$with_gpm" = yes && echo " Compiling in support for
GPM (General Purpose Mouse)."
Index: src/config.h.in
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/config.h.in,v
retrieving revision 1.53
diff -u -r1.53 config.h.in
--- config.h.in 1999/07/07 03:10:32 1.53
+++ config.h.in 2000/03/06 03:52:08
@@ -357,6 +357,11 @@
/* Do we have Netscape LDAP SDK library */
#undef HAVE_NS_LDAP
+/* Do we wish to link against the PostgreSQL RDBMS run-time library?
+ */
+#undef HAVE_POSTGRESQL
+#undef HAVE_POSTGRESQLV7
+
/* Do you have the Xauth library present? This will add some extra
functionality to gnuserv. */
#undef HAVE_XAUTH
Index: src/emacs.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/emacs.c,v
retrieving revision 1.93
diff -u -r1.93 emacs.c
--- emacs.c 1999/12/04 04:13:05 1.93
+++ emacs.c 2000/03/06 03:52:09
@@ -1062,6 +1062,10 @@
syms_of_eldap ();
#endif
+#ifdef HAVE_POSTGRESQL
+ syms_of_postgresql ();
+#endif
+
/* Now create the subtypes for the types that have them.
We do this before the vars_*() because more symbols
may get initialized here. */
@@ -1437,6 +1441,10 @@
#ifdef HAVE_LDAP
vars_of_eldap ();
+#endif
+
+#ifdef HAVE_POSTGRESQL
+ vars_of_postgresql();
#endif
/* Now initialize any specifier variables. We do this later
Index: src/inline.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/inline.c,v
retrieving revision 1.12
diff -u -r1.12 inline.c
--- inline.c 1998/05/24 05:40:44 1.12
+++ inline.c 2000/03/06 03:52:09
@@ -67,6 +67,11 @@
#include "eldap.h"
#endif
+#ifdef HAVE_POSTGRESQL
+#include <libpq-fe.h>
+#include "postgresql.h"
+#endif
+
#ifdef HAVE_TOOLBARS
#include "toolbar.h"
#endif