X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=create-sql.lisp;h=e212536b79bd5a1ca58445c7bf66937a6b5e7e44;hb=aeade16272b79115d3f307906c7a3e9597137e97;hp=8632daab775a4d089aa0b3e900fcd0737c694310;hpb=9c0bccac3fb46e0cb8ab6d2a63b7fc5a92221002;p=umlisp.git diff --git a/create-sql.lisp b/create-sql.lisp index 8632daa..e212536 100644 --- a/create-sql.lisp +++ b/create-sql.lisp @@ -2,15 +2,15 @@ ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; -;;;; Name: sql-create -;;;; Purpose: Create SQL database for UMLisp -;;;; Author: Kevin M. Rosenberg -;;;; Date Started: Apr 2000 +;;;; Name: sql-create +;;;; Purpose: Create SQL database for UMLisp +;;;; Author: Kevin M. Rosenberg +;;;; Created: Apr 2000 ;;;; -;;;; $Id: create-sql.lisp,v 1.5 2003/05/09 11:02:44 kevin Exp $ +;;;; $Id$ ;;;; ;;;; This file, part of UMLisp, is -;;;; Copyright (c) 2000-2002 by Kevin M. Rosenberg, M.D. +;;;; Copyright (c) 2000-2004 by Kevin M. Rosenberg, M.D. ;;;; ;;;; UMLisp users are granted the rights to distribute and use this software ;;;; as governed by the terms of the GNU General Public License. @@ -18,9 +18,6 @@ (in-package #:umlisp) -(eval-when (:compile-toplevel) - (declaim (optimize (speed 3) (safety 1) (compilation-speed 0) (debug 3)))) - (defun create-table-cmd (file) "Return sql command to create a table" (let ((col-func @@ -105,10 +102,21 @@ (defun create-index-cmd (colname tablename length) "Return sql create index command" - (format nil "CREATE INDEX ~a ON ~a (~a ~a)" + (format nil "CREATE INDEX ~a ON ~a (~a)" (concatenate 'string tablename "_" colname "_X") - tablename colname - (if (integerp length) (format nil "(~d)" length) ""))) + tablename + (case *umls-sql-type* + (:mysql + (concatenate 'string colname + (if (integerp length) + (format nil " (~d)" length) + ""))) + ((:postgresql :postgresql-socket) + (if (integerp length) + (format nil "substr(~A,1,~D)" colname length) + colname)) + (t + colname)))) (defun create-all-tables-cmdfile () "Return sql commands to create all tables. Not need for automated SQL import" @@ -148,7 +156,9 @@ (sql-execute (create-index-cmd (car idx) (cadr idx) (caddr idx)) conn))) (defun make-usrl (conn) - (sql-execute "drop table if exists USRL" conn) + (if (eql :mysql *umls-sql-type*) + (sql-execute "drop table if exists USRL" conn) + (ignore-errors (sql-execute "drop table USRL" conn))) (sql-execute "create table USRL (sab varchar(80), srl integer)" conn) (dolist (tuple (mutex-sql-query "select distinct SAB,SRL from MRSO order by SAB asc")) @@ -157,7 +167,8 @@ conn))) (defun sql-create-special-tables (conn) - (make-usrl conn)) + (make-usrl conn) + (make-ustats)) (defun create-umls-db-by-insert () "SQL Databases: initializes entire database via SQL insert commands" @@ -172,22 +183,32 @@ (sql-create-indexes conn +custom-index-cols+) (sql-create-special-tables conn))) -(defun create-umls-db (&optional (extension ".trans") - (copy-cmd #'mysql-copy-cmd)) +(defun create-umls-db (&optional (extension ".trans")) "SQL Databases: initializes entire database via SQL copy commands. This is much faster that using create-umls-db-insert." + (ignore-errors + (clsql:destroy-database (list *umls-sql-host* (lookup-db-name *umls-sql-db*) + *umls-sql-user* *umls-sql-passwd*) + :database-type *umls-sql-type*)) + (clsql:create-database (list *umls-sql-host* (lookup-db-name *umls-sql-db*) + *umls-sql-user* *umls-sql-passwd*) + :database-type *umls-sql-type*) (ensure-ucols+ufiles) (ensure-preparse) (translate-all-files extension) - (with-sql-connection (conn) - (sql-drop-tables conn) - (sql-create-tables conn) - (dolist (file *umls-files*) - (sql-execute (funcall copy-cmd file extension) conn)) - (sql-create-indexes conn) - (sql-create-custom-tables conn) - (sql-create-indexes conn +custom-index-cols+) - (sql-create-special-tables conn))) + (let ((copy-cmd + (ecase (umls-sql-type) + (:mysql #'mysql-copy-cmd) + (:postgresql #'pg-copy-cmd)))) + (with-sql-connection (conn) + (sql-drop-tables conn) + (sql-create-tables conn) + (dolist (file *umls-files*) + (sql-execute (funcall copy-cmd file extension) conn)) + (sql-create-indexes conn) + (sql-create-custom-tables conn) + (sql-create-indexes conn +custom-index-cols+) + (sql-create-special-tables conn)))) (defun translate-all-files (&optional (extension ".trans")) "Copy translated files and return postgresql copy commands to import"