Eric Lavigne <lavigne.eric@gmail.com> 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
<http://www.cliki.net/database> and especially
at <http://www.cliki.net/CLSQL>, but since I
personally greatly prefer PostgreSQL to MySQL,
I find <http://www.cliki.net/Pg> [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"
(handler-case
(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))
NIL
> (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))
NIL
> (my-pq "SELECT foo FROM toy")
NIL
#<POSTGRESQL::BACKEND-ERROR {58932CC5}>
>
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607