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 ;;;; $Id: aodbc-sql.cl,v 1.8 2002/03/29 08:28:14 kevin Exp $
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 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
20 (in-package :clsql-aodbc)
23 ;; interface foreign library loading routines
24 (defmethod database-type-library-loaded ((database-type (eql :aodbc)))
25 "T if foreign library was able to be loaded successfully. "
26 (when (find-package :dbi) ;; finds Allegro's DBI (AODBC) package
29 (defmethod clsql-sys:database-type-load-foreign ((databae-type (eql :aodbc)))
32 (when (find-package :dbi)
33 (clsql-sys:database-type-load-foreign :aodbc))
35 (defmethod database-initialize-database-type ((database-type (eql :aodbc)))
41 (defclass aodbc-database (database)
42 ((aodbc-conn :accessor database-aodbc-conn :initarg :aodbc-conn)))
44 (defmethod database-name-from-spec (connection-spec
45 (database-type (eql :aodbc)))
46 (check-connection-spec connection-spec database-type (dsn user password))
47 (destructuring-bind (dsn user password) connection-spec
48 (declare (ignore password))
49 (concatenate 'string dsn "/" user)))
51 (defmethod database-connect (connection-spec (database-type (eql :aodbc)))
52 (check-connection-spec connection-spec database-type (dsn user password))
53 (destructuring-bind (dsn user password) connection-spec
55 (make-instance 'aodbc-database
56 :name (database-name-from-spec connection-spec :aodbc)
58 (dbi:connect :user user
60 :data-source-name dsn))
61 (error () ;; Init or Connect failed
62 (error 'clsql-connect-error
63 :database-type database-type
64 :connection-spec connection-spec
66 :error "Connection failed")))))
68 (defmethod database-disconnect ((database aodbc-database))
69 (dbi:disconnect (database-aodbc-conn database))
70 (setf (database-aodbc-conn database) nil)
73 (defmethod database-query (query-expression (database aodbc-database) types)
75 (dbi:sql query-expression :db (database-aodbc-conn database)
78 (error 'clsql-sql-error
80 :expression query-expression
82 :error "Query failed"))))
84 (defmethod database-execute-command (sql-expression
85 (database aodbc-database))
87 (dbi:sql sql-expression :db (database-aodbc-conn database))
89 (error 'clsql-sql-error
91 :expression sql-expression
93 :error "Execute command failed"))))
95 (defstruct aodbc-result-set
97 (types nil :type cons)
98 (full-set nil :type boolean))
100 (defmethod database-query-result-set (query-expression (database aodbc-database)
103 (multiple-value-bind (query column-names)
104 (dbi:sql query-expression
105 :db (database-aodbc-conn database)
112 (make-aodbc-result-set :query query :full-set full-set
114 (length column-names)
115 nil ;; not able to return number of rows with aodbc
118 (error 'clsql-sql-error
120 :expression query-expression
122 :error "Query result set failed"))))
124 (defmethod database-dump-result-set (result-set (database aodbc-database))
125 (dbi:close-query (aodbc-result-set-query result-set))
128 (defmethod database-store-next-row (result-set
129 (database aodbc-database)
131 (let ((row (dbi:fetch-row (aodbc-result-set-query result-set) nil 'eof)))
135 (loop for elem in row
138 (setf (car rest) elem))