head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.1
	netbsd-11-0-RC3:1.1.1.1
	netbsd-11-0-RC2:1.1.1.1
	netbsd-11-0-RC1:1.1.1.1
	netbsd-11:1.1.1.1.0.30
	netbsd-11-base:1.1.1.1
	netbsd-10-1-RELEASE:1.1.1.1
	xedit-1-2-4:1.1.1.1
	netbsd-8-3-RELEASE:1.1.1.1
	netbsd-9-4-RELEASE:1.1.1.1
	netbsd-10-0-RELEASE:1.1.1.1
	netbsd-10-0-RC6:1.1.1.1
	netbsd-10-0-RC5:1.1.1.1
	netbsd-10-0-RC4:1.1.1.1
	netbsd-10-0-RC3:1.1.1.1
	netbsd-10-0-RC2:1.1.1.1
	netbsd-10-0-RC1:1.1.1.1
	netbsd-10:1.1.1.1.0.28
	netbsd-10-base:1.1.1.1
	netbsd-9-3-RELEASE:1.1.1.1
	xedit-1-2-3:1.1.1.1
	netbsd-9-2-RELEASE:1.1.1.1
	netbsd-9-1-RELEASE:1.1.1.1
	netbsd-8-2-RELEASE:1.1.1.1
	netbsd-9-0-RELEASE:1.1.1.1
	netbsd-9-0-RC2:1.1.1.1
	netbsd-9-0-RC1:1.1.1.1
	netbsd-9:1.1.1.1.0.26
	netbsd-9-base:1.1.1.1
	netbsd-8-1-RELEASE:1.1.1.1
	netbsd-8-1-RC1:1.1.1.1
	netbsd-7-2-RELEASE:1.1.1.1
	netbsd-8-0-RELEASE:1.1.1.1
	netbsd-8-0-RC2:1.1.1.1
	netbsd-8-0-RC1:1.1.1.1
	netbsd-7-1-2-RELEASE:1.1.1.1
	netbsd-7-1-1-RELEASE:1.1.1.1
	netbsd-8:1.1.1.1.0.24
	netbsd-8-base:1.1.1.1
	netbsd-7-1:1.1.1.1.0.22
	netbsd-7-1-RELEASE:1.1.1.1
	netbsd-7-1-RC2:1.1.1.1
	netbsd-7-1-RC1:1.1.1.1
	netbsd-7-0-2-RELEASE:1.1.1.1
	netbsd-7-0-1-RELEASE:1.1.1.1
	netbsd-7-0:1.1.1.1.0.20
	netbsd-7-0-RELEASE:1.1.1.1
	netbsd-7-0-RC3:1.1.1.1
	netbsd-7-0-RC2:1.1.1.1
	xedit-1-2-2:1.1.1.1
	netbsd-7-0-RC1:1.1.1.1
	netbsd-5-2-3-RELEASE:1.1.1.1
	netbsd-5-1-5-RELEASE:1.1.1.1
	netbsd-6-0-6-RELEASE:1.1.1.1
	netbsd-6-1-5-RELEASE:1.1.1.1
	netbsd-7:1.1.1.1.0.18
	netbsd-7-base:1.1.1.1
	netbsd-6-1-4-RELEASE:1.1.1.1
	netbsd-6-0-5-RELEASE:1.1.1.1
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.1
	riastradh-drm2:1.1.1.1.0.16
	riastradh-drm2-base:1.1.1.1
	netbsd-6-1-3-RELEASE:1.1.1.1
	netbsd-6-0-4-RELEASE:1.1.1.1
	netbsd-5-2-2-RELEASE:1.1.1.1
	netbsd-5-1-4-RELEASE:1.1.1.1
	netbsd-6-1-2-RELEASE:1.1.1.1
	netbsd-6-0-3-RELEASE:1.1.1.1
	netbsd-5-2-1-RELEASE:1.1.1.1
	netbsd-5-1-3-RELEASE:1.1.1.1
	netbsd-6-1-1-RELEASE:1.1.1.1
	xedit-1-2-1:1.1.1.1
	netbsd-6-1:1.1.1.1.0.14
	netbsd-6-0-2-RELEASE:1.1.1.1
	netbsd-6-1-RELEASE:1.1.1.1
	netbsd-6-1-RC4:1.1.1.1
	netbsd-6-1-RC3:1.1.1.1
	netbsd-6-1-RC2:1.1.1.1
	netbsd-6-1-RC1:1.1.1.1
	netbsd-5-2:1.1.1.1.0.12
	netbsd-6-0-1-RELEASE:1.1.1.1
	netbsd-5-2-RELEASE:1.1.1.1
	netbsd-5-2-RC1:1.1.1.1
	netbsd-6-0:1.1.1.1.0.10
	netbsd-6-0-RELEASE:1.1.1.1
	netbsd-6-0-RC2:1.1.1.1
	netbsd-6-0-RC1:1.1.1.1
	netbsd-6:1.1.1.1.0.8
	netbsd-6-base:1.1.1.1
	netbsd-5-1-2-RELEASE:1.1.1.1
	netbsd-5-1-1-RELEASE:1.1.1.1
	xedit-1-2-0:1.1.1.1
	netbsd-5-1:1.1.1.1.0.6
	netbsd-5-1-RELEASE:1.1.1.1
	netbsd-5-1-RC4:1.1.1.1
	netbsd-5-1-RC3:1.1.1.1
	netbsd-5-1-RC2:1.1.1.1
	netbsd-5-1-RC1:1.1.1.1
	netbsd-5-0-2-RELEASE:1.1.1.1
	netbsd-5-0-1-RELEASE:1.1.1.1
	netbsd-5-0:1.1.1.1.0.4
	netbsd-5-0-RELEASE:1.1.1.1
	netbsd-5-0-RC4:1.1.1.1
	netbsd-5-0-RC3:1.1.1.1
	xedit-1-1-2:1.1.1.1
	netbsd-5-0-RC2:1.1.1.1
	netbsd-5-0-RC1:1.1.1.1
	netbsd-5:1.1.1.1.0.2
	netbsd-5-base:1.1.1.1
	xedit-1-0-2:1.1.1.1
	xorg:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2008.07.30.04.16.30;	author mrg;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2008.07.30.04.16.30;	author mrg;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Initial revision
@
text
@;; Postgresql C library interface, example program 2, using the xedit
;; lisp interface

;;  Test of the asynchronous notification interface
;;
;; Start this program, then from psql in another window do
;;   NOTIFY TBL2;
;;
;; Or, if you want to get fancy, try this:
;; Populate a database with the following:
;;
;;   CREATE TABLE TBL1 (i int4);
;;
;;   CREATE TABLE TBL2 (i int4);
;;
;;   CREATE RULE r1 AS ON INSERT TO TBL1 DO
;;     (INSERT INTO TBL2 values (new.i); NOTIFY TBL2);
;;
;; and do
;;
;;   INSERT INTO TBL1 values (10);
(require "psql")

(defun exit-nicely (conn)
    (pq-finish conn)
    (quit 1)
)

;; begin, by setting the parameters for a backend connection if the
;; parameters are null, then the system will try to use reasonable
;; defaults by looking up environment variables or, failing that,
;; using hardwired constants
(setq pghost nil)		; host name of the backend server
(setq pgport nil)		; port of the backend server
(setq pgoptions nil)		; special options to start up the backend server
(setq pgtty nil)		; debugging tty for the backend server
(setq pgdbname "test")		; change this to the name of your test database
				;; XXX Note: getenv not yet implemented in the
				 ; lisp interpreter

;; make a connection to the database
(setq conn (pq-setdb pghost pgport pgoptions pgtty pgdbname))

;; check to see that the backend connection was successfully made
(when (= (pq-status conn) pg-connection-bad)
    (format t "Connection to database '~A' failed.~%" pgdbname)
    (format t "~A" (pq-error-message conn))
    (exit-nicely conn))

(setq res (pq-exec conn "LISTEN TBL2"))
(when (= (pq-status conn) pg-connection-bad)
    (format t "LISTEN command failed~%")
    (format t "~A" (pq-error-message conn))
    (exit-nicely conn))

;; Should PQclear PGresult whenever it is no longer needed to avoid memory leaks
(pq-clear res)

(loop
    ;; wait a little bit between checks; waiting with select()
    ;; would be more efficient.
	;; XXX Note: sleep not yet implemented in the lisp interpreter

    ;; collect any asynchronous backend messages
    (pq-consume-input conn)

    ;; check for asynchronous notify messages
    (when (setq notifies (pq-notifies conn))
	(format t "ASYNC NOTIFY of '~A' from backend pid '~D' received~%"
	 (pg-notify-relname notifies) (pg-notify-be-pid notifies))
    )
)

(pq-finish conn)
@


1.1.1.1
log
@initial import of xedit-1.0.2
@
text
@@
