r1648: *** empty log message ***
[clsql.git] / interfaces / postgresql / postgresql-loader.cl
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          postgresql-loader.sql
6 ;;;; Purpose:       PostgreSQL library loader using UFFI
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Feb 2002
9 ;;;;
10 ;;;; $Id: postgresql-loader.cl,v 1.2 2002/03/24 04:01:26 kevin Exp $
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 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
20 (in-package :postgresql)
21
22 (defvar *postgresql-library-filename* 
23     (cond
24      ((probe-file "/opt/postgresql/lib/libpq.so")
25       "/opt/postgresql/lib/libpq.so")
26      ((probe-file "/usr/local/lib/libpq.so")
27       "/usr/local/lib/libpq.so")
28      ((probe-file "/usr/lib/libpq.so")
29       "/usr/lib/libpq.so")
30      #+(or win32 mswindows) 
31      ((probe-file "c:/postgresql/lib/libpq.dll")
32       "c:/postgresql/lib/libpq.dll")
33      (t
34       (warn "Can't find PostgresQL client library to load.")))
35   "Location where the PostgresSQL client library is to be found.")
36
37 (defvar *postgresql-supporting-libraries* '("crypt" "c")
38   "Used only by CMU. List of library flags needed to be passed to ld to
39 load the PostgresSQL client library succesfully.  If this differs at your site,
40 set to the right path before compiling or loading the system.")
41
42 (defvar *postgresql-library-loaded* nil
43   "T if foreign library was able to be loaded successfully")
44
45 (defmethod database-type-library-loaded ((database-type (eql :postgresql)))
46   *postgresql-library-loaded*)
47                                       
48 (defmethod database-type-load-foreign ((database-type (eql :postgresql)))
49   (when
50       (uffi:load-foreign-library *postgresql-library-filename* 
51                                  :module "postgresql"
52                                  :supporting-libraries 
53                                  *postgresql-supporting-libraries*)
54     (setq *postgresql-library-loaded* t)))
55
56 (database-type-load-foreign :postgresql)