r10232: 26 Dec 2004 Kevin Rosenberg <kevin@rosenberg.net>
[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 ;;;; Author:   Kevin M. Rosenberg
8 ;;;; Created:  Feb 2002
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2004 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 (defparameter *clsql-mysql-library-path* 
22   (uffi:find-foreign-library
23    '(#+(or 64bit x86-64) "mysql64" "mysql")
24    `(,clsql-mysql-system::*library-file-dir*
25      "/usr/lib/clsql/"
26      "/sw/lib/clsql/")
27    :drive-letters '("C")))
28
29 (defvar *mysql-library-candidate-names*
30     '("libmysqlclient" "libmysql"))
31
32 (defparameter *mysql-library-candidate-directories*
33     `(,(pathname-directory *load-pathname*)
34       "/opt/mysql/lib/mysql/" "/usr/local/lib/"
35       #+(or 64bit x86-64) "/usr/lib64/" #+(or 64bit x86-64) "/usr/local/lib64/mysql/"
36       #+(or 64bit x86-64) "/usr/local/lib64/"
37       #+(or 64bit x86-64) "/usr/local/lib64/mysql/"
38
39       "/usr/lib/" "/usr/local/lib/mysql/" "/usr/lib/mysql/" "/mysql/lib/opt/" "/sw/lib/mysql/" "/opt/local/lib/mysql/"))
40
41 (defvar *mysql-library-candidate-drive-letters* '("C" "D" "E"))
42
43 (defvar *mysql-supporting-libraries* '("c")
44   "Used only by CMU. List of library flags needed to be passed to ld to
45 load the MySQL client library succesfully.  If this differs at your site,
46 set to the right path before compiling or loading the system.")
47
48 (defvar *mysql-library-loaded* nil
49   "T if foreign library was able to be loaded successfully")
50
51 (defmethod clsql-sys:database-type-library-loaded ((database-type (eql :mysql)))
52   *mysql-library-loaded*)
53                                       
54 (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :mysql)))
55   (let ((mysql-path
56          (uffi:find-foreign-library *mysql-library-candidate-names*
57                                     *mysql-library-candidate-directories*
58                                     :drive-letters
59                                     *mysql-library-candidate-drive-letters*)))
60     (unless (probe-file mysql-path)
61       (error "Can't find mysql client library to load"))
62     (uffi:load-foreign-library mysql-path
63                                :module "mysql" 
64                                :supporting-libraries 
65                                *mysql-supporting-libraries*)
66     (uffi:load-foreign-library *clsql-mysql-library-path* 
67                                :module "clsql-mysql" 
68                                :supporting-libraries 
69                                (append *mysql-supporting-libraries*)))
70   (setq *mysql-library-loaded* t))
71
72
73 (clsql-sys:database-type-load-foreign :mysql)
74