OCaml as a SQL*Plus replacement?

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
      while true do
	  let row = Array.map orastring (orafetch sth) in
	  r#add_row row;
    with |Not_found -> ();
  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";;
----------- -------------------- ----------------------- ---------------- 
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.

About Gaius

Jus' a good ol' boy, never meanin' no harm
This entry was posted in Ocaml, OCIML, Oracle. Bookmark the permalink.

4 Responses to OCaml as a SQL*Plus replacement?

  1. Pingback: OCI*ML: Minor updates | So I decided to take my work back underground

  2. Pingback: OCI*ML: Ref Cursors and Raw Messages | So I decided to take my work back underground

  3. Pingback: Scala Quickstart for Oracle DBAs | So I decided to take my work back underground

  4. Pingback: Quick histograms | So I decided to take my work back underground

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s