r10039: * BUGS: New file. Document suspected SIGPIPE
[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    "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       #+64bit "/usr/lib64/"
36       "/usr/lib/" "/usr/local/lib/mysql/" "/usr/lib/mysql/" "/mysql/lib/opt/" "/sw/lib/mysql/" "/opt/local/lib/mysql/"))
37
38 (defvar *mysql-library-candidate-drive-letters* '("C" "D" "E"))
39
40 (defvar *mysql-supporting-libraries* '("c")
41   "Used only by CMU. List of library flags needed to be passed to ld to
42 load the MySQL client library succesfully.  If this differs at your site,
43 set to the right path before compiling or loading the system.")
44
45 (defvar *mysql-library-loaded* nil
46   "T if foreign library was able to be loaded successfully")
47
48 (defmethod clsql-sys:database-type-library-loaded ((database-type (eql :mysql)))
49   *mysql-library-loaded*)
50                                       
51 (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :mysql)))
52   (let ((mysql-path
53          (uffi:find-foreign-library *mysql-library-candidate-names*
54                                     *mysql-library-candidate-directories*
55                                     :drive-letters
56                                     *mysql-library-candidate-drive-letters*)))
57     (unless (probe-file mysql-path)
58       (error "Can't find mysql client library to load"))
59     (uffi:load-foreign-library mysql-path
60                                :module "mysql" 
61                                :supporting-libraries 
62                                *mysql-supporting-libraries*)
63     (uffi:load-foreign-library *clsql-mysql-library-path* 
64                                :module "clsql-mysql" 
65                                :supporting-libraries 
66                                (append *mysql-supporting-libraries*)))
67   (setq *mysql-library-loaded* t))
68
69
70 (clsql-sys:database-type-load-foreign :mysql)
71