From: Russ Tyndall Date: Mon, 24 Aug 2009 20:57:54 +0000 (-0400) Subject: Made identifiers specified as strings be treated as the canonical name X-Git-Url: http://git.kpe.io/?p=clsql.git;a=commitdiff_plain;h=6d643c3749b77b6e6207871f0cf40f135094f457;hp=c685739c44da76247ab1c88405cfb913b0cdc55e Made identifiers specified as strings be treated as the canonical name of the column and emit them (double/ANSI) quoted. All other column names are emitted by coersion to string without ansi quoting --- diff --git a/sql/expressions.lisp b/sql/expressions.lisp index 80fffc5..9157da0 100644 --- a/sql/expressions.lisp +++ b/sql/expressions.lisp @@ -148,33 +148,18 @@ :type ',type))) (defmethod output-sql ((expr sql-ident-attribute) database) - (with-slots (qualifier name type) expr - (if (and (not qualifier) (not type)) - (etypecase name - (string - (write-string name *sql-stream*)) - (symbol - (write-string - (sql-escape (symbol-name name)) *sql-stream*))) - - ;;; KMR: The TYPE field is used by CommonSQL for type conversion -- it - ;;; should not be output in SQL statements - #+ignore - (format *sql-stream* "~@[~A.~]~A~@[ ~A~]" - (when qualifier - (sql-escape qualifier)) - (sql-escape name) - (when type - (symbol-name type))) - (format *sql-stream* "~@[~A.~]~A" - (when qualifier - (typecase qualifier - (string (format nil "~s" qualifier)) - (t (format nil "~s" (sql-escape qualifier))))) - (typecase name - (string (format nil "~s" (sql-escape name))) - (t (format nil "~s" (sql-escape name)))))) - t)) +;;; KMR: The TYPE field is used by CommonSQL for type conversion -- it +;;; should not be output in SQL statements + (let ((*print-pretty* nil)) + (with-slots (qualifier name type) expr + (format *sql-stream* "~@[~a.~]~a" + (typecase qualifier + (string (format nil "~s" qualifier)) + (symbol (safety-first (sql-escape qualifier)))) + (typecase name + (string (format nil "~s" name)) + (symbol (safety-first (sql-escape name))))) + t))) (defmethod output-sql-hash-key ((expr sql-ident-attribute) database) (with-slots (qualifier name type) diff --git a/sql/utils.lisp b/sql/utils.lisp index e6176cb..4ecf757 100644 --- a/sql/utils.lisp +++ b/sql/utils.lisp @@ -52,10 +52,9 @@ (defun sql-escape (identifier) "Change hyphens to underscores, ensure string" - (let ((unescaped (etypecase identifier - (symbol (symbol-name identifier)) - (string identifier)))) - (substitute #\_ #\- unescaped))) + (etypecase identifier + (symbol (substitute #\_ #\- (symbol-name identifier))) + (string identifier))) (defmacro without-interrupts (&body body) #+allegro `(mp:without-scheduling ,@body)