Executing SQL from Python Scripts
Prev
Next

Chapter 11. Executing SQL from Python Scripts

Although Rekall automatically accesses the server database when it gets data for a form or report, or when the user makes changes to data in a form, Rekall also allows direct access to the server database. It does this by providing a python class RekallPYDBI which is a (partial) implementation of the python DBI2 specification.

Essentially, RekallPYDBI allows you to write and execute SQL queries that interact directly with the server database [48] . Currently, just the select, insert, update and delete SQL commands are supported (so you cannot, for instance, create or drop a table).

Connecting to the server database

The first stage in using RekallPYDBI is to connect to the server database. This is shown in the example below, and uses the connect function. The first argument can be any object in the form or report. For instance, if the code is in the onClick event function of a button then use the button as the argument [49] . The second argument is the server name used to identify the server database.

import RekallPYDBI
connection = RekallPYDBI.connect (object, server)
        

You now have a connection to the same server database. The next step is to create a cursor, which is an object which can execute SQL queries.

import RekallPYDBI
connection = RekallPYDBI.connect (object, server)
cursor = connection.cursor ()
        



[48] You can, of course, import another python DBI module and use that to access a server database, however you will need to code in details such as the username and password for the server database.

[49] The first argument is needed in case you have opened multiple databases in the same instance of Rekall.

Prev
Next
Home