Commit 3a429910 authored by Philippe Pebay's avatar Philippe Pebay
Browse files

ENH: implemented support for column size.

     NB: 3 cases may occur: size unused, allowed or mandatory. In the
     latter case, if no size is provided, then a default value (#-defined)
     is assigned.
ENH: added minimal support for table preambles.
ENH: moved the GetColumnType methods to the internals of ExecuteSchema.
     This results in a smaller API, at the expense of a little flexibility.
ENH: refined support for various types at the concrete class level
parent 02206078
......@@ -31,7 +31,7 @@
#define VTK_MYSQL_DEFAULT_PORT 3306
vtkCxxRevisionMacro(vtkMySQLDatabase, "1.12");
vtkCxxRevisionMacro(vtkMySQLDatabase, "1.13");
vtkStandardNewMacro(vtkMySQLDatabase);
// ----------------------------------------------------------------------
......@@ -75,6 +75,19 @@ vtkMySQLDatabase::~vtkMySQLDatabase()
this->Tables->UnRegister(this);
}
// ----------------------------------------------------------------------
void vtkMySQLDatabase::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "DatabaseType: " << (this->DatabaseType ? this->DatabaseType : "NULL") << endl;
os << indent << "HostName: " << (this->HostName ? this->HostName : "NULL") << endl;
os << indent << "UserName: " << (this->UserName ? this->UserName : "NULL") << endl;
os << indent << "Password: " << (this->Password ? this->Password : "NULL") << endl;
os << indent << "DatabaseName: " << (this->DatabaseName ? this->DatabaseName : "NULL") << endl;
os << indent << "ServerPort: " << this->ServerPort << endl;
os << indent << "ConnectOptions: " << (this->ConnectOptions ? this->ConnectOptions : "NULL") << endl;
}
// ----------------------------------------------------------------------
bool vtkMySQLDatabase::IsSupported(int feature)
{
......@@ -314,9 +327,26 @@ vtkStdString vtkMySQLDatabase::GetColumnSpecification( vtkSQLDatabaseSchema* sch
queryStr += schema->GetColumnNameFromHandle( tblHandle, colHandle );
queryStr += "` ";
// Figure out column type
int colType = schema->GetColumnTypeFromHandle( tblHandle, colHandle );
vtkStdString colTypeStr = 0;
switch ( static_cast<vtkSQLDatabaseSchema::DatabaseColumnType>( colType ) )
{
case vtkSQLDatabaseSchema::SERIAL: colTypeStr = "INT NOT NULL AUTO_INCREMENT";
case vtkSQLDatabaseSchema::SMALLINT: colTypeStr = "SMALLINT";
case vtkSQLDatabaseSchema::INTEGER: colTypeStr = "INT";
case vtkSQLDatabaseSchema::BIGINT: colTypeStr = "BIGINT";
case vtkSQLDatabaseSchema::VARCHAR: colTypeStr = "VARCHAR";
case vtkSQLDatabaseSchema::TEXT: colTypeStr = "VARCHAR";
case vtkSQLDatabaseSchema::REAL: colTypeStr = "FLOAT";
case vtkSQLDatabaseSchema::DOUBLE: colTypeStr = "DOUBLE PRECISION";
case vtkSQLDatabaseSchema::BLOB: colTypeStr = "BLOB";
case vtkSQLDatabaseSchema::TIME: colTypeStr = "TIME";
case vtkSQLDatabaseSchema::DATE: colTypeStr = "DATE";
case vtkSQLDatabaseSchema::TIMESTAMP: colTypeStr = "TIMESTAMP";
}
vtkStdString colTypeStr = this->GetColumnTypeString( colType );
if ( colTypeStr )
{
queryStr += " ";
......@@ -328,6 +358,47 @@ vtkStdString vtkMySQLDatabase::GetColumnSpecification( vtkSQLDatabaseSchema* sch
return 0;
}
// Decide whether size is allowed, required, or unused
int colSizeType = 0;
switch ( static_cast<vtkSQLDatabaseSchema::DatabaseColumnType>( colType ) )
{
case vtkSQLDatabaseSchema::SERIAL: colSizeType = 0;
case vtkSQLDatabaseSchema::SMALLINT: colSizeType = 1;
case vtkSQLDatabaseSchema::INTEGER: colSizeType = 1;
case vtkSQLDatabaseSchema::BIGINT: colSizeType = 1;
case vtkSQLDatabaseSchema::VARCHAR: colSizeType = -1;
case vtkSQLDatabaseSchema::TEXT: colSizeType = -1;
case vtkSQLDatabaseSchema::REAL: colSizeType = 1;
case vtkSQLDatabaseSchema::DOUBLE: colSizeType = 1;
case vtkSQLDatabaseSchema::BLOB: colSizeType = 1;
case vtkSQLDatabaseSchema::TIME: colSizeType = 0;
case vtkSQLDatabaseSchema::DATE: colSizeType = 0;
case vtkSQLDatabaseSchema::TIMESTAMP: colSizeType = 0;
}
// Specify size if allowed or required
if ( colSizeType )
{
int colSize = schema->GetColumnSizeFromHandle( tblHandle, colHandle );
// IF size is provided but absurd,
// OR, if size is required but not provided OR absurd,
// THEN assign the default size.
if ( ( colSize < 0 ) || ( colSizeType == -1 && colSize < 1 ) )
{
colSize = VTK_SQL_DEFAULT_COLUMN_SIZE;
}
// At this point, we have either a valid size if required, or a possibly null valid size
// if not required. Thus, skip sizing in the latter case.
if ( colSize < 0 )
{
queryStr += "(";
queryStr += colSize;
queryStr += ")";
}
}
vtkStdString attStr = schema->GetColumnAttributesFromHandle( tblHandle, colHandle );
if ( attStr )
{
......@@ -392,38 +463,3 @@ vtkStdString vtkMySQLDatabase::GetIndexSpecification( vtkSQLDatabaseSchema* sche
return queryStr;
}
// ----------------------------------------------------------------------
vtkStdString vtkMySQLDatabase::GetColumnTypeString( int colType )
{
switch ( static_cast<vtkSQLDatabaseSchema::DatabaseColumnType>( colType ) )
{
case vtkSQLDatabaseSchema::SERIAL: return "INT NOT NULL AUTO_INCREMENT";
case vtkSQLDatabaseSchema::SMALLINT: return "SMALLINT";
case vtkSQLDatabaseSchema::INTEGER: return "INT";
case vtkSQLDatabaseSchema::BIGINT: return "BIGINT";
case vtkSQLDatabaseSchema::VARCHAR: return "VARCHAR";
case vtkSQLDatabaseSchema::TEXT: return "TEXT";
case vtkSQLDatabaseSchema::REAL: return "DOUBLE";
case vtkSQLDatabaseSchema::DOUBLE: return "DOUBLE PRECISION";
case vtkSQLDatabaseSchema::BLOB: return "BLOB";
case vtkSQLDatabaseSchema::TIME: return "TIME";
case vtkSQLDatabaseSchema::DATE: return "DATE";
case vtkSQLDatabaseSchema::TIMESTAMP: return "TIMESTAMP";
}
return 0;
}
// ----------------------------------------------------------------------
void vtkMySQLDatabase::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "DatabaseType: " << (this->DatabaseType ? this->DatabaseType : "NULL") << endl;
os << indent << "HostName: " << (this->HostName ? this->HostName : "NULL") << endl;
os << indent << "UserName: " << (this->UserName ? this->UserName : "NULL") << endl;
os << indent << "Password: " << (this->Password ? this->Password : "NULL") << endl;
os << indent << "DatabaseName: " << (this->DatabaseName ? this->DatabaseName : "NULL") << endl;
os << indent << "ServerPort: " << this->ServerPort << endl;
os << indent << "ConnectOptions: " << (this->ConnectOptions ? this->ConnectOptions : "NULL") << endl;
}
......@@ -131,6 +131,13 @@ public:
// Get the URL of the database.
virtual vtkStdString GetURL();
// Description:
// Return the SQL string with the syntax of the preamble following a
// "CREATE TABLE" SQL statement.
// NB: this method implements the MySQL-specific IF NOT EXISTS syntax,
// used when b = false.
virtual vtkStdString GetTablePreamble( bool b ) { return b ? 0 :" IF NOT EXISTS"; }
// Description:
// Return the SQL string with the syntax to create a column inside a
// "CREATE TABLE" SQL statement.
......@@ -151,16 +158,12 @@ public:
virtual vtkStdString GetIndexSpecification( vtkSQLDatabaseSchema* schema,
int tblHandle,
int idxHandle );
// Description:
// For each column type indexed in vtkSQLDatabaseSchema, return the
// corresponding MySQL-specific string.
virtual vtkStdString GetColumnTypeString( int colType );
private:
protected:
vtkMySQLDatabase();
~vtkMySQLDatabase();
private:
// We want this to be private, a user of this class
// should not be setting this for any reason
vtkSetStringMacro(DatabaseType);
......
......@@ -31,7 +31,7 @@ PURPOSE. See the above copyright notice for more information.
#include <pqxx/pqxx>
vtkStandardNewMacro(vtkPostgreSQLDatabase);
vtkCxxRevisionMacro(vtkPostgreSQLDatabase, "1.12");
vtkCxxRevisionMacro(vtkPostgreSQLDatabase, "1.13");
// ----------------------------------------------------------------------
vtkPostgreSQLDatabase::vtkPostgreSQLDatabase()
......@@ -87,6 +87,93 @@ void vtkPostgreSQLDatabase::PrintSelf(ostream &os, vtkIndent indent)
os << indent << "ConnectOptions: " << (this->ConnectOptions ? this->ConnectOptions : "NULL") << endl;
}
// ----------------------------------------------------------------------
vtkStdString vtkPostgreSQLDatabase::GetColumnSpecification( vtkSQLDatabaseSchema* schema,
int tblHandle,
int colHandle )
{
vtkStdString queryStr = schema->GetColumnNameFromHandle( tblHandle, colHandle );
// Figure out column type
int colType = schema->GetColumnTypeFromHandle( tblHandle, colHandle );
vtkStdString colTypeStr = 0;
switch ( static_cast<vtkSQLDatabaseSchema::DatabaseColumnType>( colType ) )
{
case vtkSQLDatabaseSchema::SERIAL: colTypeStr = "SERIAL";
case vtkSQLDatabaseSchema::SMALLINT: colTypeStr = "SMALLINT";
case vtkSQLDatabaseSchema::INTEGER: colTypeStr = "INTEGER";
case vtkSQLDatabaseSchema::BIGINT: colTypeStr = "BIGINT";
case vtkSQLDatabaseSchema::VARCHAR: colTypeStr = "VARCHAR";
case vtkSQLDatabaseSchema::TEXT: colTypeStr = "TEXT";
case vtkSQLDatabaseSchema::REAL: colTypeStr = "REAL";
case vtkSQLDatabaseSchema::DOUBLE: colTypeStr = "DOUBLE PRECISION";
case vtkSQLDatabaseSchema::BLOB: colTypeStr = "BYTEA";
case vtkSQLDatabaseSchema::TIME: colTypeStr = "TIME";
case vtkSQLDatabaseSchema::DATE: colTypeStr = "DATE";
case vtkSQLDatabaseSchema::TIMESTAMP: colTypeStr = "TIMESTAMP WITH TIME ZONE";
}
if ( colTypeStr )
{
queryStr += " ";
queryStr += colTypeStr;
}
else // if ( colTypeStr )
{
vtkGenericWarningMacro( "Unable to get column specification: unsupported data type " << colType );
return 0;
}
// Decide whether size is allowed, required, or unused
int colSizeType = 0;
switch ( static_cast<vtkSQLDatabaseSchema::DatabaseColumnType>( colType ) )
{
case vtkSQLDatabaseSchema::SERIAL: colSizeType = 0;
case vtkSQLDatabaseSchema::SMALLINT: colSizeType = 1;
case vtkSQLDatabaseSchema::INTEGER: colSizeType = 1;
case vtkSQLDatabaseSchema::BIGINT: colSizeType = 1;
case vtkSQLDatabaseSchema::VARCHAR: colSizeType = -1;
case vtkSQLDatabaseSchema::TEXT: colSizeType = 0;
case vtkSQLDatabaseSchema::REAL: colSizeType = 1;
case vtkSQLDatabaseSchema::DOUBLE: colSizeType = 1;
case vtkSQLDatabaseSchema::BLOB: colSizeType = 0;
case vtkSQLDatabaseSchema::TIME: colSizeType = 0;
case vtkSQLDatabaseSchema::DATE: colSizeType = 0;
case vtkSQLDatabaseSchema::TIMESTAMP: colSizeType = 0;
}
// Specify size if allowed or required
if ( colSizeType )
{
int colSize = schema->GetColumnSizeFromHandle( tblHandle, colHandle );
// IF size is provided but absurd,
// OR, if size is required but not provided OR absurd,
// THEN assign the default size.
if ( ( colSize < 0 ) || ( colSizeType == -1 && colSize < 1 ) )
{
colSize = VTK_SQL_DEFAULT_COLUMN_SIZE;
}
// At this point, we have either a valid size if required, or a possibly null valid size
// if not required. Thus, skip sizing in the latter case.
if ( colSize < 0 )
{
queryStr += "(";
queryStr += colSize;
queryStr += ")";
}
}
vtkStdString attStr = schema->GetColumnAttributesFromHandle( tblHandle, colHandle );
if ( attStr )
{
queryStr += " ";
queryStr += attStr;
}
return queryStr;
}
// ----------------------------------------------------------------------
bool vtkPostgreSQLDatabase::Open()
{
......@@ -215,28 +302,6 @@ vtkStdString vtkPostgreSQLDatabase::GetURL()
return url;
}
// ----------------------------------------------------------------------
vtkStdString vtkPostgreSQLDatabase::GetColumnTypeString( int colType )
{
switch ( static_cast<vtkSQLDatabaseSchema::DatabaseColumnType>( colType ) )
{
case vtkSQLDatabaseSchema::SERIAL: return "SERIAL";
case vtkSQLDatabaseSchema::SMALLINT: return "SMALLINT";
case vtkSQLDatabaseSchema::INTEGER: return "INTEGER";
case vtkSQLDatabaseSchema::BIGINT: return "BIGINT";
case vtkSQLDatabaseSchema::VARCHAR: return "VARCHAR";
case vtkSQLDatabaseSchema::TEXT: return "TEXT";
case vtkSQLDatabaseSchema::REAL: return "REAL";
case vtkSQLDatabaseSchema::DOUBLE: return "DOUBLE PRECISION";
case vtkSQLDatabaseSchema::BLOB: return "BYTEA";
case vtkSQLDatabaseSchema::TIME: return "TIME";
case vtkSQLDatabaseSchema::DATE: return "DATE";
case vtkSQLDatabaseSchema::TIMESTAMP: return "TIMESTAMP WITH TIME ZONE";
}
return 0;
}
// ----------------------------------------------------------------------
vtkStringArray* vtkPostgreSQLDatabase::GetTables()
{
......
......@@ -131,11 +131,6 @@ public:
// <code>'psql://'[username[':'password]'@']hostname[':'port]'/'database</code> .
virtual vtkStdString GetURL();
// Description:
// For each column type indexed in vtkSQLDatabaseSchema, return the
// corresponding PostgreSQL-specific string.
virtual vtkStdString GetColumnTypeString( int colType );
// Description:
// Get the list of tables from the database
vtkStringArray* GetTables();
......@@ -162,6 +157,15 @@ public:
// Returns true on success and false on failure.
bool DropDatabase( const char* dbName );
// Description:
// Return the SQL string with the syntax to create a column inside a
// "CREATE TABLE" SQL statement.
// NB: this method implements the PostgreSQL-specific syntax:
// <column name> <column type> <column attributes>
virtual vtkStdString GetColumnSpecification( vtkSQLDatabaseSchema* schema,
int tblHandle,
int colHandle );
protected:
vtkPostgreSQLDatabase();
~vtkPostgreSQLDatabase();
......
......@@ -38,7 +38,7 @@ PURPOSE. See the above copyright notice for more information.
#include <vtksys/SystemTools.hxx>
vtkCxxRevisionMacro(vtkSQLDatabase, "1.24");
vtkCxxRevisionMacro(vtkSQLDatabase, "1.25");
// ----------------------------------------------------------------------
vtkSQLDatabase::vtkSQLDatabase()
......@@ -63,9 +63,25 @@ vtkStdString vtkSQLDatabase::GetColumnSpecification( vtkSQLDatabaseSchema* schem
{
vtkStdString queryStr = schema->GetColumnNameFromHandle( tblHandle, colHandle );
// Figure out column type
int colType = schema->GetColumnTypeFromHandle( tblHandle, colHandle );
vtkStdString colTypeStr = this->GetColumnTypeString( colType );
vtkStdString colTypeStr = 0;
switch ( static_cast<vtkSQLDatabaseSchema::DatabaseColumnType>( colType ) )
{
case vtkSQLDatabaseSchema::SERIAL: colTypeStr = 0;
case vtkSQLDatabaseSchema::SMALLINT: colTypeStr = "INTEGER";
case vtkSQLDatabaseSchema::INTEGER: colTypeStr = "INTEGER";
case vtkSQLDatabaseSchema::BIGINT: colTypeStr = "INTEGER";
case vtkSQLDatabaseSchema::VARCHAR: colTypeStr = "VARCHAR";
case vtkSQLDatabaseSchema::TEXT: colTypeStr = "VARCHAR";
case vtkSQLDatabaseSchema::REAL: colTypeStr = "FLOAT";
case vtkSQLDatabaseSchema::DOUBLE: colTypeStr = "DOUBLE";
case vtkSQLDatabaseSchema::BLOB: colTypeStr = 0;
case vtkSQLDatabaseSchema::TIME: colTypeStr = "TIME";
case vtkSQLDatabaseSchema::DATE: colTypeStr = "DATE";
case vtkSQLDatabaseSchema::TIMESTAMP: colTypeStr = "TIMESTAMP";
}
if ( colTypeStr )
{
queryStr += " ";
......@@ -77,6 +93,46 @@ vtkStdString vtkSQLDatabase::GetColumnSpecification( vtkSQLDatabaseSchema* schem
return 0;
}
// Decide whether size is allowed, required, or unused
int colSizeType = 0;
switch ( static_cast<vtkSQLDatabaseSchema::DatabaseColumnType>( colType ) )
{
case vtkSQLDatabaseSchema::SERIAL: colSizeType = 0;
case vtkSQLDatabaseSchema::SMALLINT: colSizeType = 1;
case vtkSQLDatabaseSchema::INTEGER: colSizeType = 1;
case vtkSQLDatabaseSchema::BIGINT: colSizeType = 1;
case vtkSQLDatabaseSchema::VARCHAR: colSizeType = -1;
case vtkSQLDatabaseSchema::TEXT: colSizeType = -1;
case vtkSQLDatabaseSchema::REAL: colSizeType = 1;
case vtkSQLDatabaseSchema::DOUBLE: colSizeType = 1;
case vtkSQLDatabaseSchema::BLOB: colSizeType = 0;
case vtkSQLDatabaseSchema::TIME: colSizeType = 0;
case vtkSQLDatabaseSchema::DATE: colSizeType = 0;
case vtkSQLDatabaseSchema::TIMESTAMP: colSizeType = 0;
}
// Specify size if allowed or required
if ( colSizeType )
{
int colSize = schema->GetColumnSizeFromHandle( tblHandle, colHandle );
// IF size is provided but absurd,
// OR, if size is required but not provided OR absurd,
// THEN assign the default size.
if ( ( colSize < 0 ) || ( colSizeType == -1 && colSize < 1 ) )
{
colSize = VTK_SQL_DEFAULT_COLUMN_SIZE;
}
// At this point, we have either a valid size if required, or a possibly null valid size
// if not required. Thus, skip sizing in the latter case.
if ( colSize < 0 )
{
queryStr += "(";
queryStr += colSize;
queryStr += ")";
}
}
vtkStdString attStr = schema->GetColumnAttributesFromHandle( tblHandle, colHandle );
if ( attStr )
{
......@@ -95,16 +151,17 @@ vtkStdString vtkSQLDatabase::GetIndexSpecification( vtkSQLDatabaseSchema* schema
vtkStdString queryStr = ", ";
int idxType = schema->GetIndexTypeFromHandle( tblHandle, idxHandle );
switch ( idxType )
{
case vtkSQLDatabaseSchema::PRIMARY_KEY:
queryStr += "PRIMARY KEY ";
break;
case vtkSQLDatabaseSchema::UNIQUE: // Not supported by all SQL backends
return 0;
case vtkSQLDatabaseSchema::INDEX:
queryStr += "INDEX ";
case vtkSQLDatabaseSchema::UNIQUE:
queryStr += "UNIQUE ";
break;
case vtkSQLDatabaseSchema::INDEX: // Not supported by all SQL backends
return 0;
default:
return 0;
}
......@@ -138,28 +195,6 @@ vtkStdString vtkSQLDatabase::GetIndexSpecification( vtkSQLDatabaseSchema* schema
return queryStr;
}
// ----------------------------------------------------------------------
vtkStdString vtkSQLDatabase::GetColumnTypeString( int colType )
{
switch ( static_cast<vtkSQLDatabaseSchema::DatabaseColumnType>( colType ) )
{
case vtkSQLDatabaseSchema::SERIAL: return 0;
case vtkSQLDatabaseSchema::SMALLINT: return "INTEGER";
case vtkSQLDatabaseSchema::INTEGER: return "INTEGER";
case vtkSQLDatabaseSchema::BIGINT: return "INTEGER";
case vtkSQLDatabaseSchema::VARCHAR: return "VARCHAR";
case vtkSQLDatabaseSchema::TEXT: return 0;
case vtkSQLDatabaseSchema::REAL: return "DOUBLE";
case vtkSQLDatabaseSchema::DOUBLE: return "DOUBLE";
case vtkSQLDatabaseSchema::BLOB: return 0;
case vtkSQLDatabaseSchema::TIME: return "TIME";
case vtkSQLDatabaseSchema::DATE: return "DATE";
case vtkSQLDatabaseSchema::TIMESTAMP: return "TIMESTAMP";
}
return 0;
}
// ----------------------------------------------------------------------
vtkSQLDatabase* vtkSQLDatabase::CreateFromURL( const char* URL )
{
......@@ -235,7 +270,7 @@ vtkSQLDatabase* vtkSQLDatabase::CreateFromURL( const char* URL )
}
// ----------------------------------------------------------------------
bool vtkSQLDatabase::EffectSchema( vtkSQLDatabaseSchema* schema, bool vtkNotUsed(dropIfExists) )
bool vtkSQLDatabase::EffectSchema( vtkSQLDatabaseSchema* schema, bool dropIfExists )
{
if ( ! this->IsOpen() )
{
......@@ -258,6 +293,7 @@ bool vtkSQLDatabase::EffectSchema( vtkSQLDatabaseSchema* schema, bool vtkNotUsed
// Construct the query string for this table
vtkStdString queryStr( "CREATE TABLE " );
queryStr += schema->GetTableNameFromHandle( tblHandle );
queryStr += this->GetTablePreamble( dropIfExists );
queryStr += " (";
// Loop over all columns of the current table
......@@ -340,3 +376,4 @@ bool vtkSQLDatabase::EffectSchema( vtkSQLDatabaseSchema* schema, bool vtkNotUsed
return true;
}
......@@ -71,6 +71,10 @@ class vtkStringArray;
#define VTK_SQL_FEATURE_BATCH_OPERATIONS 1008
#define VTK_SQL_FEATURE_TRIGGERS 1009
// 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
class VTK_IO_EXPORT vtkSQLDatabase : public vtkObject
{
public:
......@@ -127,6 +131,14 @@ class VTK_IO_EXPORT vtkSQLDatabase : public vtkObject
// Get the URL of the database.
virtual vtkStdString GetURL() = 0;
// Description:
// Return the SQL string with the syntax of the preamble following a
// "CREATE TABLE" SQL statement.
// NB: by default, this method returns an empty string.
// It must be overwritten for those SQL backends which allow such
// preambles such as, e.g., MySQL.
virtual vtkStdString GetTablePreamble( bool ) { return 0; }
// Description:
// Return the SQL string with the syntax to create a column inside a
// "CREATE TABLE" SQL statement.
......@@ -149,13 +161,6 @@ class VTK_IO_EXPORT vtkSQLDatabase : public vtkObject
int tblHandle,
int idxHandle );
// Description:
// For each column type indexed in vtkSQLDatabaseSchema, return the
// corresponding SQL string.
// NB: a minimal set of common SQL types is provided; the backend-specific
// GetColumnTypeString functions allow for more types.
virtual vtkStdString GetColumnTypeString( int colType );
// Description:
// Create a the proper subclass given a URL.
// The URL format for SQL databases is a true URL of the form:
......
......@@ -28,7 +28,7 @@ PURPOSE. See the above copyright notice for more information.
#include <vtkstd/vector>
// ----------------------------------------------------------------------
vtkCxxRevisionMacro(vtkSQLDatabaseSchema, "1.16");
vtkCxxRevisionMacro(vtkSQLDatabaseSchema, "1.17");
vtkStandardNewMacro(vtkSQLDatabaseSchema);
// ----------------------------------------------------------------------
......@@ -394,6 +394,25 @@ int vtkSQLDatabaseSchema::GetColumnTypeFromHandle( int tblHandle,
return static_cast<int>( this->Internals->Tables[tblHandle].Columns[colHandle].Type );
}
// ----------------------------------------------------------------------
int vtkSQLDatabaseSchema::GetColumnSizeFromHandle( int tblHandle,
int colHandle )
{
if ( tblHandle < 0 || tblHandle >= this->GetNumberOfTables() )
{
vtkErrorMacro( "Cannot get size of a column in non-existent table " << tblHandle );
return -1;
}
if ( colHandle < 0 || colHandle >= static_cast<int>( this->Internals->Tables[tblHandle].Columns.size() ) )
{
vtkErrorMacro( "Cannot get size of non-existent column " << colHandle << " in table " << tblHandle );
return -1;
}
return static_cast<int>( this->Internals->Tables[tblHandle].Columns[colHandle].Size );
}
// ----------------------------------------------------------------------
const char* vtkSQLDatabaseSchema::GetColumnAttributesFromHandle( int tblHandle,
int colHandle )
......
......@@ -193,6 +193,11 @@ class VTK_IO_EXPORT vtkSQLDatabaseSchema : public vtkObject
int GetColumnTypeFromHandle( int tblHandle,
int colHandle );
// Description:
// Given the handles of a table and a column, get the size of the column.
int GetColumnSizeFromHandle( int tblHandle,
int colHandle );
// Description:
// Given the handles of a table and a column, get the attributes of the column.
const char* GetColumnAttributesFromHandle( int tblHandle,
......
......@@ -29,7 +29,7 @@
#include <vtksqlite/vtk_sqlite3.h>
vtkStandardNewMacro(vtkSQLiteDatabase);
vtkCxxRevisionMacro(vtkSQLiteDatabase, "1.9");
vtkCxxRevisionMacro(vtkSQLiteDatabase, "1.10");
// ----------------------------------------------------------------------
vtkSQLiteDatabase::vtkSQLiteDatabase()
......@@ -59,6 +59,112 @@ vtkSQLiteDatabase::~vtkSQLiteDatabase()
}
}
// ----------------------------------------------------------------------
void vtkSQLiteDatabase::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "SQLiteInstance: ";
if (this->SQLiteInstance)
{
os << this->SQLiteInstance << "\n";
}
else
{
os << "(null)" << "\n";
}
os << indent << "DatabaseType: "
<< (this->DatabaseType ? this->DatabaseType : "NULL") << endl;
os << indent << "DatabaseFileName: "
<< (this->DatabaseFileName ? this->DatabaseFileName : "NULL") << endl;
}
// ----------------------------------------------------------------------
vtkStdString vtkSQLiteDatabase::GetColumnSpecification( vtkSQLDatabaseSchema* schema,
int tblHandle,
int colHandle )
{