From: Russ Tyndall Date: Tue, 18 Jun 2013 21:37:46 +0000 (-0400) Subject: refactored database-output-sql-as-type in a similar fashion to X-Git-Tag: v6.5.0~21 X-Git-Url: http://git.kpe.io/?p=clsql.git;a=commitdiff_plain;h=f103c1a5416d2f22820d66020e4f9c18c766d894 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 " ") --- diff --git a/ChangeLog b/ChangeLog index c0e7c5c..e4aae09 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2013-06-18 Russ Tyndall + * 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 * sql/generic-odbc.lisp, sql/generic-postgresql.lisp, sql/oodml.lisp tests/test-fddl.lisp diff --git a/db-mysql/mysql-objects.lisp b/db-mysql/mysql-objects.lisp index 015edbb..93a802f 100644 --- a/db-mysql/mysql-objects.lisp +++ b/db-mysql/mysql-objects.lisp @@ -33,16 +33,6 @@ (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)) diff --git a/sql/generic-odbc.lisp b/sql/generic-odbc.lisp index 60c5d93..d64db20 100644 --- a/sql/generic-odbc.lisp +++ b/sql/generic-odbc.lisp @@ -94,16 +94,6 @@ (: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))) diff --git a/sql/oodml.lisp b/sql/oodml.lisp index fd59241..4197ea2 100644 --- a/sql/oodml.lisp +++ b/sql/oodml.lisp @@ -545,62 +545,36 @@ (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))