1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: aodbc-sql.cl
6 ;;;; Purpose: Low-level interface for CLSQL AODBC backend
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Feb 2002
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
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
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))
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))
49 (destructuring-bind (dsn user password) connection-spec
51 (make-instance 'aodbc-database
52 :name (database-name-from-spec connection-spec :aodbc)
54 :dbi-package (find-package '#:dbi)
56 (dbi:connect :user user
58 :data-source-name dsn))
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)
72 (dbi:sql query-expression
73 :db (clsql-sys::odbc-conn database)
75 :column-names field-names)
78 (error 'sql-database-data-error
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)))
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))