From: ·····@thelonious.cl-user.org
Subject: interact with oracle from sbcl?
Date: 
Message-ID: <87k5orwjvz.fsf@thelonious.cl-user.org>
Any suggestions about what is the best way to interact with oracle
from sbcl running on 64bit linux?

-russ

From: Alessio
Subject: Re: interact with oracle from sbcl?
Date: 
Message-ID: <1194623946.738694.306670@22g2000hsm.googlegroups.com>
On Nov 9, 3:53 pm, ·····@thelonious.cl-user.org wrote:
> Any suggestions about what is the best way to interact with oracle
> from sbcl running on 64bit linux?
>
> -russ

If it supports oracle (I think it does, at least to some extent), you
can use CL-SQL - check its documentation.

Otherwise - I have limited knowledge of Oracle, but AFAIK you could:

- use the Oracle C libraries through CFFI or SBCL's FFI, or
- interact with it via sockets (if the protocol is not too complex, I
don't know), or
- run sqlplus from SBCL and pass it commands through redirected
standard I/O.

(note that these approaches in general can be used with other CL
implementations or even other languages). IMHO the best way would be
using the C libraries if it's feasible, since it's the most efficient
way. Otherwise the other two methods might do too, if you don't have
excessive expectations, in particular running sqlplus should be
particularly straightforward, even if inefficient.

Alessio Stalla
From: Tim X
Subject: Re: interact with oracle from sbcl?
Date: 
Message-ID: <87abpm6b12.fsf@lion.rapttech.com.au>
Alessio <·············@gmail.com> writes:

> On Nov 9, 3:53 pm, ·····@thelonious.cl-user.org wrote:
>> Any suggestions about what is the best way to interact with oracle
>> from sbcl running on 64bit linux?
>>
>> -russ
>
> If it supports oracle (I think it does, at least to some extent), you
> can use CL-SQL - check its documentation.
>
> Otherwise - I have limited knowledge of Oracle, but AFAIK you could:
>
> - use the Oracle C libraries through CFFI or SBCL's FFI, or
> - interact with it via sockets (if the protocol is not too complex, I
> don't know), or
> - run sqlplus from SBCL and pass it commands through redirected
> standard I/O.
>
> (note that these approaches in general can be used with other CL
> implementations or even other languages). IMHO the best way would be
> using the C libraries if it's feasible, since it's the most efficient
> way. Otherwise the other two methods might do too, if you don't have
> excessive expectations, in particular running sqlplus should be
> particularly straightforward, even if inefficient.
>

Its been a while since I've done it and I'm not sure if cl-sql has been
updated to handle the latest versions of Oracle, but this did work with
oracle 8i. You need the Oracle client libs installed in order to build
cl-sql-oracle as it uses cffi (or at least one of the ffi's). 

I also did a 'poor mans' interface over ssh using sqlplus that provided a
way to instert/retrieve data. This was initially used from within emacs
when I didn't have access to sqlplus on the local box (and therefore
couldn't use emacs sql-mode, which uses sqlplus to provide an interactive
interface to the database). 

Essentially, the script just executed sqlplus over ssh and redirected
input/output so that anything sent to the scripts stdin was sent to sqlplus
and anything returned by sqlplus was sent out on stdout. I used this
technique for a number of scripts and with a number of languages - can't
remember if CL was one, but Tcl, Perl, Bash and elisp certainly were. Can't
see why it couldn't be done with any CL that allows you to execute a script
and grab/send output/input.
 
Tim

-- 
tcross (at) rapttech dot com dot au
From: John Thingstad
Subject: Re: interact with oracle from sbcl?
Date: 
Message-ID: <op.t1i953ltut4oq5@pandora.alfanett.no>
P� Fri, 09 Nov 2007 15:53:04 +0100, skrev <·····@thelonious.cl-user.org>:

>
> Any suggestions about what is the best way to interact with oracle
> from sbcl running on 64bit linux?
>
> -russ

clsql supports oracle.

Here is a example. a sligthly modified except from a blog program I wrote  
earlier this fall. untested on oracle

(defpackage :test
   (:export :init-db :get-items)
   (:use :cl :clsql))

(in-package :test)

(defparameter *connection*)

(defun init-db ()
   (initialize-database-type :database-type :oracle)
   (setf *connection* (connect '("host" "database" "user" "password"))))

(defun to-plist (column titles)
   (mapcan (lambda (item title)
             (list (intern (string-upcase title) "KEYWORD")
                   item))
           column titles))

(enable-sql-reader-syntax)

(defun get-items (blog-id)
   (multiple-value-bind (items titles)
       (select [id] [title] [pub_time] [description] [blog_id]
               :from [blog_items]
               :where [= [blog_id] blog-id]
               :order-by [pub_time])
     (iter (for item in items)
       (collect (to-plist item titles)))))

(disable-sql-reader-syntax)

and type

(test:init-db)
(test:get-items 7)

returns

((:ID 6 :TITLE "My second entry" :PUB_TIME "2007-07-02 20:24:44"  
:DESCRIPTION "This is my second entry" :BLOG_ID 7)
(:ID 1 :TITLE "My first entry" :PUB_TIME "2007-07-14 01:28:59"  
:DESCRIPTION "This is my first test" :BLOG_ID 7)
(:ID 191 :TITLE "Blog functional" :PUB_TIME "2007-07-15 19:24:13"  
:DESCRIPTION "" :BLOG_ID 7)
(:ID 223 :TITLE "Fixed" :PUB_TIME "2007-08-16 01:06:49" :DESCRIPTION ""  
:BLOG_ID 7))

Of cource you will need to set up your own database, but you get the idea.

-- 
Sendt med Operas revolusjonerende e-postprogram: http://www.opera.com/mail/
From: ··············@gmail.com
Subject: Re: interact with oracle from sbcl?
Date: 
Message-ID: <1194717897.188046.186110@50g2000hsm.googlegroups.com>
> Any suggestions about what is the best way to interact with oracle
> from sbcl running on 64bit linux?

you can also use cl-rdbms ( http://common-lisp.net/project/cl-rdbms/ )
or directly the OCI CFFI bindings you can find in it.

- attila