Afficher les réponses par date
Hi Joel
Welcome back in Scheme circles.
I've not tried, but you should be able to use Oracle through my "gperl" Perl interface and the Perl DBI Oracle driver. gperl is bundled with http://scheme.mine.nu/gambit/chjmodule/ . There's a readme file which should help getting it to run (*). You should be able to use the gperl code by just including it and it's dependencies instead of using chjmodule if you don't want to use the latter. Just ask if you have questions or problems.
Note that, as already mentioned on this list, while one scheme thread is running in C libraries (regardless whether it's Perl or something else), other scheme threads don't have a chance to run unless special provisions are taken. Potential solutions include manual pthread creation and synchronization, GHC style FFI extensions for doing that automatically, and Marc Feeley introducing system threads into Gambit. Of course, not using scheme threads, but separate processes (fork) and message passing (Termite?) may be a viable workaround.
Christian.
* http://scheme.mine.nu/gambit/chjmodule/chjmodule-20051128-README.gperl
At 0:48 Uhr +0000 25.01.2006, Joel Reymont wrote:
Folks,
Is anyone using Gambit to connect to Oracle?
Thanks, Joel
Thank you Christian!
I've not tried, but you should be able to use Oracle through my "gperl" Perl interface and the Perl DBI Oracle driver. gperl is bundled with http://scheme.mine.nu/gambit/chjmodule/ . There's a readme file which should help getting it to run (*). You should be able to use the gperl code by just including it and it's dependencies instead of using chjmodule if you don't want to use the latter. Just ask if you have questions or problems.
At 16:47 Uhr +0000 25.01.2006, Joel Reymont wrote:
Thank you Christian!
You're welcome!
Actually, since I will need mysql connectivity relatively soon, and to make sure I didn't promise too much, I've written a quick DBI interface--see below.
(use p-dbi) (define db (dbi.connect "DBI:mysql:EiD" "eid" "the-passwd")) (define sth (dbh.prepare db "select * from _Departementss")) (sth.execute sth)
DBD::mysql::st execute failed: Table 'EiD._Departementss' doesn't exist. #f
(define sth (dbh.prepare db "select * from _Departement")) (sth.execute sth)
26
(sth.fetchrow-array sth)
("1" "Elektrotechnik" "2")
(sth.fetchrow-array sth)
("2" "Werkstoffe" "2")
(sth.fetchrow-array sth)
("3" "Architektur" "1")
(sth.fetchrow-array sth)
("4" "Physik" "3")
(sth.fetchrow-array sth)
("5" "Umweltnaturwissenschaften" "4")
(dbi.errstr sth)
#f ;; no error.
;; optional (gc will take care of it too):
(dbh.disconnect db)
DBI::db=HASH(0x84f37dc)->disconnect invalidates 1 active statement handle (either destroy statement handles or call finish on them before disconnecting). #t ;; the warning is because I didn't finish reading the result set.
If you want the functions to throw exceptions instead of returning false for errors, the natural way would be to give DBI a RaiseError=>1 attribute. But currently gperl is missing a way to generate perl hashes. If you need those, and don't see how to add the necessary perl XS functions to gperl, ask me to do it.
Cheers Christian.
;;p-dbi-module.scm------------------------------ (requires gperl) (namespace "") ;; trick to avoid having to define an exports list, and ;; work around old bug present in chjmodule (doesn't ;; reimport bindings after module reloads (*)), helpful ;; during developement of a module. ;; (*) of course I shall fix chjmodule some time soon..
;;p-dbi.scm------------------------------------- ;; cj Wed, 25 Jan 2006 19:08:57 +0100
(gperl-activate) (perl-use "DBI")
; (define-perl-method dbi.connect (string/sv string/sv string/sv) ; sv) ;; todo: implement hash handling for: #!optional attrs-hash (define (dbi.connect data-source username auth #!optional attr) (if attr (error "attr argument not yet supported, requires perl hash handling functions in gperl") ((perl-method (string/sv string/sv string/sv string/sv) sv "connect") "DBI" data-source username auth)))
;; (implement perl-object type checking on scheme side ? (using perl isa operation) )
(define-perl-method dbh.do (sv string/sv) string ;;ok? )
; (define-perl-method dbh.selectall_arrayref (sv) ; ;;todo: implement array handling ; ..)
; selectall_hashref
; selectcol_arrayref
(define-perl-method dbh.selectrow-array (sv string/sv) (#!rest string)) ;; return a list of strings.
; selectrow_arrayref
; selectrow_hashref
(define-perl-method dbh.prepare (sv string/sv) sv)
; (define-perl-method sth.execute (sv #!rest string/sv) ; ;; handle return value as false-or-number-of-results. ; ) ; (define (sth.execute sth #!rest bind-values) ; (let ((res (apply ; (perl-method (sv #!rest string/sv) ; sv ; "execute") ; (cons sth bind-values)))) ; (if (sv-true? res) ; (sv->number res) ; #f))) ;ehr actually I did take care of this already in gperl..: (define-perl-method sth.execute (sv #!rest string/sv) number/false)
(define-perl-method sth.fetchrow-array (sv) (#!rest string)) ;; return a list of strings
(define-perl-method dbh.begin-work (sv) boolean;;ok? ;string/false ) (define-perl-method dbh.commit (sv) boolean;;ok? ;string/false ) (define-perl-method dbh.rollback (sv) boolean;;ok? ;string/false )
(define-perl-method dbh.disconnect (sv) boolean)
(define-perl-method dbi.err (sv) number/false)
(define-perl-method dbi.errstr (sv) string/false)
(define-perl-method dbi.state (sv) string)
;; eof
At 20:14 Uhr +0100 25.01.2006, Christian wrote:
I've written a quick DBI interface--see below.
I've noticed a problem: the number/false conversion doesn't accept the "0E0" string returned by DBI as "0 but true" value:
(define sth (dbh.prepare db "create table Foo (id int not null auto_increment primary key, Text varchar(255)) type=innodb")) (sth.execute sth)
*** ERROR IN (console)@21.1 -- Unknown error (gperl#sv->number/false '#<SV* #2 0x8537B64>) 1>
(sv->string #2)
"0E0"
I've put a patch to the current gperl and to the p-dbi sent in my previous mail at this address: http://scheme.mine.nu/gambit/downloads/gperl-and-p-dbi-20050225.patch (I've also added a more verbose message to stderr for the above case. BTW: I should probably change all ".../false" type and conversion-function names to "maybe-...")
With this patch, after rebuilding gperl (bruse gperl) and dopping the Foo table (mysql> drop table Foo;) it now gives:
(sth.execute sth)
0
(sth.execute sth)
DBD::mysql::st execute failed: Table 'Foo' already exists. #f
(define sth (dbh.prepare db "insert into Foo set Text=?")) (sth.execute sth "Hello")
1
(sth.execute sth "World")
1
Cheers Christian.