FreeMat: vtkSQLDatabase

FreeMat

- Main Page
- Related Pages

vtkSQLDatabase

Section: Visualization Toolkit IO Classes

# Usage

Abstract base class for all SQL database connection classes. Manages a connection to the database, and is responsible for creating instances of the associated vtkSQLQuery objects associated with this class in order to perform execute queries on the database. To allow connections to a new type of database, create both a subclass of this class and vtkSQLQuery, and implement the required functions:

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

# Methods

The class vtkSQLDatabase has several methods that can be used. They are listed below. Note that the documentation is translated automatically from the VTK sources, and may not be completely intelligible. When in doubt, consult the VTK website. In the methods listed below, `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`
  - 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.
- `bool = obj.EffectSchema (vtkSQLDatabaseSchema , bool dropIfExistsfalse)` - Effect a database schema.