+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
<listitem>
<para>
- <symbol>:db-type</symbol> - A string which will be used as the
+ <symbol>:column-</symbol> - A string which will be used as the
type specifier for this slots column definition in the database.
</para></listitem>
<listitem>
<para>
- <symbol>:nulls-ok</symbol> - If &t;, all &sql; &null; values
- retrieved from the database become nil; if &nil;, all &null;
- values retrieved are converted by
- <function>DATABASE-NULL-VALUE</function>. </para></listitem>
+ <symbol>:void-value</symbol> - The Lisp value to return if the
+ field is &null;. The default is &nil;.</para></listitem>
<listitem>
<para>
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
;;; 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+)
: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
(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)
(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+)
((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
(email
:accessor employee-email
:type (string 100)
- :nulls-ok t
:initarg :email)
(companyid
:type integer)
:foreign-key companyid
:set nil))
(managerid
- :type integer
- :nulls-ok t)
+ :type integer)
(manager
:accessor employee-manager
:db-kind :join