r9456: relax type for server-version
[clsql.git] / db-aodbc / aodbc-sql.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          aodbc-sql.cl
6 ;;;; Purpose:       Low-level interface for CLSQL AODBC backend
7 ;;;; Programmer:    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 #:clsql-aodbc)
20
21 ;; interface foreign library loading routines
22 (defmethod clsql-sys:database-type-library-loaded ((database-type (eql :aodbc)))
23   "T if foreign library was able to be loaded successfully. "
24   (when (find-package :dbi) ;; finds Allegro's DBI (AODBC) package
25     t))
26
27 (defmethod clsql-sys:database-type-load-foreign ((databae-type (eql :aodbc)))
28   t)
29
30 (when (find-package :dbi)
31   (clsql-sys:database-type-load-foreign :aodbc)) 
32
33
34 ;; AODBC interface
35
36 (defclass aodbc-database (generic-odbc-database)
37   ((aodbc-conn :accessor database-aodbc-conn :initarg :aodbc-conn)
38    (aodbc-db-type :accessor database-aodbc-db-type :initform :unknown)))
39
40 (defmethod database-name-from-spec (connection-spec
41                                     (database-type (eql :aodbc)))
42   (check-connection-spec connection-spec database-type (dsn user password))
43   (destructuring-bind (dsn user password) connection-spec
44     (declare (ignore password))
45     (concatenate 'string dsn "/" user)))
46
47 (defmethod database-connect (connection-spec (database-type (eql :aodbc)))
48   (check-connection-spec connection-spec database-type (dsn user password))
49   #+aodbc-v2
50   (destructuring-bind (dsn user password) connection-spec
51     (handler-case
52         (make-instance 'aodbc-database
53           :name (database-name-from-spec connection-spec :aodbc)
54           :database-type :aodbc
55           :dbi-package (find-package '#:dbi)
56           :aodbc-conn
57           (dbi:connect :user user
58                        :password password
59                        :data-source-name dsn))
60       (clsql-error (e)
61         (error e))
62       (error ()         ;; Init or Connect failed
63         (error 'sql-connection-error
64                :database-type database-type
65                :connection-spec connection-spec
66                :message "Connection failed")))))
67
68
69
70 (defmethod database-create (connection-spec (type (eql :aodbc)))
71   (warn "Not implemented."))
72
73 (defmethod database-destroy (connection-spec (type (eql :aodbc)))
74   (warn "Not implemented."))
75
76 (defmethod database-probe (connection-spec (type (eql :aodbc)))
77   (warn "Not implemented."))
78
79 ;;; Backend capabilities
80
81 (defmethod database-underlying-type ((database aodbc-database))
82   (database-aodbc-db-type database))
83
84 (defmethod db-backend-has-create/destroy-db? ((db-type (eql :aodbc)))
85   nil)
86
87 (defmethod database-initialize-database-type ((database-type (eql :aodbc)))
88   t)
89
90 (when (clsql-sys:database-type-library-loaded :aodbc)
91   (clsql-sys:initialize-database-type :database-type :aodbc))