X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Foodml.lisp;h=399519cfa0bef8d9544cf3a9b458e4c90513deb4;hp=e2f6b48eb2b5cc02c92bcd0fe201024f73163e27;hb=5e33459f30bccb5c83fdb5eefadaa4022ebafa42;hpb=333e8280f2f3438ffd379349bc9746c34cccc159 diff --git a/sql/oodml.lisp b/sql/oodml.lisp index e2f6b48..399519c 100644 --- a/sql/oodml.lisp +++ b/sql/oodml.lisp @@ -87,14 +87,11 @@ ;; Called by 'get-slot-values-from-view' ;; -(defvar *update-context* nil) - (defmethod update-slot-from-db ((instance standard-db-object) slotdef value) (declare (optimize (speed 3) #+cmu (extensions:inhibit-warnings 3))) (let* ((slot-reader (view-class-slot-db-reader slotdef)) (slot-name (slot-definition-name slotdef)) - (slot-type (specified-type slotdef)) - (*update-context* (cons (type-of instance) slot-name))) + (slot-type (specified-type slotdef))) (cond ((and value (null slot-reader)) (setf (slot-value instance slot-name) (read-sql-value value (delistify slot-type) @@ -309,9 +306,12 @@ (error "No view-table for class ~A" classname)) (sql-expression :table (view-table class)))) + +(defparameter *default-varchar-length* 255) + (defmethod database-get-type-specifier (type args database db-type) (declare (ignore type args database db-type)) - "VARCHAR(255)") + (format nil "VARCHAR(~D)" *default-varchar-length*)) (defmethod database-get-type-specifier ((type (eql 'integer)) args database db-type) (declare (ignore database db-type)) @@ -326,26 +326,23 @@ (defmethod database-get-type-specifier ((type (eql 'bigint)) args database db-type) (declare (ignore args database db-type)) "BIGINT") - -(defmethod database-get-type-specifier ((type (eql 'simple-base-string)) args - database db-type) - (declare (ignore database db-type)) - (if args - (format nil "VARCHAR(~A)" (car args)) - "VARCHAR(255)")) -(defmethod database-get-type-specifier ((type (eql 'simple-string)) args +(deftype varchar () + "A variable length string for the SQL varchar type." + 'string) + +(defmethod database-get-type-specifier ((type (eql 'varchar)) args database db-type) (declare (ignore database db-type)) (if args (format nil "VARCHAR(~A)" (car args)) - "VARCHAR(255)")) + (format nil "VARCHAR(~D)" *default-varchar-length*))) (defmethod database-get-type-specifier ((type (eql 'string)) args database db-type) (declare (ignore database db-type)) (if args - (format nil "VARCHAR(~A)" (car args)) - "VARCHAR(255)")) + (format nil "CHAR(~A)" (car args)) + (format nil "VARCHAR(~D)" *default-varchar-length*))) (deftype universal-time () "A positive integer as returned by GET-UNIVERSAL-TIME." @@ -402,7 +399,7 @@ (declare (ignore database db-type)) (if args (format nil "CHAR(~D)" (first args)) - "CHAR")) + "CHAR(1)")) (defmethod database-output-sql-as-type (type val database db-type) @@ -418,14 +415,12 @@ (defmethod database-output-sql-as-type ((type (eql 'symbol)) val database db-type) (declare (ignore database db-type)) - (if (keywordp val) - (symbol-name val) - (if val - (concatenate 'string - (package-name (symbol-package val)) - "::" - (symbol-name val)) - ""))) + (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)) @@ -451,15 +446,12 @@ (declare (ignore database db-type)) val) -(defmethod database-output-sql-as-type ((type (eql 'simple-string)) - val database db-type) - (declare (ignore database db-type)) - val) - -(defmethod database-output-sql-as-type ((type (eql 'simple-base-string)) +(defmethod database-output-sql-as-type ((type (eql 'char)) val database db-type) (declare (ignore database db-type)) - val) + (etypecase val + (character (write-to-string val)) + (string val))) (defmethod read-sql-value (val type database db-type) (declare (ignore type database db-type)) @@ -469,14 +461,14 @@ (declare (ignore database db-type)) val) -(defmethod read-sql-value (val (type (eql 'simple-string)) database db-type) +(defmethod read-sql-value (val (type (eql 'varchar)) database db-type) (declare (ignore database db-type)) val) -(defmethod read-sql-value (val (type (eql 'simple-base-string)) database db-type) +(defmethod read-sql-value (val (type (eql 'char)) database db-type) (declare (ignore database db-type)) - val) - + (schar val 0)) + (defmethod read-sql-value (val (type (eql 'keyword)) database db-type) (declare (ignore database db-type)) (when (< 0 (length val)) @@ -487,8 +479,7 @@ (declare (ignore database db-type)) (when (< 0 (length val)) (unless (string= val (symbol-name-default-case "NIL")) - (intern (symbol-name-default-case val) - (symbol-package *update-context*))))) + (read-from-string val)))) (defmethod read-sql-value (val (type (eql 'integer)) database db-type) (declare (ignore database db-type)) @@ -527,7 +518,7 @@ (read-from-string val))) (number val))) -(defmethod read-sql-value (val (type (eql 'univeral-time)) database db-type) +(defmethod read-sql-value (val (type (eql 'universal-time)) database db-type) (declare (ignore database db-type)) (unless (eq 'NULL val) (etypecase val