X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql%2Fexpressions.lisp;h=5e75b01ccdfaaae1842dabe6dea7179cb77674e0;hb=refs%2Ftags%2Fv5.2.0;hp=7389d1c06470690d04943ffa8b077d8bf1cb08e2;hpb=29184a377bfebf51266104aadafc5fe422cbd791;p=clsql.git diff --git a/sql/expressions.lisp b/sql/expressions.lisp index 7389d1c..5e75b01 100644 --- a/sql/expressions.lisp +++ b/sql/expressions.lisp @@ -192,15 +192,25 @@ sql `(make-instance 'sql-ident-table :name ',name :table-alias ',alias))) +(defun special-char-p (s) + "Check if a string has any special characters" + (loop for char across s + thereis (find char '(#\space #\, #\. #\! #\@ #\# #\$ #\% + #\^ #\& #\* #\| #\( #\) #\- #\+)))) + (defmethod output-sql ((expr sql-ident-table) database) (with-slots (name alias) expr - (etypecase name - (string - (format *sql-stream* "~s" (sql-escape name))) - (symbol - (write-string (sql-escape name) *sql-stream*))) - (when alias - (format *sql-stream* " ~s" alias))) + (flet ((p (s) ;; the etypecase is in sql-escape too + (let ((sym? (symbolp s)) + (s (sql-escape s))) + (format *sql-stream* + (if (and sym? (not (special-char-p s))) + "~a" "~s") + s)))) + (p name) + (when alias + (princ #\space *sql-stream*) + (p alias)))) t) (defmethod output-sql-hash-key ((expr sql-ident-table) database)