|Back: Spire's main menus||Home: Table of Contents|
If your lab already has a database of reconstruction projects, Spire can communicate with it. 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 (code for MySQL is included in Spire package).
Setting up Spire to connect to an external database:
spiderLocalMysql.py. This file should be copied to
spiderLocalDB.pyas a template (see an example). This module must contain a class
spiderDatabase, which inherits from
spiderClasses.SpiderDatabase. This class object must have the following attributes and methods:
|a database name to present to the user, e.g., "the Project Database"|
|the project ID number is used to specify a particular project in the database.|
|another SQL query to fetch project information|
|sets the required attributes.|
|returns 1 or 0 depending on whether it can successfully connect.|
|returns results of SQL statement|
|given an uploadable object, establish a connection and insert data into appropriate places in the external database|
Example: setting up Spire to connect to a MySQL databaseThe Spire distribution contains example code for a tiny project database in MySQL.
You must first:
testmysql.py, which creates a table in the specified database and inserts some test data in it. Usage:
testmysql.py -u user -p password -d database -t tableAll arguments are optional. If you type just
testmysql.pyit will use the following default values:
database = "test_spire"
table = "projects"
user = "" i.e., anonymous login must be enabled for mysql
password = ""
testmysql.pywill create the table
projectsin the database
test_spireand put some values in the table.
CHECK THE FIELD NAMES Data loaded into table 'projects': +------------+-----------+------+--------------+----------+ | project_id | pixelsize | kev | project_file | data_ext | +------------+-----------+------+--------------+----------+ | 149 | 4.78 | 100 | proj149 | xyz | +------------+-----------+------+--------------+----------+"database", "user", and "password" must be set up for your MySQL database.
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,
and run Spire. Start a new project, enter project number 149. It should fetch data
from the MySQL database.