Re: Some starter guidance?
Michael Raskin <jhyiugjhvbjh234-JGs/[email protected]>
| Newsgroups | gmane.lisp.clsql.general |
|---|---|
| Message-ID | <[email protected]> |
Peter Stirling wrote: > * (clsql:query "update client_details set date_of_birth = '1981-05-07'") This seems to be a no-return-data query. So clsql:execute-command is more appropriate. > [1] I tried to make a macro for locally enabling the syntax: > > (defmacro with-sql-syntax (&body body) > `(progn > (clsql:locally-enable-sql-reader-syntax) > ,@body > (clsql:locally-disable-sql-reader-syntax))) > > but it doesn't seem to do anything (i.e. compile errors), neither where > I was intending to use it (wrapping (clsql:select inside functions), nor > as wrapped around top-level defuns. Unfortunately, reader-syntax is deeper than macros.. Macro gets already parsed body, and the parsing stage is where all the reader-syntax work has to happen. To make the reader itself evaluate a form, there is "#." reader macro. #.(clsql:locally-enable-sql-reader-syntax) (clsql:select [*] :from [some-table]) #.(clsql:restore-sql-reader-syntax-state) The good news is that you can define simple functions with shorter names for these operations without any trouble, as #. can use any function that is defined in the packages you have already loaded. You can even define the helper functions in the same file using eval-when. (eval-when (:load-toplevel :execute :compile-toplevel) (defun sql-on () (clsql:locally-enable-sql-reader-syntax)) (defun sql-off () (clsql:restore-sql-reader-syntax-state))) #.(sql-on) (clsql:select [*] :from [some-table]) #.(sql-off) If you insist, you can even define a reader-macro to enable sql syntax for one form (instead of your macro), but that seems an overcomplicated solution.