This directory contains a SWIG interface for Python to the C
implementation of the MAPI library and a Python package that uses this
interface to provide a Python DB-API 2.0 (*) compliant interface.

The Python DB-API package was written by Arjan Scherpenisse (arjan at
users.sourceforge.net).  The module on which it is based was written
by Sjoerd Mullender <Sjoerd.Mullender@cwi.nl>.

The main interface for the SWIG-generated module is Mapi.py.  It is a
wrapper around the modules generated by SWIG, giving a Pythonic
interface to the Mapi library.  A more direct translation of the C
interface to Python is the generated module MapiLib.py.

A tiny example of the use of Mapi.py follows:

import Mapi
m = Mapi.Mapi(host = 'localhost', port = 45123, username = 'monetdb',
              password = 'monetdb', lang = 'sql')
h = m.query('select * from tables')
while h.fetch_row() > 0:
    for i in range(h.get_field_count()):
        print repr(h.fetch_field(i)),
    print

Note that the version of SWIG that comes with RedHat 9 (swig-1.1p5-22)
is too old for the interface file: we need at least version 1.3.x.


The Python DB-API 2.0 complinat interface is in the module
MonetSQLdb.  A tiny example of how to use this packages follows:

import MonetSQLdb

# Let the cursor return dictionaries instead of tuples:
# x = MonetSQLdb.connect(cursorclass = MonetSQLdb.cursors.DictCursor)

x = MonetSQLdb.connect(host = 'localhost', user = 'monetdb',
		       password = 'monetdb', lang = 'sql')

# Use MIL as language:
#x = MonetSQLdb.connect(host = 'localhost', user = 'monetdb',
#			password = 'monetdb', lang = 'mil', port = 50000)
#c = x.cursor()
#c.execute('ls();')

c = x.cursor()
c.execute('select * from tables')

print c.fetchone()

# print c.fetchall()

x.close()

(*) See http://www.python.org/peps/pep-0249.html
