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
10 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
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 ;;;; *************************************************************************
17 (in-package #:clsql-aodbc)
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
25 (defmethod clsql-sys:database-type-load-foreign ((databae-type (eql :aodbc)))
28 (when (find-package :dbi)
29 (clsql-sys:database-type-load-foreign :aodbc))
34 (defclass aodbc-database (generic-odbc-database)
35 ((aodbc-db-type :accessor database-aodbc-db-type :initform :unknown)))
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)))
44 (defmethod database-connect (connection-spec (database-type (eql :aodbc)))
45 (check-connection-spec connection-spec database-type (dsn user password))
47 (destructuring-bind (dsn user password) connection-spec
49 (make-instance 'aodbc-database
50 :name (database-name-from-spec connection-spec :aodbc)
52 :dbi-package (find-package '#:dbi)
54 (dbi:connect :user user
56 :data-source-name dsn))
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")))))
66 (defmethod database-query (query-expression (database aodbc-database)
67 result-types field-names)
70 (dbi:sql query-expression
71 :db (clsql-sys::odbc-conn database)
73 :column-names field-names)
76 (error 'sql-database-data-error
78 :expression query-expression
79 :message "Query failed"))))
81 (defmethod database-create (connection-spec (type (eql :aodbc)))
82 (warn "Not implemented."))
84 (defmethod database-destroy (connection-spec (type (eql :aodbc)))
85 (warn "Not implemented."))
87 (defmethod database-probe (connection-spec (type (eql :aodbc)))
88 (warn "Not implemented."))
90 ;;; Backend capabilities
92 (defmethod database-underlying-type ((database aodbc-database))
93 (database-aodbc-db-type database))
95 (defmethod db-backend-has-create/destroy-db? ((db-type (eql :aodbc)))
98 (defmethod database-initialize-database-type ((database-type (eql :aodbc)))
101 (when (clsql-sys:database-type-library-loaded :aodbc)
102 (clsql-sys:initialize-database-type :database-type :aodbc))