r9518: initial db2 support
[clsql.git] / db-db2 / db2-loader.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          db2-loader.lisp
6 ;;;; Purpose:       Foreign library loader for CLSQL Db2 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-db2)
18
19 (defparameter *db2-lib-path*
20   (let ((db2-home (getenv "DB2_HOME")))
21     (when db2-home
22       (make-pathname :directory 
23                      (append 
24                       (pathname-directory
25                        (parse-namestring (concatenate 'string db2-home "/")))
26                         (list "lib"))))))
27
28 (defparameter *db2-client-library-path* 
29     (uffi:find-foreign-library
30      "libdb2"
31      `(,@(when *load-truename* (list (make-pathname :directory (pathname-directory *load-truename*))))
32        ,@(when *db2-lib-path* (list *db2-lib-path*))
33        #+64bit "/opt/IBM/db2/V8.1/lib64/"
34        "/opt/IBM/db2/V8.1/lib/")
35      :drive-letters '("C")))
36
37 (defvar *db2-supporting-libraries* '("c")
38   "Used only by CMU. List of library flags needed to be passed to ld to
39 load the Db2 client library succesfully.  If this differs at your site,
40 set to the right path before compiling or loading the system.")
41
42 (defvar *db2-library-loaded* nil
43   "T if foreign library was able to be loaded successfully")
44
45 (defmethod clsql-sys:database-type-library-loaded ((database-type (eql :db2)))
46   *db2-library-loaded*)
47
48 (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :db2)))
49   (if (pathnamep *db2-client-library-path*) 
50       (progn
51         (uffi:load-foreign-library *db2-client-library-path*
52                                    :module "clsql-db2"
53                                    :supporting-libraries 
54                                    *db2-supporting-libraries*)
55         (setq *db2-library-loaded* t))
56       (warn "Unable to load db2 client library.")))
57
58 (clsql-sys:database-type-load-foreign :db2)
59
60