Automated commit for debian release 6.7.2-1
[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 ;;;; This file, part of CLSQL, is Copyright (c) 2002 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 #:clsql-aodbc)
18
19 ;; interface foreign library loading routines
20 (defmethod clsql-sys:database-type-library-loaded ((database-type (eql :aodbc)))
21   "T if foreign library was able to be loaded successfully. "
22   (when (find-package :dbi) ;; finds Allegro's DBI (AODBC) package
23     t))
24
25 (defmethod clsql-sys:database-type-load-foreign ((databae-type (eql :aodbc)))
26   t)
27
28 (when (find-package :dbi)
29   (clsql-sys:database-type-load-foreign :aodbc))
30
31
32 ;; AODBC interface
33
34 (defclass aodbc-database (generic-odbc-database)
35   ((aodbc-db-type :accessor database-aodbc-db-type :initform :unknown)))
36
37 (defmethod database-name-from-spec (connection-spec
38                                     (database-type (eql :aodbc)))
39   (check-connection-spec connection-spec database-type (dsn user password))
40   (destructuring-bind (dsn user password) connection-spec
41     (declare (ignore password))
42     (concatenate 'string dsn "/" user)))
43
44 (defmethod database-connect (connection-spec (database-type (eql :aodbc)))
45   (check-connection-spec connection-spec database-type (dsn user password))
46   #+aodbc-v2
47   (destructuring-bind (dsn user password) connection-spec
48     (handler-case
49         (make-instance 'aodbc-database
50           :name (database-name-from-spec connection-spec :aodbc)
51           :database-type :aodbc
52           :dbi-package (find-package '#:dbi)
53           :odbc-conn
54           (dbi:connect :user user
55                        :password password
56                        :data-source-name dsn))
57       (sql-error (e)
58         (error e))
59       (error ()         ;; Init or Connect failed
60         (error 'sql-connection-error
61                :database-type database-type
62                :connection-spec connection-spec
63                :message "Connection failed")))))
64
65
66 (defmethod database-query (query-expression (database aodbc-database)
67                            result-types field-names)
68   #+aodbc-v2
69   (handler-case
70       (dbi:sql query-expression
71                :db (clsql-sys::odbc-conn database)
72                :types result-types
73                :column-names field-names)
74     #+ignore
75     (error ()
76       (error 'sql-database-data-error
77              :database database
78              :expression query-expression
79              :message "Query failed"))))
80
81 (defmethod database-create (connection-spec (type (eql :aodbc)))
82   (warn "Not implemented."))
83
84 (defmethod database-destroy (connection-spec (type (eql :aodbc)))
85   (warn "Not implemented."))
86
87 (defmethod database-probe (connection-spec (type (eql :aodbc)))
88   (warn "Not implemented."))
89
90 ;;; Backend capabilities
91
92 (defmethod database-underlying-type ((database aodbc-database))
93   (database-aodbc-db-type database))
94
95 (defmethod db-backend-has-create/destroy-db? ((db-type (eql :aodbc)))
96   nil)
97
98 (defmethod database-initialize-database-type ((database-type (eql :aodbc)))
99   t)
100
101 (when (clsql-sys:database-type-library-loaded :aodbc)
102   (clsql-sys:initialize-database-type :database-type :aodbc))