Skip to content

Commit

Permalink
Support table options for CREATE TABLE.
Browse files Browse the repository at this point in the history
This allows one to create MySQL tables with the
ENGINE=InnoDB option so that transactions will be
honored. The default MyISAM storage engine does
not honor transactions.
  • Loading branch information
drone2537 committed Jul 10, 2010
1 parent 023c867 commit 9479637
Show file tree
Hide file tree
Showing 4 changed files with 332 additions and 219 deletions.
19 changes: 19 additions & 0 deletions IO/vtkSQLDatabase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,25 @@ bool vtkSQLDatabase::EffectSchema( vtkSQLDatabaseSchema* schema, bool dropIfExis
}
queryStr += ")";

// Add options to the end of the CREATE TABLE statement
int numOpt = schema->GetNumberOfOptionsInTable( tblHandle );
if ( numOpt < 0 )
{
query->RollbackTransaction();
query->Delete();
return false;
}
for ( int optHandle = 0; optHandle < numOpt; ++ optHandle )
{
vtkStdString optBackend = schema->GetOptionBackendFromHandle( tblHandle, optHandle );
if ( strcmp( optBackend, VTK_SQL_ALLBACKENDS ) && strcmp( optBackend, this->GetClassName() ) )
{
continue;
}
queryStr += " ";
queryStr += schema->GetOptionTextFromHandle( tblHandle, optHandle );
}

// Execute the CREATE TABLE query
query->SetQuery( queryStr );
if ( ! query->Execute() )
Expand Down
46 changes: 23 additions & 23 deletions IO/vtkSQLDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ PURPOSE. See the above copyright notice for more information.
//
// The subclass should also provide API to set connection parameters.
//
// This class also provides the function EffectSchema to transform a
// 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
// on the database classes and for the SQLite example. Thanks to David Thompson
// and Philippe Pebay from Sandia National Laboratories for implementing
// this class.
//
Expand All @@ -61,7 +61,7 @@ class vtkStringArray;

// This is a list of features that each database may or may not
// support. As yet (April 2008) we don't provide access to most of
// them.
// them.
#define VTK_SQL_FEATURE_TRANSACTIONS 1000
#define VTK_SQL_FEATURE_QUERY_SIZE 1001
#define VTK_SQL_FEATURE_BLOB 1002
Expand All @@ -73,7 +73,7 @@ class vtkStringArray;
#define VTK_SQL_FEATURE_BATCH_OPERATIONS 1008
#define VTK_SQL_FEATURE_TRIGGERS 1009 // supported

// Default size for columns types which require a size to be specified
// Default size for columns types which require a size to be specified
// (i.e., VARCHAR), when no size has been specified
#define VTK_SQL_DEFAULT_COLUMN_SIZE 32

Expand All @@ -93,43 +93,43 @@ class VTK_IO_EXPORT vtkSQLDatabase : public vtkObject
// Description:
// Close the connection to the database.
virtual void Close() = 0;

// Description:
// Return whether the database has an open connection.
virtual bool IsOpen() = 0;

// Description:
// Return an empty query on this database.
virtual vtkSQLQuery* GetQueryInstance() = 0;

// Description:
// Did the last operation generate an error
virtual bool HasError() = 0;

// Description:
// 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...
virtual const char* GetLastErrorText() = 0;

// Description:
// Get the type of the database (e.g. mysql, psql,..).
virtual char* GetDatabaseType() = 0;

// Description:
// Get the list of tables from the database.
virtual vtkStringArray* GetTables() = 0;

// Description:
// Get the list of fields for a particular table.
virtual vtkStringArray* GetRecord(const char *table) = 0;

// Description:
// Return whether a feature is supported by the database.
virtual bool IsSupported(int vtkNotUsed(feature)) { return false; }

// Description:
// Get the URL of the database.
virtual vtkStdString GetURL() = 0;
Expand All @@ -141,47 +141,47 @@ class VTK_IO_EXPORT vtkSQLDatabase : public vtkObject
// It must be overwritten for those SQL backends which allow such
// preambles such as, e.g., MySQL.
virtual vtkStdString GetTablePreamble( bool ) { return vtkStdString(); }

// Description:
// 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
// It must be overwritten for those SQL backends which have a different
// syntax such as, e.g., MySQL.
virtual vtkStdString GetColumnSpecification( vtkSQLDatabaseSchema* schema,
int tblHandle,
int colHandle );

// Description:
// Return the SQL string with the syntax to create an index inside a
// "CREATE TABLE" SQL statement.
// NB1: this method implements the following minimally-portable syntax:
// <index type> [<index name>] (<column name 1>,... )
// It must be overwritten for those SQL backends which have a different
// It must be overwritten for those SQL backends which have a different
// syntax such as, e.g., MySQL.
// NB2: this method does not assume that INDEX creation is supported
// within a CREATE TABLE statement. Therefore, should such an INDEX arise
// in the schema, a CREATE INDEX statement is returned and skipped is
// in the schema, a CREATE INDEX statement is returned and skipped is
// set to true. Otherwise, skipped will always be returned false.
virtual vtkStdString GetIndexSpecification( vtkSQLDatabaseSchema* schema,
int tblHandle,
int idxHandle,
bool& skipped );

// Description:
// 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
// It must be overwritten for those SQL backends which have a different
// syntax such as, e.g., PostgreSQL.
virtual vtkStdString GetTriggerSpecification( vtkSQLDatabaseSchema* schema,
int tblHandle,
int trgHandle );

// Description:
// Create a the proper subclass given a URL.
// The URL format for SQL databases is a true URL of the form:
Expand Down Expand Up @@ -209,17 +209,17 @@ class VTK_IO_EXPORT vtkSQLDatabase : public vtkObject
// Description:
// Stores the database class pointer as an information key. This is currently
// used to store database pointers as part of 'data on demand' data objects.
// For example: The application may have a table/tree/whatever of documents,
// the data structure is storing the meta-data but not the full text. Further
// down the pipeline algorithms or views may want to retrieve additional
// For example: The application may have a table/tree/whatever of documents,
// the data structure is storing the meta-data but not the full text. Further
// down the pipeline algorithms or views may want to retrieve additional
// information (full text)for specific documents.
static vtkInformationObjectBaseKey* DATABASE();

//BTX
protected:
vtkSQLDatabase();
~vtkSQLDatabase();

// Description:
// Subclasses should override this method to determine connection paramters
// given the URL. This is called by CreateFromURL() to initialize the instance.
Expand Down
Loading

0 comments on commit 9479637

Please sign in to comment.