Re: lisp mail archive software

Daniel Barlow <[email protected]> Mon, 07 Jul 2003 11:13:50 +0100
Newsgroups gmane.lisp.clump
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Miles Egan <[email protected]> writes:

> Good to know.  I definitely like the approach.  Do you know offhand if
> it supports autoincrement fields the way the native client libs do?  I
> think the native libs let you execute a special select after inserting a
> new row with an autoincrement key.  The client libs supposedly retain
> this as a per-thread value.

I've been working with Eric's pg.lisp lately, and I'm quite impressed.
I developed a thin and slightly ad-hoc objectish layer around it (yes,
I know about UncommonSQL) which I'll probably package up nicely when
it settles down a bit.

I've never used Postgres through the C client libraries (always
through usql or perl DBI) but the deal at the protocol level seems to
be that the return value from an insert includes the oid of the new
row.  You can then do another select "where oid=" to get the rest of
the row.

(defmethod save-instance ((i istr-instance))
  (let* ((text (save-instance-sql i))  ; "insert into ..."
	 (r (pg:pg-exec *database-handle* text)))
    (when (= (mismatch (pg:pg-result r :status) "INSERT") 6)
      (setf (instance-id i)
	    (caar
	     (pg:pg-result
	      (pg:pg-exec *database-handle* "select id from "
			  (table-name-for-class (class-of i)) " where oid="
			  (s. (pg:pg-result r :oid)))   :tuples))))
    i))



- -dan

- -- 

   http://www.cliki.net/ - Link farm for free CL-on-Unix resources 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/CUfkHDK5ZnWQiRMRAn8UAJ9qfk2zwgz76qpDdybeJL7IIA85MQCeMAFf
MrL3ABympEqAShu+0oSd0jU=
=JmO2
-----END PGP SIGNATURE-----