r9521: rrf updates
[umlisp.git] / parse-common.lisp
index c6032363b39749f0f758613c8c6549731fc55359..e2cb6ea26955d6abaaf2dcc636517e2c0427dfc5 100644 (file)
@@ -206,7 +206,10 @@ Currently, these are the LEX and NET files."
 (defun find-ucols-for-ufile (ufile)
   "Returns list of umls-cols for a file structure"
   (loop for colname in (fields ufile)
-       collect (find-ucol colname (fil ufile))))
+      collect (find-ucol colname 
+                        (if (subdir ufile)
+                            (concatenate 'string (subdir ufile) "/" (fil ufile))
+                          (fil ufile)))))
 
 (defun umls-field-string-to-list (fmt)
   "Converts a comma delimited list of fields into a list of field names. Will
@@ -250,32 +253,73 @@ append a unique number (starting at 2) onto a column name that is repeated in th
 "Return datatype for column name"  
   (second (find colname +col-datatypes+ :key #'car :test #'string-equal)))
 
+(defun canonicalize-column-type (type)
+  (cond
+   ((string-equal type "SMALLINT")
+    (case *umls-sql-type*
+      (:mysql "SMALLINT")
+      ((:postgresql :postgresql-socket) "INT2")
+      (:oracle "NUMBER(5,0)")
+      (t "INTEGER")))
+   ((string-equal type "INTEGER")
+    (case *umls-sql-type*
+      (:mysql "INTEGER")
+      ((:postgresql :postgresql-socket) "INT4")
+      (:oracle "NUMBER(9,0)")
+      (t "INTEGER")))
+   ((string-equal type "BIGINT")
+    (case *umls-sql-type*
+      (:mysql "BIGINT")
+      ((:postgresql :postgresql-socket) "INT8")
+      (:oracle "NUMBER(38,0)")
+      (t "INTEGER")))
+   ((string-equal type "TEXT")
+    (case *umls-sql-type*
+      (:mysql "TEXT")
+      ((:postgresql :postgresql-socket) "TEXT")
+      (:oracle "VARCHAR2(3000)")
+      (t "VARCHAR(3000)")))
+   ((string-equal type "VARCHAR")
+    (case *umls-sql-type*
+      (:mysql "VARCHAR")
+      ((:postgresql :postgresql-socket) "VARCHAR")
+      (:oracle "VARCHAR2")
+      (t "VARCHAR")))
+   ((string-equal type "NUMERIC")
+    (case *umls-sql-type*
+      (:mysql "NUMERIC")
+      ((:postgresql :postgresql-socket) "NUMERIC")
+      (:oracle "NUMBER")
+      (t "NUMERIC")))
+   (t
+    type)))
+      
 (defun ensure-ucol-datatype (col datatype)
-"Add data type information to column"
+  "Add data type information to column"
   (setf (datatype col) datatype)
   (case datatype
-    (sql-u (setf (sqltype col) "INTEGER"
+    (sql-u (setf (sqltype col) (canonicalize-column-type "INTEGER")
                 (parse-fun col) #'parse-ui
                 (quote-str col) ""))
-    (sql-s (setf (sqltype col) "SMALLINT" 
+    (sql-s (setf (sqltype col) (canonicalize-column-type "SMALLINT")
                 (parse-fun col) #'parse-integer
                 (quote-str col) ""))
-    (sql-l (setf (sqltype col) "BIGINT" 
+    (sql-l (setf (sqltype col)  (canonicalize-column-type "BIGINT")
                 (parse-fun col) #'parse-integer
                 (quote-str col) ""))
-    (sql-i (setf (sqltype col) "INTEGER" 
+    (sql-i (setf (sqltype col)  (canonicalize-column-type "INTEGER")
                 (parse-fun col) #'parse-integer
                 (quote-str col) ""))
-    (sql-f (setf (sqltype col) "NUMERIC" 
+    (sql-f (setf (sqltype col)  (canonicalize-column-type "NUMERIC")
                 (parse-fun col) #'read-from-string
                 (quote-str col) ""))
-    (t                      ; Default column type, optimized text storage
+    (t                                 ; Default column type, optimized text storage
      (setf (parse-fun col) #'add-sql-quotes 
           (quote-str col) "'")
      (when (and (cmax col) (av col))
        (if (> (cmax col) 255)
-          (setf (sqltype col) "TEXT")
-          (setf (sqltype col) "VARCHAR"))))))
+          (setf (sqltype col) (canonicalize-column-type "TEXT"))
+        (setf (sqltype col) (canonicalize-column-type "VARCHAR")))))))
 
 (defun escape-column-name (name)
   (substitute #\_ #\/ name))