how to specify database in join

Michael Pheasant <[email protected]> Fri, 26 Nov 2010 12:22:45 +1000
Newsgroups gmane.lisp.clsql.general
Message-ID <[email protected]>
Hi

In SQL selects I can specify database & table name, and I can
construct the database name on the fly, eg:

(let ((db1 "someDb") (db2 "otherDb"))
 (format nil "select t1.foo, t2.bar from ~A.baz t1, ~A.buz t2 where
t1.foo = t2.foo" db1 db2))
-> "select t1.foo, t2.bar from someDb.baz t1, otherDb.buz t2 where
t1.foo = t2.foo"

*) Is there a reader syntax for this? I can get a static db, but cant
figure out how to get a run-time one:

 (clsql:sql [select [foo] [bar] :from [db1 baz] ])
 -> "SELECT FOO,BAR FROM DB1.BAZ"

I guess I could do it with a macro but was wondering if theres a built
in [] syntax I havent seen.


*) Similarly, is there a OO def-view-class syntax for :join fields
where the :join-class comes from a table in a different database?

I have a situation where I have a mysql server with many databases
(eg, db1, db2, ...) each with a table (baz) with the same definition
but different data in each db.

The databases are all accessible from the same db connection. The only
place i see to specify a database is in the connection string, but it
should also be valid to specify in the SQL, I just dont see how do to
it in the def-view-class.


PS. I tried posting to clsql-help but get bounces on bad user name
even though I recently subscribed.

Cheers,

Mike.