cb75e5e5b3959db88f637aa4a94a2dcf499ce256
[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 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
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 #:mysql)
18
19 ;; searches clsql_mysql64 to accomodate both 32-bit and 64-bit libraries on same system
20 (defparameter *clsql-mysql-library-candidate-names*
21   `(,@(when (> most-positive-fixnum (expt 2 32)) (list "clsql_mysql64"))
22     "clsql_mysql"))
23
24 (defvar *mysql-library-candidate-names*
25   '(
26     #+(or allegro cmu lispworks openmcl sb-thread scl) "libmysqlclient_r"
27     "libmysqlclient"
28     "libmysql"))
29
30
31
32 (defvar *mysql-supporting-libraries* '("c")
33   "Used only by CMU. List of library flags needed to be passed to ld to
34 load the MySQL client library succesfully.  If this differs at your site,
35 set to the right path before compiling or loading the system.")
36
37 (defvar *mysql-library-loaded* nil
38   "T if foreign library was able to be loaded successfully")
39
40 (defmethod clsql-sys:database-type-library-loaded ((database-type (eql :mysql)))
41   *mysql-library-loaded*)
42
43 (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :mysql)))
44   (unless *mysql-library-loaded*
45     (clsql:push-library-path clsql-mysql-system::*library-file-dir*)
46
47     (clsql-uffi:find-and-load-foreign-library *mysql-library-candidate-names*
48                                               :module "mysql"
49                                               :supporting-libraries *mysql-supporting-libraries*)
50
51     (clsql-uffi:find-and-load-foreign-library *clsql-mysql-library-candidate-names*
52                                               :module "clsql-mysql"
53                                               :supporting-libraries *mysql-supporting-libraries*)
54     (setq *mysql-library-loaded* t)))
55
56 (clsql-sys:database-type-load-foreign :mysql)