Subject: Re: only 2 simple questions : a newbie
From: (Rob Warnock)
Date: Fri, 20 Jan 2006 23:19:42 -0600
Newsgroups: comp.lang.lisp
Message-ID: <>
Eric Lavigne <> wrote:
| Another issue is database access. There is probably a bit of that built
| in to some of the above web programming libraries, but what is a good
| way to access a database such as MySQL? The emphasis is on quick and
| easy (for setup and programming), not on performance.

Well, you should definitely start by looking at
<> and especially
at <>, but since I
personally greatly prefer PostgreSQL to MySQL,
I find <> [a direct socket
interface to PostgreSQL] to be all I need, e.g.:

    > (defun pq (query)
	"PQ -- Does quick & dirty PostgreSQL query to my private
	 database, and then releases the SQL connection.
	  Success ==> (values results nil) ; list of rows+1 lists of strings
	  Fail ==>    (values nil error)   ; SQL-ERROR condition object"
	    (with-pg-connection (conn "rpw3" "rpw3")
	      ;; single query needs no transaction
	      (let* ((res (pg-exec conn query))
		     (cols (mapcar #'car (pg-result res :attributes)))
		     (rows (pg-result res :tuples)))
		(values (cons cols rows) nil)))
	  (error (cc)
	    (values nil cc))))
    > (my-pq "SELECT * FROM toy WHERE c2 = 'video'")

    (("season" "media" "title" "seq")
     ("xmas" "video" "The Grinch who Stole Christmas" 4)
     ("xmas" "video" "Home Alone" 6))
    > (my-pq "SELECT season, count(season) FROM toy GROUP BY season")

    (("c1" "count") ("easter" 2) ("fall" 1) ("spring" 1)
     ("summer" 1) ("winter" 1) ("xmas" 3))
    > (my-pq "SELECT foo FROM toy")



Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607