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.7 2002/03/29 08:23:38 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 (defmethod database-type-library-loaded ((database-type (eql :aodbc)))
24 "T if foreign library was able to be loaded successfully. "
25 (when (find-package :dbi) ;; finds Allegro's DBI (AODBC) package
28 (defmethod clsql-sys:database-type-load-foreign ((databae-type (eql :aodbc)))
31 (when (find-package :dbi)
32 (clsql-sys:database-type-load-foreign :aodbc)) ;; doesn't do anything
34 (defmethod database-initialize-database-type ((database-type (eql :aodbc)))
37 (defclass aodbc-database (database)
38 ((aodbc-conn :accessor database-aodbc-conn :initarg :aodbc-conn)))
40 (defmethod database-name-from-spec (connection-spec
41 (database-type (eql :aodbc)))
42 (check-connection-spec connection-spec database-type (dsn user password))
43 (destructuring-bind (dsn user password) connection-spec
44 (declare (ignore password))
45 (concatenate 'string dsn "/" user)))
47 (defmethod database-connect (connection-spec (database-type (eql :aodbc)))
48 (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:connect :user user
56 :data-source-name dsn))
57 (error () ;; Init or Connect failed
58 (error 'clsql-connect-error
59 :database-type database-type
60 :connection-spec connection-spec
62 :error "Connection failed")))))
64 (defmethod database-disconnect ((database aodbc-database))
65 (dbi:disconnect (database-aodbc-conn database))
66 (setf (database-aodbc-conn database) nil)
69 (defmethod database-query (query-expression (database aodbc-database) types)
71 (dbi:sql query-expression :db (database-aodbc-conn database)
74 (error 'clsql-sql-error
76 :expression query-expression
78 :error "Query failed"))))
80 (defmethod database-execute-command (sql-expression
81 (database aodbc-database))
83 (dbi:sql sql-expression :db (database-aodbc-conn database))
85 (error 'clsql-sql-error
87 :expression sql-expression
89 :error "Execute command failed"))))
91 (defstruct aodbc-result-set
93 (types nil :type cons)
94 (full-set nil :type boolean))
96 (defmethod database-query-result-set (query-expression (database aodbc-database)
99 (multiple-value-bind (query column-names)
100 (dbi:sql query-expression
101 :db (database-aodbc-conn database)
108 (make-aodbc-result-set :query query :full-set full-set
110 (length column-names)
111 nil ;; not able to return number of rows with aodbc
114 (error 'clsql-sql-error
116 :expression query-expression
118 :error "Query result set failed"))))
120 (defmethod database-dump-result-set (result-set (database aodbc-database))
121 (dbi:close-query (aodbc-result-set-query result-set))
124 (defmethod database-store-next-row (result-set
125 (database aodbc-database)
127 (let ((row (dbi:fetch-row (aodbc-result-set-query result-set) nil 'eof)))
131 (loop for elem in row
134 (setf (car rest) elem))