Update of /project/pg/cvsroot/pg In directory common-lisp.net:/tmp/cvs-serv4439
Modified Files: meta-queries.lisp Log Message: Add a utility function PG-DESCRIBE-TABLE.
Date: Mon Dec 19 23:16:43 2005 Author: emarsden
Index: pg/meta-queries.lisp diff -u pg/meta-queries.lisp:1.1 pg/meta-queries.lisp:1.2 --- pg/meta-queries.lisp:1.1 Fri Mar 5 19:08:08 2004 +++ pg/meta-queries.lisp Mon Dec 19 23:16:42 2005 @@ -1,7 +1,7 @@ ;;; meta-queries.lisp -- DBMS metainformation ;;; -;;; Author: Eric Marsden emarsden@laas.fr -;;; Time-stamp: <2004-03-05 emarsden> +;;; Author: Eric Marsden eric.marsden@free.fr +;;; Time-stamp: <2005-12-19 emarsden> ;; ;; ;; Metainformation such as the list of databases present in the @@ -35,6 +35,16 @@ "Return a string identifying the version and operating environment of the backend." (let ((res (pg-exec conn "SELECT version()"))) (first (pg-result res :tuple 0)))) + +(defun pg-describe-table (conn table) + (flet ((oid-to-name (oid) + (maphash (lambda (key value) + (when (eql value oid) + (return-from oid-to-name key))) + *type-to-oid*))) + (let ((res (pg-exec conn (format nil "SELECT * FROM ~S WHERE 0=1" table)))) + (loop :for (name oid) :in (pg-result res :attributes) + :collect (list name (oid-to-name oid))))))
;; EOF