r8936: merged classic-tests into tests
[clsql.git] / db-mysql / mysql-loader.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          mysql-loader.sql
6 ;;;; Purpose:       MySQL library loader using UFFI
7 ;;;; Programmers:   Kevin M. Rosenberg
8 ;;;; Date Started:  Feb 2002
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; CLSQL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (in-package :mysql)
20
21 ;;;; Modified by Kevin Rosenberg 
22 ;;;;  - probe potential directories to find library
23 ;;;;  - Changed from CMUCL functions to UFFI to
24 ;;;;      -- prevent library from being loaded multiple times
25 ;;;;      -- support Allegro CL and Lispworks
26
27 (defparameter *clsql-mysql-library-path* 
28   (uffi:find-foreign-library
29    "mysql"
30    `(,(make-pathname :directory (pathname-directory *load-truename*))
31      "/usr/lib/clsql/"
32      "/sw/lib/clsql/"
33      "/home/kevin/debian/src/clsql/db-mysql/")
34    :drive-letters '("C")))
35
36 (defparameter *libz-library-path* 
37   (uffi:find-foreign-library
38    '("libz" "zlib")
39    `(,(make-pathname :directory (pathname-directory *load-truename*))
40       "/usr/lib/"
41       "/sw/lib/"
42       "/usr/local/lib/"
43       "/home/kevin/debian/src/clsql/db-mysql/"
44       "/mysql/lib/opt/")
45    :drive-letters '("C")))
46   
47 (defvar *mysql-library-candidate-names*
48     '("libmysqlclient" "libmysql"))
49
50 (defparameter *mysql-library-candidate-directories*
51     `(,(pathname-directory *load-pathname*)
52       "/opt/mysql/lib/mysql/" "/usr/local/lib/" "/usr/lib/" "/usr/local/lib/mysql/" "/usr/lib/mysql/" "/mysql/lib/opt/" "/sw/lib/mysql/"))
53
54 (defvar *mysql-library-candidate-drive-letters* '("C" "D" "E"))
55
56 (defvar *mysql-supporting-libraries* '("c")
57   "Used only by CMU. List of library flags needed to be passed to ld to
58 load the MySQL client library succesfully.  If this differs at your site,
59 set to the right path before compiling or loading the system.")
60
61 (defvar *mysql-library-loaded* nil
62   "T if foreign library was able to be loaded successfully")
63
64 (defmethod clsql-base-sys:database-type-library-loaded ((database-type (eql :mysql)))
65   *mysql-library-loaded*)
66                                       
67 (defmethod clsql-base-sys:database-type-load-foreign ((database-type (eql :mysql)))
68   (let ((mysql-path
69          (uffi:find-foreign-library *mysql-library-candidate-names*
70                                     *mysql-library-candidate-directories*
71                                     :drive-letters
72                                     *mysql-library-candidate-drive-letters*)))
73     (unless (probe-file mysql-path)
74       (error "Can't find mysql client library to load"))
75     (uffi:load-foreign-library *libz-library-path*) 
76     (uffi:load-foreign-library mysql-path
77                                :module "mysql" 
78                                :supporting-libraries 
79                                *mysql-supporting-libraries*)
80     (uffi:load-foreign-library *clsql-mysql-library-path* 
81                                :module "clsql-mysql" 
82                                :supporting-libraries 
83                                (append *mysql-supporting-libraries*)))
84   (setq *mysql-library-loaded* t))
85
86
87 (clsql-base-sys:database-type-load-foreign :mysql)
88