From: Jonathon McKitrick
Subject: QUOTE and the reader in cl-sql
Date: 
Message-ID: <1146854225.947142.64400@e56g2000cwe.googlegroups.com>
When you call clsql:locally-enable-sql-reader-syntax, that lets you put
brackets around sql field names.  Will this work with the QUOTE
operator?  And by extension, BACKQUOTE?
Is there anything to keep in mind to make this work correctly?

From: Anon
Subject: Re: QUOTE and the reader in cl-sql
Date: 
Message-ID: <u-idnUr6FZpxMsbZRVn-qA@comcast.com>
"Jonathon McKitrick" <···········@bigfoot.com> wrote in 
····························@e56g2000cwe.googlegroups.com:

> When you call clsql:locally-enable-sql-reader-syntax, that lets you put
> brackets around sql field names.  Will this work with the QUOTE
> operator?  And by extension, BACKQUOTE?
> Is there anything to keep in mind to make this work correctly?
> 

It seems you can do this:

 (defmacro foo (table)
  `(print-query [select [*] :from ,table]))

(foo [customer])

or this

(defmacro foo (table)
  `(print-query [select [*] :from ,(sql-expression :table table)]))

 (foo customer)

but this doesn't seem possible

(defmacro foo (table)
  `(print-query [select [*] :from [,table]]))

(foo customer)

The reason seems to be that whatever is in [...]
gets expanded into a (sql-expression) before the macro expansion.
From: hayeah
Subject: Re: QUOTE and the reader in cl-sql
Date: 
Message-ID: <1146942191.650029.195570@v46g2000cwv.googlegroups.com>
Here's what I did when I needed the same thing.
Not sure at all if it's a good idea. Comments, anyone?

(defun sql-reader-open (stream char)
  (declare (ignore char))
  (let ((sqllist (read-delimited-list #\] stream t)))
    (print (list 'reader=> sqllist))
    (unless *read-suppress*
      (handler-case
	  (cond ((string= (write-to-string (car sqllist)) "||")
		 (apply (sql-operator 'concat-op) (cdr sqllist)))
		((and (= (length sqllist) 1) (eql (car sqllist) '*))
		 (apply #'generate-sql-reference sqllist))
		((sql-operator (car sqllist))
		 (apply (sql-operator (car sqllist)) (cdr sqllist)))
		(t (apply #'generate-sql-reference sqllist)))
	(sql-user-error (c)
	  (error 'sql-user-error
		 :message (format nil "Error ~A occured while attempting to parse
'~A' at file position ~A"
				  (sql-user-error-message c) sqllist (file-position stream))))))))