iNTERFACEWARE Products Manual > Installing and Using Chameleon > Using Python Scripting > Chameleon Python API > Environment Variable > Working With Any Database |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
From the environment variable, you can use the get_database() function to connect to any database that is supported by Chameleon:
This function returns a database object that enables you to query a database and obtain data from it.
The four parameters that the get_database() function requires are all strings. The only parameter that is not self-explanatory is the DatabaseType parameter. The table below lists the possible values for this parameter and when you should use each one.
For a simple example of how to use get_database(), suppose that you have a MySQL database named patient_info that contains a table named addresses. This table contains two columns: PatientName, which is the surname of a patient, and PatientAddress, which is the patient's address. Now, suppose that your Chameleon VMD file contains a table named Patient that contains three columns:
To populate the Address field of this table, you must modify your VMD file to query the patient_info database. To do this:
The Segment Inbound script retrieves the patient address from the MySQL database and assigns it to a Python global variable named Address. (It assumes that there is only one database entry that matches; if more than one match is found, it chooses the first match.) The Table Inbound script then sets the value of the Address field of the Patient table to be the of the Address global variable.
|