From afe872863374de73b2f2ef767e742a40d7465e4a Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Sat, 1 May 2004 22:00:53 +0000 Subject: [PATCH] r9193: remove old :nulls-ok attribute. Add :void-value attribute. --- ChangeLog | 7 +++++++ doc/csql.xml | 8 +++----- sql/generics.lisp | 5 ----- sql/metaclasses.lisp | 17 ++++++++--------- sql/objects.lisp | 22 ++-------------------- tests/test-init.lisp | 12 ++++-------- 6 files changed, 24 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index dbf9824..d20f186 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +1 May 2004 Kevin Rosenberg (kevin@rosenberg.net) + * Version 2.10.6-pre1 + * sql/metaclasses.lisp: Add void-value slot + * doc/csql.xml: Update def-view-class documentation + * test/test-init.lisp: Change old :db-type to :db-kind. + Remove old :nulls-ok attributes. + 1 May 2004 Kevin Rosenberg (kevin@rosenberg.net) * Version 2.10.5: SQLite backend now passes all result-types tests * clsql-sqlite.asd: Depend on clsql-uffi system diff --git a/doc/csql.xml b/doc/csql.xml index 47491ff..09ac4db 100644 --- a/doc/csql.xml +++ b/doc/csql.xml @@ -247,16 +247,14 @@ mapped into a database). They would be defined as follows: - :db-type - A string which will be used as the + :column- - A string which will be used as the type specifier for this slots column definition in the database. - :nulls-ok - If &t;, all &sql; &null; values - retrieved from the database become nil; if &nil;, all &null; - values retrieved are converted by - DATABASE-NULL-VALUE. + :void-value - The Lisp value to return if the + field is &null;. The default is &nil;. diff --git a/sql/generics.lisp b/sql/generics.lisp index d1b642a..a7c8be1 100644 --- a/sql/generics.lisp +++ b/sql/generics.lisp @@ -84,11 +84,6 @@ your application needs to take action when a View Class instance has been updated by (select ... :refresh t) then add an INSTANCE-REFRESH method specializing on your subclass of STANDARD-DB-OBJECT.")) -(defgeneric database-null-value (type) - (:documentation - "Return an expression of type TYPE which SQL NULL values will be -converted into.")) - (defgeneric update-slot-with-null (instance slotname slotdef) (:documentation "Called to update a slot when its column has a NULL value. If nulls are allowed for the column, the slot's value will be diff --git a/sql/metaclasses.lisp b/sql/metaclasses.lisp index b7b2e50..d6d92b8 100644 --- a/sql/metaclasses.lisp +++ b/sql/metaclasses.lisp @@ -56,8 +56,8 @@ ;;; Lispworks 4.2 and before requires special processing of extra slot and class options -(defvar +extra-slot-options+ '(:column :db-kind :db-reader :nulls-ok :db-constraints - :db-writer :db-type :db-info)) +(defvar +extra-slot-options+ '(:column :db-kind :db-reader :void-value :db-constraints + :db-writer :db-info)) (defvar +extra-class-options+ '(:base-table)) (dolist (slot-option +extra-slot-options+) @@ -287,13 +287,12 @@ column definition in the database.") :initform nil :documentation "A single constraint or list of constraints for this column") - (nulls-ok - :accessor view-class-slot-nulls-ok - :initarg :nulls-ok + (void-value + :accessor view-class-slot-void-value + :initarg :void-value :initform nil :documentation - "If t, all sql NULL values retrieved from the database become nil; if nil, -all NULL values retrieved are converted by DATABASE-NULL-VALUE") + "Value to store is the SQL value is NULL. Default is NIL.") (db-info :accessor view-class-slot-db-info :initarg :db-info @@ -443,8 +442,8 @@ which does type checking before storing a value in a slot." (when (slot-boundp sd 'db-type) (view-class-slot-db-type sd))) - (setf (slot-value slotd 'nulls-ok) - (view-class-slot-nulls-ok sd)) + (setf (slot-value slotd 'void-value) + (view-class-slot-void-value sd)) ;; :db-kind slot value defaults to :base (store slot value in ;; database) diff --git a/sql/objects.lisp b/sql/objects.lisp index 0ea28e9..f2d82e6 100644 --- a/sql/objects.lisp +++ b/sql/objects.lisp @@ -425,30 +425,12 @@ superclass of the newly-defined View Class." (get-slot-values-from-view instance (list slot-def) (car res))))) -(defmethod database-null-value ((type t)) - (cond - ((subtypep type 'string) nil) - ((subtypep type 'integer) nil) - ((subtypep type 'list) nil) - ((subtypep type 'boolean) nil) - ((eql type t) nil) - ((subtypep type 'symbol) nil) - ((subtypep type 'keyword) nil) - ((subtypep type 'wall-time) nil) - ((subtypep type 'duration) nil) - ((subtypep type 'money) nil) - (t - (error "Unable to handle null for type ~A" type)))) - (defmethod update-slot-with-null ((object standard-db-object) slotname slotdef) (let ((st (slot-type slotdef)) - (allowed (slot-value slotdef 'nulls-ok))) - (if allowed - (setf (slot-value object slotname) nil) - (setf (slot-value object slotname) - (database-null-value st))))) + (void-value (slot-value slotdef 'void-value))) + (setf (slot-value object slotname) void-value))) (defvar +no-slot-value+ '+no-slot-value+) diff --git a/tests/test-init.lisp b/tests/test-init.lisp index feee1d5..d8eec64 100644 --- a/tests/test-init.lisp +++ b/tests/test-init.lisp @@ -34,24 +34,22 @@ ((extraterrestrial :initform nil :initarg :extraterrestrial))) (def-view-class person (thing) - ((height :db-kind :base :accessor height :type float :nulls-ok t + ((height :db-kind :base :accessor height :type float :initarg :height) - (married :db-kind :base :accessor married :type boolean :nulls-ok t + (married :db-kind :base :accessor married :type boolean :initarg :married) - (birthday :nulls-ok t :type clsql-base:wall-time :initarg :birthday) + (birthday :type clsql-base:wall-time :initarg :birthday) (hobby :db-kind :virtual :initarg :hobby :initform nil))) (def-view-class employee (person) ((emplid :db-kind :key :db-constraints :not-null - :nulls-ok nil :type integer :initarg :emplid) (groupid :db-kind :key :db-constraints :not-null - :nulls-ok nil :type integer :initarg :groupid) (first-name @@ -65,7 +63,6 @@ (email :accessor employee-email :type (string 100) - :nulls-ok t :initarg :email) (companyid :type integer) @@ -77,8 +74,7 @@ :foreign-key companyid :set nil)) (managerid - :type integer - :nulls-ok t) + :type integer) (manager :accessor employee-manager :db-kind :join -- 2.34.1