Just re-read the Jane Street article OCaml as a scripting language†, and added an interactive toplevel to OCI*ML and a first stab at a make install task, but I still have to do:



$ ocimlsh -I <directory where ociml.cma and .cmi are>



So there must be something wrong in my Makefile 😦 Anyone got any suggestions?

Anyway, consider (qq for “quick query”):

open Ociml open Report let qq sth sqltext = orasql sth sqltext; let r = new report (Array.map orastring (oracols sth)) in begin try while true do let row = Array.map orastring (orafetch sth) in r#add_row row; done; with |Not_found -> (); end; r#print_report ();

Save as qq.ml then:

$ ../ociml/ocimlsh -I ../ociml/ Objective Caml version 3.12.0 # #use "qq.ml";; # let lda = oralogon "gaius/abc123";; # let sth = oraopen lda;; # qq sth "select * from ociml_test";; CONSTANT_ID DATE_ENTERED CONSTANT_NAME CONST_VALUE ----------- -------------------- ----------------------- ---------------- 1 13-MAY-2011 20:47:09 PI 3.142000 2 01-JAN-1970 01:00:00 e 2.718000 3 13-MAY-2011 20:47:10 Square root 2 1.410000 4 13-MAY-2011 20:47:10 Speed of light 300000000.000000 5 13-MAY-2011 20:47:10 Acceleration of gravity 9.800000 - : unit = () #

I need to make ocimlsh as straightforward to use as SQL*Plus so that even people who presently mash up sqlplus and bash to write “throwaway” scripts will want to adopt it. I think it’s already simpler than Perl and DBI. And Report formats better than SQL*Plus which always gets the column widths wrong…

† Also see Scripting with Types from Galois.