r4837: Auto commit for Debian build
[umlisp.git] / sql-create.lisp
index 700af8f6c9c06f1ac8e74faa256467d2c733963a..1868e12488192619b4eadc066fc5699b03bf91de 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2000
 ;;;;
-;;;; $Id: sql-create.lisp,v 1.13 2003/05/06 04:42:55 kevin Exp $
+;;;; $Id: sql-create.lisp,v 1.16 2003/05/06 06:09:29 kevin Exp $
 ;;;;
 ;;;; This file, part of UMLisp, is
 ;;;;    Copyright (c) 2000-2002 by Kevin M. Rosenberg, M.D.
       (custom-col-values (custom-colstructs-for-file file) values t)))))
 
 
-(defun custom-col-value (col doquote values)
+(defun custom-col-value (col values doquote)
   (let ((custom-value (funcall (umls-col-custom-value-func col) values)))
-    (if doquote
-       (let ((q (umls-col-quotechar col)))
-         (concatenate 'string q (escape-backslashes custom-value) q))
-       (escape-backslashes custom-value))))
+    (if custom-value
+       (if doquote
+           (let ((q (umls-col-quotechar col)))
+             (concatenate 'string q (escape-backslashes custom-value) q))
+           (escape-backslashes custom-value))
+       "")))
 
 (defun custom-col-values (colstructs values doquote)
   "Returns a list of string column values for SQL inserts for custom columns"
-  (loop for col in colstructs collect (custom-col-value col doquote values)))
-
+  (loop for col in colstructs collect (custom-col-value col values doquote)))
 
 (defun remove-custom-cols (cols)
   "Remove custom cols from a list col umls-cols"
@@ -193,25 +194,24 @@ This is much faster that using create-umls-db-insert."
   (make-noneng-index-file extension)
   (dolist (f *umls-files*) (translate-umls-file f extension)))
 
-(defun translate-file (filename extension files)
-  "Translate a umls file into a format suitable for sql copy cmd"
-  (let ((output-path (umls-pathname filename extension))
-       (input-files (mklist files)))
-    (if (probe-file output-path)
-       (format t "File ~A already exists: skipping~%" output-path)
-       (dolist (input-file input-files)
-         (with-open-file (ostream output-path :direction :output)
-           (with-umls-file (line (umls-file-fil input-file))
-             (umls-translate input-file line ostream)
-             (princ #\newline ostream)))))))
-
 (defun translate-umls-file (file extension)
   "Translate a umls file into a format suitable for sql copy cmd"
-  (translate-file (umls-file-fil file) extension file))
+  (translate-files (umls-file-fil file) extension (list file)))
 
 (defun make-noneng-index-file (extension)
   "Make non-english index file"
-  (translate-file "MRXW.NONEN" extension (noneng-lang-index-files)))
+  (translate-files "MRXW.NONENG" extension (noneng-lang-index-files)))
+
+(defun translate-files (output-basename extension input-files)
+  "Translate a umls file into a format suitable for sql copy cmd"
+  (let ((output-path (umls-pathname output-basename extension)))
+    (if (probe-file output-path)
+       (format t "File ~A already exists: skipping~%" output-path)
+      (with-open-file (ostream output-path :direction :output)
+       (dolist (input-file input-files)
+         (with-umls-file (line (umls-file-fil input-file))
+           (umls-translate input-file line ostream)
+           (princ #\newline ostream)))))))
 
 (defun pg-copy-cmd (file extension)
   "Return postgresql copy statement for a file"  
@@ -227,9 +227,11 @@ This is much faster that using create-umls-db-insert."
    (umls-pathname (umls-file-fil file) extension) (umls-file-table file)))
 
 (defun col-value (col value)
-  (if (eq (umls-col-datatype col) 'sql-u)
-      (write-to-string (parse-ui value ""))
-      (escape-backslashes value)))
+  (if value
+      (if (eq (umls-col-datatype col) 'sql-u)
+         (write-to-string (parse-ui value ""))
+         (escape-backslashes value))
+      ""))
 
 (defun umls-translate (file line strm)
   "Translate a single line for sql output"