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.4 2002/03/24 18:39:32 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 database-initialize-database-type ((database-type (eql :aodbc)))
31 (defclass aodbc-database (database)
32 ((aodbc-conn :accessor database-aodbc-conn :initarg :aodbc-conn)))
34 (defmethod database-name-from-spec (connection-spec
35 (database-type (eql :aodbc)))
36 (check-connection-spec connection-spec database-type (dsn user password))
37 (destructuring-bind (dsn user password) connection-spec
38 (declare (ignore password))
39 (concatenate 'string dsn "/" user)))
41 (defmethod database-connect (connection-spec (database-type (eql :aodbc)))
42 (check-connection-spec connection-spec database-type (dsn user password))
43 (destructuring-bind (dsn user password) connection-spec
45 (make-instance 'aodbc-database
46 :name (database-name-from-spec connection-spec :aodbc)
48 (dbi:connect :user user
50 :data-source-name dsn))
51 (error () ;; Init or Connect failed
52 (error 'clsql-connect-error
53 :database-type database-type
54 :connection-spec connection-spec
56 :error "Connection failed")))))
58 (defmethod database-disconnect ((database aodbc-database))
59 (dbi:disconnect (database-aodbc-conn database))
60 (setf (database-aodbc-conn database) nil)
63 (defmethod database-query (query-expression (database aodbc-database) field-types)
65 (dbi:sql query-expression :db (database-aodbc-conn database))
67 (error 'clsql-sql-error
69 :expression query-expression
71 :error "Query failed"))))
73 (defmethod database-execute-command (sql-expression
74 (database aodbc-database))
76 (dbi:sql sql-expression :db (database-aodbc-conn database))
78 (error 'clsql-sql-error
80 :expression sql-expression
82 :error "Execute command failed"))))
84 (defstruct aodbc-result-set
86 (field-types nil :type cons)
87 (full-set nil :type boolean))
89 (defmethod database-query-result-set (query-expression (database aodbc-database)
90 &key full-set field-types)
92 (multiple-value-bind (query column-names)
93 (dbi:sql query-expression
94 :db (database-aodbc-conn database)
100 (make-aodbc-result-set :query query :full-set full-set
101 :field-types field-types)
102 (length column-names)
103 nil ;; not able to return number of rows with aodbc
106 (error 'clsql-sql-error
108 :expression query-expression
110 :error "Query result set failed"))))
112 (defmethod database-dump-result-set (result-set (database aodbc-database))
113 (dbi:close-query (aodbc-result-set-query result-set))
116 (defmethod database-store-next-row (result-set
117 (database aodbc-database)
119 (let ((row (dbi:fetch-row (aodbc-result-set-query result-set) nil 'eof)))
123 (loop for elem in row
126 (setf (car rest) elem))