VTK
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
vtkSQLDatabaseSchema Class Reference

represent an SQL database schema More...

#include <vtkSQLDatabaseSchema.h>

Inheritance diagram for vtkSQLDatabaseSchema:
Inheritance graph
[legend]
Collaboration diagram for vtkSQLDatabaseSchema:
Collaboration graph
[legend]

List of all members.

Public Types

enum  VarargTokens {
  COLUMN_TOKEN = 58, INDEX_TOKEN = 63, INDEX_COLUMN_TOKEN = 65, END_INDEX_TOKEN = 75,
  TRIGGER_TOKEN = 81, OPTION_TOKEN = 86, END_TABLE_TOKEN = 99
}
typedef vtkObject Superclass
enum  DatabaseColumnType {
  SERIAL = 0, SMALLINT = 1, INTEGER = 2, BIGINT = 3,
  VARCHAR = 4, TEXT = 5, REAL = 6, DOUBLE = 7,
  BLOB = 8, TIME = 9, DATE = 10, TIMESTAMP = 11
}
enum  DatabaseIndexType { INDEX = 0, UNIQUE = 1, PRIMARY_KEY = 2 }
enum  DatabaseTriggerType {
  BEFORE_INSERT = 0, AFTER_INSERT = 1, BEFORE_UPDATE = 2, AFTER_UPDATE = 3,
  BEFORE_DELETE = 4, AFTER_DELETE = 5
}

Public Member Functions

virtual int IsA (const char *type)
vtkSQLDatabaseSchemaNewInstance () const
void PrintSelf (ostream &os, vtkIndent indent)
virtual int AddTable (const char *tblName)
int GetPreambleHandleFromName (const char *preName)
const char * GetPreambleNameFromHandle (int preHandle)
const char * GetPreambleActionFromHandle (int preHandle)
const char * GetPreambleBackendFromHandle (int preHandle)
int GetTableHandleFromName (const char *tblName)
const char * GetTableNameFromHandle (int tblHandle)
int GetIndexHandleFromName (const char *tblName, const char *idxName)
const char * GetIndexNameFromHandle (int tblHandle, int idxHandle)
int GetIndexTypeFromHandle (int tblHandle, int idxHandle)
int GetColumnHandleFromName (const char *tblName, const char *colName)
const char * GetColumnNameFromHandle (int tblHandle, int colHandle)
int GetColumnTypeFromHandle (int tblHandle, int colHandle)
int GetColumnSizeFromHandle (int tblHandle, int colHandle)
const char * GetColumnAttributesFromHandle (int tblHandle, int colHandle)
int GetTriggerHandleFromName (const char *tblName, const char *trgName)
const char * GetTriggerNameFromHandle (int tblHandle, int trgHandle)
int GetTriggerTypeFromHandle (int tblHandle, int trgHandle)
const char * GetTriggerActionFromHandle (int tblHandle, int trgHandle)
const char * GetTriggerBackendFromHandle (int tblHandle, int trgHandle)
const char * GetOptionTextFromHandle (int tblHandle, int optHandle)
const char * GetOptionBackendFromHandle (int tblHandle, int trgHandle)
void Reset ()
int GetNumberOfPreambles ()
int GetNumberOfTables ()
int GetNumberOfColumnsInTable (int tblHandle)
int GetNumberOfIndicesInTable (int tblHandle)
int GetNumberOfColumnNamesInIndex (int tblHandle, int idxHandle)
int GetNumberOfTriggersInTable (int tblHandle)
int GetNumberOfOptionsInTable (int tblHandle)
virtual int AddPreamble (const char *preName, const char *preAction, const char *preBackend=VTK_SQL_ALLBACKENDS)
virtual int AddColumnToTable (int tblHandle, int colType, const char *colName, int colSize, const char *colAttribs)
virtual int AddColumnToTable (const char *tblName, int colType, const char *colName, int colSize, const char *colAttribs)
virtual int AddIndexToTable (int tblHandle, int idxType, const char *idxName)
virtual int AddIndexToTable (const char *tblName, int idxType, const char *idxName)
virtual int AddColumnToIndex (int tblHandle, int idxHandle, int colHandle)
virtual int AddColumnToIndex (const char *tblName, const char *idxName, const char *colName)
virtual int AddTriggerToTable (int tblHandle, int trgType, const char *trgName, const char *trgAction, const char *trgBackend=VTK_SQL_ALLBACKENDS)
virtual int AddTriggerToTable (const char *tblName, int trgType, const char *trgName, const char *trgAction, const char *trgBackend=VTK_SQL_ALLBACKENDS)
virtual int AddOptionToTable (int tblHandle, const char *optStr, const char *optBackend=VTK_SQL_ALLBACKENDS)
virtual int AddOptionToTable (const char *tblName, const char *optStr, const char *optBackend=VTK_SQL_ALLBACKENDS)
const char * GetIndexColumnNameFromHandle (int tblHandle, int idxHandle, int cnmHandle)
virtual void SetName (const char *)
virtual char * GetName ()
int AddTableMultipleArguments (const char *tblName,...)

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkSQLDatabaseSchemaSafeDownCast (vtkObjectBase *o)
static vtkSQLDatabaseSchemaNew ()

Protected Member Functions

virtual vtkObjectBaseNewInstanceInternal () const
 vtkSQLDatabaseSchema ()
 ~vtkSQLDatabaseSchema ()

Protected Attributes

char * Name
class
vtkSQLDatabaseSchemaInternals * 
Internals

Detailed Description

represent an SQL database schema

This class stores the information required to create an SQL database from scratch. Information on each table's columns, indices, and triggers is stored. You may also store an arbitrary number of preamble statements, intended to be executed before any tables are created; this provides a way to create procedures or functions that may be invoked as part of a trigger action. Triggers and table options may be specified differently for each backend database type you wish to support.

Thanks:
Thanks to Philippe Pebay and David Thompson from Sandia National Laboratories for implementing this class.
See also:
vtkSQLDatabase
Tests:
vtkSQLDatabaseSchema (Tests)

Definition at line 63 of file vtkSQLDatabaseSchema.h.


Member Typedef Documentation

Reimplemented from vtkObject.

Definition at line 66 of file vtkSQLDatabaseSchema.h.


Member Enumeration Documentation

Basic data types for database columns

Enumerator:
SERIAL 
SMALLINT 
INTEGER 
BIGINT 
VARCHAR 
TEXT 
REAL 
DOUBLE 
BLOB 
TIME 
DATE 
TIMESTAMP 

Definition at line 73 of file vtkSQLDatabaseSchema.h.

Types of indices that can be generated for database tables

Enumerator:
INDEX 
UNIQUE 
PRIMARY_KEY 

Definition at line 92 of file vtkSQLDatabaseSchema.h.

Events where database triggers can be registered.

Enumerator:
BEFORE_INSERT 
AFTER_INSERT 
BEFORE_UPDATE 
AFTER_UPDATE 
BEFORE_DELETE 
AFTER_DELETE 

Definition at line 102 of file vtkSQLDatabaseSchema.h.

Enumerator:
COLUMN_TOKEN 
INDEX_TOKEN 
INDEX_COLUMN_TOKEN 
END_INDEX_TOKEN 
TRIGGER_TOKEN 
OPTION_TOKEN 
END_TABLE_TOKEN 

Definition at line 328 of file vtkSQLDatabaseSchema.h.


Constructor & Destructor Documentation


Member Function Documentation

static int vtkSQLDatabaseSchema::IsTypeOf ( const char *  name) [static]

Return 1 if this class type is the same type of (or a subclass of) the named class. Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.

Reimplemented from vtkObject.

virtual int vtkSQLDatabaseSchema::IsA ( const char *  name) [virtual]

Return 1 if this class is the same type of (or a subclass of) the named class. Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.

Reimplemented from vtkObject.

Reimplemented from vtkObject.

virtual vtkObjectBase* vtkSQLDatabaseSchema::NewInstanceInternal ( ) const [protected, virtual]

Reimplemented from vtkObject.

Reimplemented from vtkObject.

void vtkSQLDatabaseSchema::PrintSelf ( ostream &  os,
vtkIndent  indent 
) [virtual]

Methods invoked by print to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Reimplemented from vtkObject.

Create an object with Debug turned off, modified time initialized to zero, and reference counting on.

Reimplemented from vtkObject.

virtual int vtkSQLDatabaseSchema::AddPreamble ( const char *  preName,
const char *  preAction,
const char *  preBackend = VTK_SQL_ALLBACKENDS 
) [virtual]

Add a preamble to the schema This can be used, in particular, to create functions and/or load languages in a backend-specific manner. Example usage: vtkSQLDatabaseSchema* schema = vtkSQLDatabaseSchema::New(); schema->SetName( "Example" ); schema->AddPreamble( "dropPLPGSQL", "DROP LANGUAGE IF EXISTS PLPGSQL CASCADE", VTK_SQL_POSTGRESQL ); schema->AddPreamble( "loadPLPGSQL", "CREATE LANGUAGE PLPGSQL", VTK_SQL_POSTGRESQL ); schema->AddPreamble( "createsomefunction", "CREATE OR REPLACE FUNCTION somefunction() RETURNS TRIGGER AS $btable$ " "BEGIN " "INSERT INTO btable (somevalue) VALUES (NEW.somenmbr); " "RETURN NEW; " "END; $btable$ LANGUAGE PLPGSQL", VTK_SQL_POSTGRESQL );

virtual int vtkSQLDatabaseSchema::AddTable ( const char *  tblName) [virtual]

Add a table to the schema

virtual int vtkSQLDatabaseSchema::AddColumnToTable ( int  tblHandle,
int  colType,
const char *  colName,
int  colSize,
const char *  colAttribs 
) [virtual]

Add a column to table. The returned value is a column handle or -1 if an error occurred.

virtual int vtkSQLDatabaseSchema::AddColumnToTable ( const char *  tblName,
int  colType,
const char *  colName,
int  colSize,
const char *  colAttribs 
) [inline, virtual]

Add a column to table. The returned value is a column handle or -1 if an error occurred.

Definition at line 140 of file vtkSQLDatabaseSchema.h.

virtual int vtkSQLDatabaseSchema::AddIndexToTable ( int  tblHandle,
int  idxType,
const char *  idxName 
) [virtual]

Add an index to table. The returned value is an index handle or -1 if an error occurred.

virtual int vtkSQLDatabaseSchema::AddIndexToTable ( const char *  tblName,
int  idxType,
const char *  idxName 
) [inline, virtual]

Add an index to table. The returned value is an index handle or -1 if an error occurred.

Definition at line 154 of file vtkSQLDatabaseSchema.h.

virtual int vtkSQLDatabaseSchema::AddColumnToIndex ( int  tblHandle,
int  idxHandle,
int  colHandle 
) [virtual]

Add a column to a table index. The returned value is an index-column handle or -1 if an error occurred.

virtual int vtkSQLDatabaseSchema::AddColumnToIndex ( const char *  tblName,
const char *  idxName,
const char *  colName 
) [inline, virtual]

Add a column to a table index. The returned value is an index-column handle or -1 if an error occurred.

Definition at line 166 of file vtkSQLDatabaseSchema.h.

virtual int vtkSQLDatabaseSchema::AddTriggerToTable ( int  tblHandle,
int  trgType,
const char *  trgName,
const char *  trgAction,
const char *  trgBackend = VTK_SQL_ALLBACKENDS 
) [virtual]

Add a (possibly backend-specific) trigger action to a table. Triggers must be given unique, non-NULL names as some database backends require them. The returned value is a trigger handle or -1 if an error occurred.

virtual int vtkSQLDatabaseSchema::AddTriggerToTable ( const char *  tblName,
int  trgType,
const char *  trgName,
const char *  trgAction,
const char *  trgBackend = VTK_SQL_ALLBACKENDS 
) [inline, virtual]

Add a (possibly backend-specific) trigger action to a table. Triggers must be given unique, non-NULL names as some database backends require them. The returned value is a trigger handle or -1 if an error occurred.

Definition at line 184 of file vtkSQLDatabaseSchema.h.

virtual int vtkSQLDatabaseSchema::AddOptionToTable ( int  tblHandle,
const char *  optStr,
const char *  optBackend = VTK_SQL_ALLBACKENDS 
) [virtual]

Add (possibly backend-specific) text to the end of a CREATE TABLE (...) statement. This is most useful for specifying storage semantics of tables that are specific to the backend. For example, table options can be used to specify the TABLESPACE of a PostgreSQL table or the ENGINE of a MySQL table. The returned value is an option handle or -1 if an error occurred.

virtual int vtkSQLDatabaseSchema::AddOptionToTable ( const char *  tblName,
const char *  optStr,
const char *  optBackend = VTK_SQL_ALLBACKENDS 
) [inline, virtual]

Add (possibly backend-specific) text to the end of a CREATE TABLE (...) statement. This is most useful for specifying storage semantics of tables that are specific to the backend. For example, table options can be used to specify the TABLESPACE of a PostgreSQL table or the ENGINE of a MySQL table. The returned value is an option handle or -1 if an error occurred.

Definition at line 203 of file vtkSQLDatabaseSchema.h.

Given a preamble name, get its handle.

Given a preamble handle, get its name.

Given a preamble handle, get its action.

Given a preamble handle, get its backend.

Given a table name, get its handle.

Given a table hanlde, get its name.

int vtkSQLDatabaseSchema::GetIndexHandleFromName ( const char *  tblName,
const char *  idxName 
)

Given the names of a table and an index, get the handle of the index in this table.

const char* vtkSQLDatabaseSchema::GetIndexNameFromHandle ( int  tblHandle,
int  idxHandle 
)

Given the handles of a table and an index, get the name of the index.

int vtkSQLDatabaseSchema::GetIndexTypeFromHandle ( int  tblHandle,
int  idxHandle 
)

Given the handles of a table and an index, get the type of the index.

const char* vtkSQLDatabaseSchema::GetIndexColumnNameFromHandle ( int  tblHandle,
int  idxHandle,
int  cnmHandle 
)

Given the handles of a table, an index, and a column name, get the column name.

int vtkSQLDatabaseSchema::GetColumnHandleFromName ( const char *  tblName,
const char *  colName 
)

Given the names of a table and a column, get the handle of the column in this table.

const char* vtkSQLDatabaseSchema::GetColumnNameFromHandle ( int  tblHandle,
int  colHandle 
)

Given the handles of a table and a column, get the name of the column.

int vtkSQLDatabaseSchema::GetColumnTypeFromHandle ( int  tblHandle,
int  colHandle 
)

Given the handles of a table and a column, get the type of the column.

int vtkSQLDatabaseSchema::GetColumnSizeFromHandle ( int  tblHandle,
int  colHandle 
)

Given the handles of a table and a column, get the size of the column.

const char* vtkSQLDatabaseSchema::GetColumnAttributesFromHandle ( int  tblHandle,
int  colHandle 
)

Given the handles of a table and a column, get the attributes of the column.

int vtkSQLDatabaseSchema::GetTriggerHandleFromName ( const char *  tblName,
const char *  trgName 
)

Given the names of a trigger and a table, get the handle of the trigger in this table.

const char* vtkSQLDatabaseSchema::GetTriggerNameFromHandle ( int  tblHandle,
int  trgHandle 
)

Given the handles of a table and a trigger, get the name of the trigger.

Given the handles of a table and a trigger, get the type of the trigger.

const char* vtkSQLDatabaseSchema::GetTriggerActionFromHandle ( int  tblHandle,
int  trgHandle 
)

Given the handles of a table and a trigger, get the action of the trigger.

const char* vtkSQLDatabaseSchema::GetTriggerBackendFromHandle ( int  tblHandle,
int  trgHandle 
)

Given the handles of a table and a trigger, get the backend of the trigger.

const char* vtkSQLDatabaseSchema::GetOptionTextFromHandle ( int  tblHandle,
int  optHandle 
)

Given the handles of a table and one of its options, return the text of the option.

const char* vtkSQLDatabaseSchema::GetOptionBackendFromHandle ( int  tblHandle,
int  trgHandle 
)

Given the handles of a table and one of its options, get the backend of the option.

Reset the schema to its initial, empty state.

Get the number of preambles.

Get the number of tables.

Get the number of columns in a particular table .

Get the number of indices in a particular table .

Get the number of column names associated to a particular index in a particular table .

Get the number of triggers defined for a particular table.

Get the number of options associated with a particular table.

virtual void vtkSQLDatabaseSchema::SetName ( const char *  ) [virtual]

Set/Get the name of the schema.

virtual char* vtkSQLDatabaseSchema::GetName ( ) [virtual]

Set/Get the name of the schema.

int vtkSQLDatabaseSchema::AddTableMultipleArguments ( const char *  tblName,
  ... 
)

An unwrappable but useful routine to construct built-in schema. Example usage: int main() { vtkSQLDatabaseSchema* schema = vtkSQLDatabaseSchema::New(); schema->SetName( "Example" ); schema->AddTableMultipleArguments( "atable", vtkSQLDatabaseSchema::COLUMN_TOKEN, vtkSQLDatabaseSchema::INTEGER, "tablekey", 0, "", vtkSQLDatabaseSchema::COLUMN_TOKEN, vtkSQLDatabaseSchema::VARCHAR, "somename", 11, "NOT NULL", vtkSQLDatabaseSchema::COLUMN_TOKEN, vtkSQLDatabaseSchema::BIGINT, "somenmbr", 17, "DEFAULT 0", vtkSQLDatabaseSchema::INDEX_TOKEN, vtkSQLDatabaseSchema::PRIMARY_KEY, "bigkey", vtkSQLDatabaseSchema::INDEX_COLUMN_TOKEN, "tablekey", vtkSQLDatabaseSchema::END_INDEX_TOKEN, vtkSQLDatabaseSchema::INDEX_TOKEN, vtkSQLDatabaseSchema::UNIQUE, "reverselookup", vtkSQLDatabaseSchema::INDEX_COLUMN_TOKEN, "somename", vtkSQLDatabaseSchema::INDEX_COLUMN_TOKEN, "somenmbr", vtkSQLDatabaseSchema::END_INDEX_TOKEN, vtkSQLDatabaseSchema::TRIGGER_TOKEN, vtkSQLDatabaseSchema::AFTER_INSERT, "InsertTrigger", "DO NOTHING", VTK_SQL_SQLITE, vtkSQLDatabaseSchema::TRIGGER_TOKEN, vtkSQLDatabaseSchema::AFTER_INSERT, "InsertTrigger", "FOR EACH ROW EXECUTE PROCEDURE somefunction ()", VTK_SQL_POSTGRESQL, vtkSQLDatabaseSchema::TRIGGER_TOKEN, vtkSQLDatabaseSchema::AFTER_INSERT, "InsertTrigger", "FOR EACH ROW INSERT INTO btable SET SomeValue = NEW.SomeNmbr", VTK_SQL_MYSQL, vtkSQLDatabaseSchema::END_TABLE_TOKEN ); return 0; }


Member Data Documentation

char* vtkSQLDatabaseSchema::Name [protected]

Definition at line 373 of file vtkSQLDatabaseSchema.h.

class vtkSQLDatabaseSchemaInternals* vtkSQLDatabaseSchema::Internals [protected]

Definition at line 375 of file vtkSQLDatabaseSchema.h.


The documentation for this class was generated from the following file: