8ca48f904331670420e80c83de047278d25e205f
[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-filenames*
26   (list "libclntsh" "oci"))
27
28 (defvar *oracle-supporting-libraries* '("c")
29   "Used only by CMU. List of library flags needed to be passed to ld to
30 load the Oracle client library succesfully.  If this differs at your site,
31 set to the right path before compiling or loading the system.")
32
33 (defvar *oracle-library-loaded* nil
34   "T if foreign library was able to be loaded successfully")
35
36 (defmethod clsql-sys:database-type-library-loaded ((database-type (eql :oracle)))
37   *oracle-library-loaded*)
38
39 (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :oracle)))
40   (when *oracle-home*
41     (dolist (dir-name '("lib" "bin"))
42       (dolist (lib-name '("libclntsh" "oci"))
43         (clsql:push-library-path
44          (make-pathname :name lib-name
45                         :directory (append (pathname-directory *oracle-home*)
46                                            (list dir-name)))))))
47
48   (clsql-uffi:find-and-load-foreign-library *oracle-client-library-filenames*
49                                             :module "clsql-oracle"
50                                             :supporting-libraries *oracle-supporting-libraries*)
51   (setq *oracle-library-loaded* t))
52
53 (clsql-sys:database-type-load-foreign :oracle)
54
55