r9471: 5 May 2004 Kevin Rosenberg <kevin@rosenberg.net>
[clsql.git] / sql / oodml.lisp
index 3a005ad0990ac8b19d82c95fbcca018e7b55f590..e2f6b48eb2b5cc02c92bcd0fe201024f73163e27 100644 (file)
@@ -1,7 +1,7 @@
 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
 ;;;; *************************************************************************
 ;;;;
-;;;; $Id$
+;;;; $Id$
 ;;;;
 ;;;; The CLSQL Object Oriented Data Manipulation Language (OODML).
 ;;;;
   (declare (ignore database args db-type))
   "INT8")
 
-(deftype raw-string (&optional len)
-  "A string which is not trimmed when retrieved from the database"
+#+ignore
+(deftype char (&optional len)
+  "A lisp type for the SQL CHAR type."
   `(string ,len))
 
-(defmethod database-get-type-specifier ((type (eql 'raw-string)) args database db-type)
-  (declare (ignore database db-type))
-  (if args
-      (format nil "VARCHAR(~A)" (car args))
-      "VARCHAR"))
-
 (defmethod database-get-type-specifier ((type (eql 'float)) args database db-type)
   (declare (ignore database db-type))
   (if args
   (declare (ignore args database db-type))
   "BOOL")
 
+(defmethod database-get-type-specifier ((type (eql 'number)) args database db-type)
+  (declare (ignore database db-type))
+  (cond
+   ((and (consp args) (= (length args) 2))
+    (format nil "NUMBER(~D,~D)" (first args) (second args)))
+   ((and (consp args) (= (length args) 1))
+    (format nil "NUMBER(~D)" (first args)))
+   (t
+    "NUMBER")))
+
+(defmethod database-get-type-specifier ((type (eql 'char)) args database db-type)
+  (declare (ignore database db-type))
+  (if args
+      (format nil "CHAR(~D)" (first args))
+    "CHAR"))
+
+
 (defmethod database-output-sql-as-type (type val database db-type)
   (declare (ignore type database db-type))
   val)
   (declare (ignore database db-type))
   val)
 
-(defmethod read-sql-value (val (type (eql 'raw-string)) database db-type)
-  (declare (ignore database db-type))
-  val)
-
 (defmethod read-sql-value (val (type (eql 'keyword)) database db-type)
   (declare (ignore database db-type))
   (when (< 0 (length val))
   (declare (ignore database db-type))
   (equal "t" val))
 
+(defmethod read-sql-value (val (type (eql 'number)) database db-type)
+  (declare (ignore database db-type))
+  (etypecase val
+    (string
+     (unless (string-equal "NIL" val)
+       (read-from-string val)))
+    (number val)))
+
 (defmethod read-sql-value (val (type (eql 'univeral-time)) database db-type)
   (declare (ignore database db-type))
   (unless (eq 'NULL val)
@@ -1057,11 +1073,4 @@ as elements of a list."
                 (record-caches database)) results)
   results)
 
-(defun update-cached-results (targets qualifiers database)
-  ;; FIXME: this routine will need to update slots in cached objects, perhaps adding or removing objects from cached
-  ;; for now, dump cache entry and perform fresh search
-  (let ((res (apply #'find-all targets qualifiers)))
-    (setf (gethash (compute-records-cache-key targets qualifiers)
-                  (record-caches database)) res)
-    res))