blob: 98f9ec82d1161286475f802210afaa9998a961ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
;;;; *************************************************************************
;;;; FILE IDENTIFICATION
;;;;
;;;; Name: aodbc-sql.cl
;;;; Purpose: Low-level interface for CLSQL AODBC backend
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Feb 2002
;;;;
;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
;;;; CLSQL users are granted the rights to distribute and use this software
;;;; as governed by the terms of the Lisp Lesser GNU Public License
;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
;;;; *************************************************************************
(in-package #:clsql-aodbc)
;; interface foreign library loading routines
(defmethod clsql-sys:database-type-library-loaded ((database-type (eql :aodbc)))
"T if foreign library was able to be loaded successfully. "
(when (find-package :dbi) ;; finds Allegro's DBI (AODBC) package
t))
(defmethod clsql-sys:database-type-load-foreign ((databae-type (eql :aodbc)))
t)
(when (find-package :dbi)
(clsql-sys:database-type-load-foreign :aodbc))
;; AODBC interface
(defclass aodbc-database (generic-odbc-database)
((aodbc-db-type :accessor database-aodbc-db-type :initform :unknown)))
(defmethod database-name-from-spec (connection-spec
(database-type (eql :aodbc)))
(check-connection-spec connection-spec database-type (dsn user password))
(destructuring-bind (dsn user password) connection-spec
(declare (ignore password))
(concatenate 'string dsn "/" user)))
(defmethod database-connect (connection-spec (database-type (eql :aodbc)))
(check-connection-spec connection-spec database-type (dsn user password))
#+aodbc-v2
(destructuring-bind (dsn user password) connection-spec
(handler-case
(make-instance 'aodbc-database
:name (database-name-from-spec connection-spec :aodbc)
:database-type :aodbc
:dbi-package (find-package '#:dbi)
:odbc-conn
(dbi:connect :user user
:password password
:data-source-name dsn))
(sql-error (e)
(error e))
(error () ;; Init or Connect failed
(error 'sql-connection-error
:database-type database-type
:connection-spec connection-spec
:message "Connection failed")))))
(defmethod database-query (query-expression (database aodbc-database)
result-types field-names)
#+aodbc-v2
(handler-case
(dbi:sql query-expression
:db (clsql-sys::odbc-conn database)
:types result-types
:column-names field-names)
#+ignore
(error ()
(error 'sql-database-data-error
:database database
:expression query-expression
:message "Query failed"))))
(defmethod database-create (connection-spec (type (eql :aodbc)))
(warn "Not implemented."))
(defmethod database-destroy (connection-spec (type (eql :aodbc)))
(warn "Not implemented."))
(defmethod database-probe (connection-spec (type (eql :aodbc)))
(warn "Not implemented."))
;;; Backend capabilities
(defmethod database-underlying-type ((database aodbc-database))
(database-aodbc-db-type database))
(defmethod db-backend-has-create/destroy-db? ((db-type (eql :aodbc)))
nil)
(defmethod database-initialize-database-type ((database-type (eql :aodbc)))
t)
(when (clsql-sys:database-type-library-loaded :aodbc)
(clsql-sys:initialize-database-type :database-type :aodbc))
|