Updated get-database-type-specifier to handle text/longchar type
authorRuss Tyndall <russ@acceleration.net>
Mon, 10 Jun 2013 18:33:16 +0000 (14:33 -0400)
committerRuss Tyndall <russ@acceleration.net>
Mon, 10 Jun 2013 18:39:24 +0000 (14:39 -0400)
and refactored

 * added a warning above defaulting to VARCHAR (since its probably NOT
   what is expected on a bad type specifier).

 * added a case where the specified type being a string, passes that
   string directly (to better/more easily allow db-specific
   data-types).

 * added cases where longchar or text converts to text, and exported
   those symbols (as this seemed type seemed to be missing from
   fddl/oddl anyway).

 * reorganized these default methods into a single method with a case
   statement rather than many eql specified methods (about half the
   code)

 * updated the docs to use text instead of longchar since text is a
   more standard db-type (pg,my,and ms all use text)

ChangeLog
doc/ref-fddl.xml
sql/generic-postgresql.lisp
sql/oodml.lisp
sql/package.lisp

index b305fa1aa486a622f155b2a1451d29f03b83fb0d..819087e8c1f09c0639614745a0272b8c879f73eb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2013-06-10 Russ Tyndall <russ@acceleration.net>
+        * sql/oodml.lisp, sql/generic-postgresql.lisp, doc/ref-fddl.xml, 
+         sql/packages.lisp
+
+       Updated get-database-type-specifier to handle text/longchar type
+       and refactored
+
+        * added a warning above defaulting to VARCHAR (since its probably
+        NOT what is expected on a bad type specifier).
+
+        * added a case where the specified type being a string, passes
+        that string directly (to better/more easily allow db-specific
+        data-types).
+
+        * added cases where longchar or text converts to text, and
+        exported those symbols (as this seemed type seemed to be missing
+        from fddl/oddl anyway).
+
+        * reorganized these default methods into a single method with a
+        case statement rather than many eql specified methods (about half
+        the code)
+
+         * updated the docs to use text instead of longchar since text is
+         a more standard db-type (pg,my,and ms all use text)
+
 2013-03-07 Ryan Davis <ryan@acceleration.net>
        * db-postgresql-socket/postgresql-socket-api.lisp - bugfix to
        adapt to changes in md5:md5sum-sequence. CLSQL now requires a
index 5caa87d50ddb0d663c9f83fe49d52935a1dd19f1..b48bd3b8395395d9202799e5d648227335631fb0 100644 (file)
               '(([id] integer)
                 ([height] float)
                 ([name] (string 24))
-                ([comments] longchar)))
+                ([comments] text)))
 => 
 (table-exists-p [foo]) 
 => T 
index 178b3b0473901ac0909fd64381a2de2b816620db..feeaced389b125c371f40475cfd8bb0ba79e021a 100644 (file)
@@ -22,7 +22,8 @@
 
 (defmethod database-get-type-specifier (type args database
                                         (db-type (eql :postgresql)))
-  (declare (ignore type args database))
+  (warn "Could not determine a valid :postgresqlsql type specifier for ~A ~A ~A, defaulting to VARCHAR "
+        type args database)
   "VARCHAR")
 
 (defmethod database-get-type-specifier ((type (eql 'string)) args database
index ceb8f98851a1cfccc71bffda8db91ca71774c5cb..2a15e309a8c212c6a0e8a1207865274bca50605a 100644 (file)
             (error "No view-table for class ~A"  classname))
           (sql-expression :table (view-table class))))
 
-
-(defmethod database-get-type-specifier (type args database db-type)
-  (declare (ignore type args database db-type))
-  (format nil "VARCHAR(~D)" *default-string-length*))
-
-(defmethod database-get-type-specifier ((type (eql 'integer)) args database db-type)
-  (declare (ignore database db-type))
-  (if args
-      (format nil "INT(~A)" (car args))
-      "INT"))
-
 (deftype tinyint ()
   "An 8-bit integer, this width may vary by SQL implementation."
   'integer)
 
-(defmethod database-get-type-specifier ((type (eql 'tinyint)) args database db-type)
-  (declare (ignore args database db-type))
-  "INT")
-
 (deftype smallint ()
   "An integer smaller than a 32-bit integer. this width may vary by SQL implementation."
   'integer)
 
-(defmethod database-get-type-specifier ((type (eql 'smallint)) args database db-type)
-  (declare (ignore args database db-type))
-  "INT")
-
 (deftype mediumint ()
   "An integer smaller than a 32-bit integer, but may be larger than a smallint. This width may vary by SQL implementation."
   'integer)
 
-(defmethod database-get-type-specifier ((type (eql 'mediumint)) args database db-type)
-  (declare (ignore args database db-type))
-  "INT")
-
 (deftype bigint ()
   "An integer larger than a 32-bit integer, this width may vary by SQL implementation."
   'integer)
 
-(defmethod database-get-type-specifier ((type (eql 'bigint)) args database db-type)
-  (declare (ignore args database db-type))
-  "BIGINT")
-
 (deftype varchar (&optional size)
   "A variable length string for the SQL varchar type."
   (declare (ignore size))
   '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))
-      (format nil "VARCHAR(~D)" *default-string-length*)))
-
-(defmethod database-get-type-specifier ((type (eql 'string)) args database db-type)
-  (declare (ignore database db-type))
-  (if args
-      (format nil "CHAR(~A)" (car args))
-      (format nil "VARCHAR(~D)" *default-string-length*)))
-
 (deftype universal-time ()
   "A positive integer as returned by GET-UNIVERSAL-TIME."
   '(integer 1 *))
 
-(defmethod database-get-type-specifier ((type (eql 'universal-time)) args database db-type)
-  (declare (ignore args database db-type))
-  "BIGINT")
-
-(defmethod database-get-type-specifier ((type (eql 'wall-time)) args database db-type)
-  (declare (ignore args database db-type))
-  "TIMESTAMP")
-
-(defmethod database-get-type-specifier ((type (eql 'date)) args database db-type)
-  (declare (ignore args database db-type))
-  "DATE")
-
-(defmethod database-get-type-specifier ((type (eql 'duration)) args database db-type)
-  (declare (ignore database args db-type))
-  "VARCHAR")
-
-(defmethod database-get-type-specifier ((type (eql 'money)) args database db-type)
-  (declare (ignore database args db-type))
-  "INT8")
+(deftype generalized-boolean ()
+  "A type which outputs a SQL boolean value, though any lisp type can be stored in the slot."
+  t)
 
 #+ignore
 (deftype char (&optional len)
   "A lisp type for the SQL CHAR type."
   `(string ,len))
 
-(defmethod database-get-type-specifier ((type (eql 'float)) args database db-type)
-  (declare (ignore database db-type))
-  (if args
-      (format nil "FLOAT(~A)" (car args))
-      "FLOAT"))
-
-(defmethod database-get-type-specifier ((type (eql 'long-float)) args database db-type)
-  (declare (ignore database db-type))
-  (if args
-      (format nil "FLOAT(~A)" (car args))
-      "FLOAT"))
-
-(deftype generalized-boolean ()
-  "A type which outputs a SQL boolean value, though any lisp type can be stored in the slot."
-  t)
-
-(defmethod database-get-type-specifier ((type (eql 'boolean)) args database db-type)
-  (declare (ignore args database db-type))
-  "BOOL")
-
-(defmethod database-get-type-specifier ((type (eql 'generalized-boolean)) args database db-type)
+(defmethod database-get-type-specifier ((type string) args database (db-type t))
+  "Pass through the literal type as defined in the type string"
   (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(1)"))
-
+  type)
+
+(defmethod database-get-type-specifier ((type symbol) args database db-type)
+  (case type
+    (char (if args
+              (format nil "CHAR(~D)" (first args))
+              "CHAR(1)"))
+    ((varchar string)
+     (if args
+         (format nil "VARCHAR(~A)" (car args))
+         (format nil "VARCHAR(~D)" *default-string-length*)))
+    ((longchar text) "text")
+    (integer (if args
+                 (format nil "INT(~A)" (car args))
+                 "INT"))
+    ((tinyint smallint mediumint) "INT")
+    ((long-float float)
+     (if args
+         (format nil "FLOAT(~A)" (car args))
+         "FLOAT"))
+    ((bigint universal-time) "BIGINT")
+    (number
+     (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")))
+    (wall-time "TIMESTAMP")
+    (date "DATE")
+    (duration "VARCHAR")
+    (money "INT8")
+    ((boolean generalized-boolean) "BOOL")
+    (t (warn "Could not determine a valid ~A type specifier for ~A ~A ~A, defaulting to VARCHAR "
+             db-type type args database)
+     (format nil "VARCHAR(~D)" *default-string-length*))))
 
 (defmethod database-output-sql-as-type (type val database db-type)
   (declare (ignore type database db-type))
index eb6faf8cc1396bb6aa3fd5c6acb4b3195659e5fe..a8a511185ea34c1a9cd9de847b5278cdf758fc51 100644 (file)
          #:view-table
          #:bigint
          #:varchar
+         #:longchar
+         #:text
          #:generalized-boolean
          #:mediumint
          #:smallint