X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Fexpressions.lisp;fp=sql%2Fexpressions.lisp;h=ef58af7d06ed62d4a4b2d2447eafb3053b389ca1;hp=90b2620c0a376e4c98b8b88079daea49d86e5f83;hb=7c5e205e6323991c72e19e910c1a68bb3acc0fc5;hpb=dc107d34212597ed1272cfa21138d384e71b00d2 diff --git a/sql/expressions.lisp b/sql/expressions.lisp index 90b2620..ef58af7 100644 --- a/sql/expressions.lisp +++ b/sql/expressions.lisp @@ -137,22 +137,29 @@ (write-string (database-output-sql expr database) *sql-stream*) (values)) -(defvar *output-hash* (make-hash-table :test #'equal) + +(defvar *output-hash* + #+sbcl + (make-hash-table :test #'equal :synchronized T :weakness :key-and-value) + #-sbcl + (make-hash-table :test #'equal ) "For caching generated SQL strings.") (defmethod output-sql :around ((sql t) database) - (let* ((hash-key (output-sql-hash-key sql database)) - (hash-value (when hash-key (gethash hash-key *output-hash*)))) - (cond ((and hash-key hash-value) - (write-string hash-value *sql-stream*)) - (hash-key - (let ((*sql-stream* (make-string-output-stream))) - (call-next-method) - (setf hash-value (get-output-stream-string *sql-stream*)) - (setf (gethash hash-key *output-hash*) hash-value)) - (write-string hash-value *sql-stream*)) - (t - (call-next-method))))) + (if (null *output-hash*) + (call-next-method) + (let* ((hash-key (output-sql-hash-key sql database)) + (hash-value (when hash-key (gethash hash-key *output-hash*)))) + (cond ((and hash-key hash-value) + (write-string hash-value *sql-stream*)) + (hash-key + (let ((*sql-stream* (make-string-output-stream))) + (call-next-method) + (setf hash-value (get-output-stream-string *sql-stream*)) + (setf (gethash hash-key *output-hash*) hash-value)) + (write-string hash-value *sql-stream*)) + (t + (call-next-method)))))) (defmethod output-sql-hash-key (expr database) (declare (ignore expr database)) @@ -254,7 +261,9 @@ (with-slots (qualifier name type) expr (list (and database (database-underlying-type database)) - 'sql-ident-attribute qualifier name type))) + 'sql-ident-attribute + (unescaped-database-identifier qualifier) + (unescaped-database-identifier name) type))) ;; For SQL Identifiers for tables @@ -297,7 +306,9 @@ (with-slots (name alias) expr (list (and database (database-underlying-type database)) - 'sql-ident-table name alias))) + 'sql-ident-table + (unescaped-database-identifier name) + (unescaped-database-identifier alias)))) (defclass sql-relational-exp (%sql-expression) ((operator