Try to respect the casing of symbols where it seems intentional (ie:
[clsql.git] / sql / expressions.lisp
index 7a8c11a6b226d1202ad6158830a4f0a8fd701676..983d4a526bb5667e1eb6fa17f2c6090c15f93823 100644 (file)
                             #\^ #\& #\* #\| #\( #\) #\- #\+ #\< #\>
                             #\{ #\}))))
 
+(defun special-cased-symbol-p (sym)
+  "Should the symbols case be preserved, or should we convert to default casing"
+  (let ((name (symbol-name sym)))
+    (case (readtable-case *readtable*)
+      (:upcase (not (string= (string-upcase name) name)))
+      (:downcase (not (string= (string-downcase name) name)))
+      (t t))))
+
 (defun %make-database-identifier (inp &optional database)
   "We want to quote an identifier if it came to us as a string or if it has special characters
    in it."
       (symbol
        (let ((s (sql-escape inp)))
          (if (and (not (eql '* inp)) (special-char-p s))
-             (%escape-identifier (convert-to-db-default-case s database) inp)
-             (make-instance '%database-identifier :escaped s :unescaped inp)))))))
+             (%escape-identifier
+              (if (special-cased-symbol-p inp)
+                  s
+                  (convert-to-db-default-case s database)) inp)
+             (make-instance '%database-identifier :escaped s :unescaped inp))
+         )))))
 
 (defun combine-database-identifiers (ids &optional (database clsql-sys:*default-database*)
                                      &aux res all-sym? pkg)