Plasma GitLab Archive
Projects Blog Knowledge



Never completed bindings for the Informix DBMS

Some years ago, I developed a DBMS driver called OcamlDB targeting the Adabas (an antecedent of MaxDB) and Informix DBMS. This driver is not continued. Maybe the source code is still interesting for similar projects.

The following paragraphs are the only available documentation:

This is an early release of a DBMS driver for Objective Caml. There is a generic interface that must be instantiated with a so-called low level driver. Currently, there is only a driver for the Adabas DBMS. In the very near future I plan to write a second low-level driver for Informix DBMS, but since I have more serious things to do there will be no more drivers written by myself.

Since the whole source code is not very much there will be no 'license'. But I do not guarantee anything. This code may crash your database such that there is nothing to recover, I've warned you.

If you plan to contribute another low-level driver, please contact me. If the DBMS follows the ANSI standards this should not be very difficult, embedded SQL is more or less the same in any DBMS (but do not forget: the details count).

I'm also interested in your ideas to improve the module; my Email address is given below.

Module Structure

  • Db_types: defines various types, especially:
    • signature: types of host variables
    • value: values of host variables
    • date, time: exactly what you think
    • some exceptions
  • Db: defines class Db.t that represents a connection to a concrete DBMS. You can prepare a statement and execute it. There is a special type 'result' to represent (selection) cursors.

    The object of type Db.t knows its driver that is compatible with Dbll.t. Db.t is actually only a layer to increase comfort.

  • Db_login: defines Db_login.t that abstracts over connection data such as user name, password and so on.
  • Dbll: defines the type of low-level drivers. There are many comments and thoughts in this file. Read it to better understand what's going on.

Simple examples

First get login info:

	let login = new Db_login.t;;
	login # init_from_file "login.txt";;
Note that login.txt is a properly parsed configuration file, e.g.
	user = "username"
	password = "password"
	host = "localhost"
	database = "BHB_W"

There are some more possibilities, for example you can force to interactively input the password:
	password = invisible interactive "Enter password: "
Look into the grammar in Db_login to find out more.

Get low-level driver:

	let driver = new Dbll_adabas;;

New Db.t object:

	let db = new Db.t;;
	db # connect login;;
you should now be connected to your DBMS.

Prepare a statement:

	let stm = db # prepare_string "insert into table (?, ?)";;

Check the type of the host variables:

	db # description stm;;
The first array describes variables for input, the second array those for output.
This step can be safely left out.

Execute the statement:

	db # execute stm [| Int 3; Varchar "abc" |]

For "select" statements, a cursor is better:

	let stm' = db # prepare_string "select * from table where id = ?";;

	let r = db # select stm' [| Int 45677 |];;

In "r" there is now the result table.

	let stream = db # open_result r;;
stream is now a value array Stream.t (a stream of rows, and every row is an array of columns)

After you have read "stream" using functions in Stream, do not forget to release the cursor.

	db # close_result r;;


Installation should be easy on any Unix operating system. Please see the README file in the distributed package for details.
Link: OcamlDB
This web site is published by Informatikbüro Gerd Stolpmann
Powered by Caml