Merge branch 'master' of git://git.b9.com/clsql
[clsql/s11.git] / db-aodbc / aodbc-sql.lisp
blobe83b3fe0aa1bfb0869e3fb36c777fc8959795643
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 ;;;; *************************************************************************
19 (in-package #:clsql-aodbc)
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))
27 (defmethod clsql-sys:database-type-load-foreign ((databae-type (eql :aodbc)))
30 (when (find-package :dbi)
31 (clsql-sys:database-type-load-foreign :aodbc))
34 ;; AODBC interface
36 (defclass aodbc-database (generic-odbc-database)
37 ((aodbc-db-type :accessor database-aodbc-db-type :initform :unknown)))
39 (defmethod database-name-from-spec (connection-spec
40 (database-type (eql :aodbc)))
41 (check-connection-spec connection-spec database-type (dsn user password))
42 (destructuring-bind (dsn user password) connection-spec
43 (declare (ignore password))
44 (concatenate 'string dsn "/" user)))
46 (defmethod database-connect (connection-spec (database-type (eql :aodbc)))
47 (check-connection-spec connection-spec database-type (dsn user password))
48 #+aodbc-v2
49 (destructuring-bind (dsn user password) connection-spec
50 (handler-case
51 (make-instance 'aodbc-database
52 :name (database-name-from-spec connection-spec :aodbc)
53 :database-type :aodbc
54 :dbi-package (find-package '#:dbi)
55 :odbc-conn
56 (dbi:connect :user user
57 :password password
58 :data-source-name dsn))
59 (sql-error (e)
60 (error e))
61 (error () ;; Init or Connect failed
62 (error 'sql-connection-error
63 :database-type database-type
64 :connection-spec connection-spec
65 :message "Connection failed")))))
68 (defmethod database-query (query-expression (database aodbc-database)
69 result-types field-names)
70 #+aodbc-v2
71 (handler-case
72 (dbi:sql query-expression
73 :db (clsql-sys::odbc-conn database)
74 :types result-types
75 :column-names field-names)
76 #+ignore
77 (error ()
78 (error 'sql-database-data-error
79 :database database
80 :expression query-expression
81 :message "Query failed"))))
83 (defmethod database-create (connection-spec (type (eql :aodbc)))
84 (warn "Not implemented."))
86 (defmethod database-destroy (connection-spec (type (eql :aodbc)))
87 (warn "Not implemented."))
89 (defmethod database-probe (connection-spec (type (eql :aodbc)))
90 (warn "Not implemented."))
92 ;;; Backend capabilities
94 (defmethod database-underlying-type ((database aodbc-database))
95 (database-aodbc-db-type database))
97 (defmethod db-backend-has-create/destroy-db? ((db-type (eql :aodbc)))
98 nil)
100 (defmethod database-initialize-database-type ((database-type (eql :aodbc)))
103 (when (clsql-sys:database-type-library-loaded :aodbc)
104 (clsql-sys:initialize-database-type :database-type :aodbc))