r10015: 21 Sep 2004 Kevin Rosenberg <kevin@rosenberg.net>
[clsql.git] / db-oracle / oracle-loader.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          oracle-loader.lisp
6 ;;;; Purpose:       Foreign library loader for CLSQL Oracle interface
7 ;;;;
8 ;;;; $Id$
9 ;;;;
10 ;;;; This file is part of CLSQL.
11 ;;;;
12 ;;;; CLSQL users are granted the rights to distribute and use this software
13 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
14 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
15 ;;;; *************************************************************************
16
17 (in-package #:clsql-oracle)
18
19 (defparameter *oracle-home*
20   (let ((oracle-home (getenv "ORACLE_HOME")))
21     (when oracle-home
22       (parse-namestring (concatenate 'string oracle-home "/"))))
23   "Pathname of ORACLE_HOME as set in user environment.")
24
25 (defparameter *oracle-client-library-path* 
26     (uffi:find-foreign-library
27      '("libclntsh" "oci")
28      `(,@(when *load-truename*
29            (list (make-pathname
30                   :directory (pathname-directory *load-truename*))))
31          ,@(when *oracle-home*
32              (list
33               (make-pathname :defaults *oracle-home*
34                              :directory 
35                              (append (pathname-directory *oracle-home*)
36                                      (list "lib")))
37               (make-pathname :defaults *oracle-home*
38                              :directory 
39                              (append (pathname-directory *oracle-home*)
40                                      (list "bin")))))
41          "/usr/lib/oracle/10.1.0.2/client/lib/")
42      :drive-letters '("C")))
43
44 (defvar *oracle-supporting-libraries* '("c")
45   "Used only by CMU. List of library flags needed to be passed to ld to
46 load the Oracle client library succesfully.  If this differs at your site,
47 set to the right path before compiling or loading the system.")
48
49 (defvar *oracle-library-loaded* nil
50   "T if foreign library was able to be loaded successfully")
51
52 (defmethod clsql-sys:database-type-library-loaded ((database-type (eql :oracle)))
53   *oracle-library-loaded*)
54
55 (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :oracle)))
56   (if (pathnamep *oracle-client-library-path*) 
57       (progn
58         (uffi:load-foreign-library *oracle-client-library-path*
59                                    :module "clsql-oracle"
60                                    :supporting-libraries 
61                                    *oracle-supporting-libraries*)
62         (setq *oracle-library-loaded* t))
63       (warn "Unable to load oracle client library.")))
64
65 (clsql-sys:database-type-load-foreign :oracle)
66
67