views:

68

answers:

2

So I'm looking to modify the CLSQL abstractions to suit my own needs. I've been using the clsql-sys package and that's suited most of my needs. However, I can't seem to find how to get a list of field names and field types from the result set. In fact, I just seem can't to find anything ANYWHERE to get types (names I can just hack into the database-query-result-set method.)

Any help would be much appreciated, especially on the types.

thanks! Jieren

+1  A: 

As the manual entry for the query function states:

query query-expression &key database result-types flatp field-names => result

...

field-names A boolean with a default value of T. When T, this function returns a second value of a list of field names. When NIL, this function only returns one value - the list of rows.

(emphasis mine). That's how you can get the field names. As for the field types... Hm. Seems, like query wants to be fed the types. The manual is silent about getting the types from the actual result set.

Dirk
well the problem with clsql:query is that it runs the query and returns everything as a big fat list of lists. I really don't want that. I want to decouple the running of the query and the generating of the return values if that makes sense. Ideally, I would do (clsql-sys:database-query-result-set), get the result set and then run something to get the field names and field types from that result set.
Jieren
Agreed. The CLSQL high-level interface is somewhat awkward, in particular if you know that your query will return a large result set, which would be best consumed a row at a time. But according to the docs, neither map-query nor do-query allow you to retreive anything but the data from the result.
Dirk
+1  A: 

I did eventually find out how to do this, but only for MySQL and Oracle, which makes the generic functions no longer valid universally. It's also very hacky (I've hardcoded the types)

I've documented this here: http://www.jierenchen.com/2009/08/solution.html

Let me know via e-mail if you have any questions about this.

Jieren