| Back: Spire's main menus | Home: Table of Contents | Next: FAQ |
Spire can communicate with an external database. This generally occurs at the beginning and end of a project. At the start of a project Spire can download some project parameters (e.g., electron voltage, pixel resolution, etc) from the database. At the end of a project, final volumes, resolution information, etc. can be uploaded into the database.
Since Spire does not know which database you are using, nor anything about the internal organization of that database, you will have to supply that information. This usually means
- installing an additional Python database library,
- writing some Python code that enables Spire to access your database.
Setting up Spire to connect to an external database: the general case
spiderLocalDB.pyspiderDatabase, which inherits from spiderClasses.SpiderDatabase. This class object must have the following attributes and methods:
| Attributes | |
|---|---|
databaseName | a database name to present to the user, e.g., "the Project Archive" |
id | the project ID number is used to specify a particular project in the database. |
testquery | simple SQL query to test the connection. |
projectquery | another SQL query to fetch project information |
| Methods | |
isExtDatabaseAlive() | returns 1 or 0 depending on whether it can successfully connect. |
sendQuery(query) | returns results of SQL statement |
getProjectInfo() | using the projectquery, fetches project information, and inserts it into GB.P, the internal class object of the current Spire project. |
upload(upload_object) | given an uploadable object, establish a connection and insert data into appropriate places in the external database |
spiderLocalDB.py in $PYTHONPATH/site-packages/Spire
Example: setting up Spire to connect to a MySQL database
The Spire distribution contains example code for a tiny project database in MySQL.You must first:
MySQLdb, installed
newtable.py database user password newtable
loadtable.py database user password table
E.g., for database 'test' and user 'brian', whose password is 'heinz57'
newtable.py test brian heinz57 projects
loadtable.py test brian heinz57 projects
copy this file, spiderLocalMysql.py, to spiderLocalDB.py, and run Spire. Start a new project, enter project number 149. It should fetch data from the MySQL database.