refactored database-output-sql-as-type in a similar fashion to
authorRuss Tyndall <russ@acceleration.net>
Tue, 18 Jun 2013 21:37:46 +0000 (17:37 -0400)
committerRuss Tyndall <russ@acceleration.net>
Tue, 18 Jun 2013 21:37:46 +0000 (17:37 -0400)
the previous refactor of database-get-type-specifier (fewer
methods using case instead of eql specifiers)

 * removed very strange definition of outputing floats as strings for
   something sane (it was previously doing silly work like setting the
   default read float type (which AFAICT doesnt affect printing))

 * half of the cases nil returned "" other times it returned nil,
   now if we get a null value we return nil always

 * removed odd-logic (seemingly untouched since the initial import),
   that removed null characters from printed lists.  If we have #\null
   in a printed list, we had probably better figure out what went wrong
   there rather than destructively modifying the list output on the way
   to the DB ;; removed (substitute-char-string escaped #\Null " ")

ChangeLog
db-mysql/mysql-objects.lisp
sql/generic-odbc.lisp
sql/oodml.lisp

index c0e7c5c2ab56bc64c2616ab78c3ea5b64287b030..e4aae097c8a3acf7f397696ce0b295808b7892ea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2013-06-18 Russ Tyndall <russ@acceleration.net>
+        * sql/oodml.lisp, sql/mysql-objects.lisp
+        refactored database-output-sql-as-type in a similar fashion to
+        the previous refactor of database-get-type-specifier (fewer
+        methods using case instead of eql specifiers)
+
+        * removed very strange definition of outputing floats as strings
+          for something sane (it was previously doing silly work like
+          setting the default read float type (which AFAICT doesnt affect
+          printing))
+
+        * half of the cases nil returned "" other times it returned nil,
+          now if we get a null value we return nil always
+
+        * removed odd-logic (seemingly untouched since the initial import),
+          that removed null characters from printed lists.  If we have #\null
+          in a printed list, we had probably better figure out what went wrong
+          there rather than destructively modifying the list output on the way
+          to the DB ;; removed (substitute-char-string escaped #\Null " ")
+
 2013-06-18 Russ Tyndall <russ@acceleration.net>
         * sql/generic-odbc.lisp, sql/generic-postgresql.lisp, sql/oodml.lisp
          tests/test-fddl.lisp
index 015edbb6501791e3a45f82889f10ffc6f7ebfe9c..93a802f762ca3be7cefaa5229e0e894097373610 100644 (file)
   (declare (ignore args database))
   "TINYINT")
 
-(defmethod database-output-sql-as-type ((type (eql 'boolean)) val database
-                                        (db-type (eql :mysql)))
-  (declare (ignore database))
-  (if val 1 0))
-
-(defmethod database-output-sql-as-type ((type (eql 'generalized-boolean)) val database
-                                        (db-type (eql :mysql)))
-  (declare (ignore database))
-  (if val 1 0))
-
 (defmethod read-sql-value (val (type (eql 'boolean)) database
                            (db-type (eql :mysql)))
   (declare (ignore database))
index 60c5d930463c116bef189e8bb732ede6a3b8f588..d64db208b1b3a62b190b4773624ab67cd8adb12b 100644 (file)
     (:mssql "1")
     (t "'Y'")))
 
-(defmethod database-output-sql-as-type ((type (eql 'boolean)) val database
-                                        (db-type (eql :mssql)))
-  (declare (ignore database))
-  (if val 1 0))
-
-(defmethod database-output-sql-as-type ((type (eql 'generalized-boolean)) val database
-                                        (db-type (eql :mssql)))
-  (declare (ignore database))
-  (if val 1 0))
-
 ;;; Database backend capabilities
 
 (defmethod db-type-use-fully-qualified-column-on-drop-index? ((db-type (eql :mssql)))
index fd592413fe4a6baaf4712d9c73f93a0ee2895043..4197ea23b7efaa70cafbc9317a9c302b41c3d715 100644 (file)
   (declare (ignore type database db-type))
   val)
 
-(defmethod database-output-sql-as-type ((type (eql 'list)) val database db-type)
-  (declare (ignore database db-type))
-  (progv '(*print-circle* *print-array*) '(t t)
-    (let ((escaped (prin1-to-string val)))
-      (substitute-char-string
-       escaped #\Null " "))))
-
-(defmethod database-output-sql-as-type ((type (eql 'symbol)) val database db-type)
-  (declare (ignore database db-type))
-  (if val
-      (concatenate 'string
-                   (package-name (symbol-package val))
-                   "::"
-                   (symbol-name val))
-      ""))
-
-(defmethod database-output-sql-as-type ((type (eql 'keyword)) val database db-type)
-  (declare (ignore database db-type))
-  (if val
-      (symbol-name val)
-      ""))
-
-(defmethod database-output-sql-as-type ((type (eql 'vector)) val database db-type)
-  (declare (ignore database db-type))
-  (progv '(*print-circle* *print-array*) '(t t)
-    (prin1-to-string val)))
-
-(defmethod database-output-sql-as-type ((type (eql 'array)) val database db-type)
-  (declare (ignore database db-type))
-  (progv '(*print-circle* *print-array*) '(t t)
-    (prin1-to-string val)))
-
-(defmethod database-output-sql-as-type ((type (eql 'boolean)) val database db-type)
-  (declare (ignore database db-type))
-  (if val "t" "f"))
-
-(defmethod database-output-sql-as-type ((type (eql 'generalized-boolean)) val database db-type)
-  (declare (ignore database db-type))
-  (if val "t" "f"))
-
-(defmethod database-output-sql-as-type ((type (eql 'string)) val database db-type)
-  (declare (ignore database db-type))
-  val)
-
-(defmethod database-output-sql-as-type ((type (eql 'char)) val database db-type)
-  (declare (ignore database db-type))
-  (etypecase val
-    (character (write-to-string val))
-    (string val)))
-
-(defmethod database-output-sql-as-type ((type (eql 'float)) val database db-type)
-  (declare (ignore database db-type))
-  (if (eq (type-of val) 'null)
-      nil
-      (let ((*read-default-float-format* (type-of val)))
-       (format nil "~F" val))))
+(defmethod database-output-sql-as-type ((type symbol) val database db-type)
+  (declare (ignore database))
+  (case type ;; booleans handle null differently
+    ((boolean generalized-boolean)
+     (case db-type
+       ;; done here so it can be done once
+       ((:mssql :mysql) (if val 1 0))
+       (otherwise (if val "t" "f"))))
+    (otherwise
+     ;; in all other cases if we have nil give everyone else a shot at it,
+     ;; which by default returns nil
+     (if (null val)
+         (call-next-method)
+         (case type
+           (symbol
+            (format nil "~A::~A"
+                    (package-name (symbol-package val))
+                    (symbol-name val)))
+           (keyword (symbol-name val))
+           (string val)
+           (char (etypecase val
+                   (character (write-to-string val))
+                   (string val)))
+           (float (format nil "~F" val))
+           ((list vector array)
+            (let* ((*print-circle* t)
+                   (*print-array* t)
+                   (value (prin1-to-string val)))
+              value))
+           (otherwise (call-next-method)))))))
 
 (defmethod read-sql-value (val type database db-type)
   (declare (ignore database db-type))