From: Russ Tyndall Date: Mon, 10 Jun 2013 18:33:16 +0000 (-0400) Subject: Updated get-database-type-specifier to handle text/longchar type X-Git-Tag: v6.5.0~23^2~1 X-Git-Url: http://git.kpe.io/?p=clsql.git;a=commitdiff_plain;h=4972b90bab0ee31300e49c0c06b472de747cbbb6 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) --- diff --git a/ChangeLog b/ChangeLog index b305fa1..819087e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2013-06-10 Russ Tyndall + * 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 * db-postgresql-socket/postgresql-socket-api.lisp - bugfix to adapt to changes in md5:md5sum-sequence. CLSQL now requires a diff --git a/doc/ref-fddl.xml b/doc/ref-fddl.xml index 5caa87d..b48bd3b 100644 --- a/doc/ref-fddl.xml +++ b/doc/ref-fddl.xml @@ -105,7 +105,7 @@ '(([id] integer) ([height] float) ([name] (string 24)) - ([comments] longchar))) + ([comments] text))) => (table-exists-p [foo]) => T diff --git a/sql/generic-postgresql.lisp b/sql/generic-postgresql.lisp index 178b3b0..feeaced 100644 --- a/sql/generic-postgresql.lisp +++ b/sql/generic-postgresql.lisp @@ -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 diff --git a/sql/oodml.lisp b/sql/oodml.lisp index ceb8f98..2a15e30 100644 --- a/sql/oodml.lisp +++ b/sql/oodml.lisp @@ -465,136 +465,80 @@ (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)) diff --git a/sql/package.lisp b/sql/package.lisp index eb6faf8..a8a5111 100644 --- a/sql/package.lisp +++ b/sql/package.lisp @@ -373,6 +373,8 @@ #:view-table #:bigint #:varchar + #:longchar + #:text #:generalized-boolean #:mediumint #:smallint