Section: Visualization Toolkit IO Classes
Open() - open the database connection, if possible. Close() - close the connection. GetQueryInstance() - create and return an instance of the vtkSQLQuery subclass associated with the database type.
The subclass should also provide API to set connection parameters.
This class also provides the function EffectSchema to transform a database schema into a SQL database.
.SECTION Thanks Thanks to Andrew Wilson from Sandia National Laboratories for his work on the database classes and for the SQLite example. Thanks to David Thompson and Philippe Pebay from Sandia National Laboratories for implementing this class.
To create an instance of class vtkSQLDatabase, simply invoke its constructor as follows
obj = vtkSQLDatabase
obj
is an instance of the vtkSQLDatabase class.
string = obj.GetClassName ()
int = obj.IsA (string name)
vtkSQLDatabase = obj.NewInstance ()
vtkSQLDatabase = obj.SafeDownCast (vtkObject o)
bool = obj.Open (string password)
- Open a new connection to the database.
You need to set up any database parameters before calling this function.
For database connections that do not require a password, pass an empty string.
Returns true is the database was opened sucessfully, and false otherwise.
obj.Close ()
- Close the connection to the database.
bool = obj.IsOpen ()
- Return whether the database has an open connection.
vtkSQLQuery = obj.GetQueryInstance ()
- Return an empty query on this database.
bool = obj.HasError ()
- Did the last operation generate an error
string = obj.GetLastErrorText ()
- Get the last error text from the database
I'm using const so that people do NOT
use the standard vtkGetStringMacro in their
implementation, because 99% of the time that
will not be the correct thing to do...
string = obj.GetDatabaseType ()
- Get the type of the database (e.g. mysql, psql,..).
vtkStringArray = obj.GetTables ()
- Get the list of tables from the database.
vtkStringArray = obj.GetRecord (string table)
- Get the list of fields for a particular table.
bool = obj.IsSupported (int )
- Get the URL of the database.
vtkStdString = obj.GetURL ()
- Get the URL of the database.
vtkStdString = obj.GetTablePreamble (bool )
- Return the SQL string with the syntax to create a column inside a
"CREATE TABLE" SQL statement.
NB: this method implements the following minimally-portable syntax:
<column name> <column type> <column attributes>
It must be overwritten for those SQL backends which have a different
syntax such as, e.g., MySQL.
vtkStdString = obj.GetColumnSpecification (vtkSQLDatabaseSchema schema, int tblHandle, int colHandle)
- Return the SQL string with the syntax to create a column inside a
"CREATE TABLE" SQL statement.
NB: this method implements the following minimally-portable syntax:
<column name> <column type> <column attributes>
It must be overwritten for those SQL backends which have a different
syntax such as, e.g., MySQL.
vtkStdString = obj.GetTriggerSpecification (vtkSQLDatabaseSchema schema, int tblHandle, int trgHandle)
- Return the SQL string with the syntax to create a trigger using a
"CREATE TRIGGER" SQL statement.
NB1: support is contingent on VTK_FEATURE_TRIGGERS being recognized as
a supported feature. Not all backends (e.g., SQLite) support it.
NB2: this method implements the following minimally-portable syntax:
<trigger name> {BEFORE | AFTER} <event> ON <table name> FOR EACH ROW <trigger action>
It must be overwritten for those SQL backends which have a different
syntax such as, e.g., PostgreSQL.
bool = obj.EffectSchema (vtkSQLDatabaseSchema , bool dropIfExistsfalse)
- Effect a database schema.