VTK
dox/IO/SQL/vtkSQLDatabaseSchema.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 Program:   Visualization Toolkit
00004 Module:    vtkSQLDatabaseSchema.h
00005 
00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007 All rights reserved.
00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010 This software is distributed WITHOUT ANY WARRANTY; without even
00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012 PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 /*-------------------------------------------------------------------------
00016   Copyright 2008 Sandia Corporation.
00017   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00018   the U.S. Government retains certain rights in this software.
00019 -------------------------------------------------------------------------*/
00045 #ifndef __vtkSQLDatabaseSchema_h
00046 #define __vtkSQLDatabaseSchema_h
00047 
00048 #include "vtkIOSQLModule.h" // For export macro
00049 #include "vtkObject.h"
00050 
00051 #include <cstdarg> // Because one method has a variable list of arguments
00052 
00053 // This is a list of known supported VTK SQL backend classes.
00054 // A particular SQL backend does not have to be listed here to be supported, but
00055 // these macros allow for the specification of SQL backend-specific database schema items.
00056 #define VTK_SQL_ALLBACKENDS      "*" // works for all backends
00057 #define VTK_SQL_MYSQL            "vtkMySQLDatabase"
00058 #define VTK_SQL_POSTGRESQL       "vtkPostgreSQLDatabase"
00059 #define VTK_SQL_SQLITE           "vtkSQLiteDatabase"
00060 
00061 class vtkSQLDatabaseSchemaInternals;
00062 
00063 class VTKIOSQL_EXPORT vtkSQLDatabaseSchema : public vtkObject
00064 {
00065  public:
00066   vtkTypeMacro(vtkSQLDatabaseSchema, vtkObject);
00067   void PrintSelf(ostream& os, vtkIndent indent);
00068   static vtkSQLDatabaseSchema* New();
00069 
00070   //BTX
00072 
00073   enum DatabaseColumnType
00074     {
00075       SERIAL    = 0, // specifying the indices explicitly to prevent bad compiler mishaps
00076       SMALLINT  = 1,
00077       INTEGER   = 2,
00078       BIGINT    = 3,
00079       VARCHAR   = 4,
00080       TEXT      = 5,
00081       REAL      = 6,
00082       DOUBLE    = 7,
00083       BLOB      = 8,
00084       TIME      = 9,
00085       DATE      = 10,
00086       TIMESTAMP = 11
00087     };
00089 
00091 
00092   enum DatabaseIndexType
00093     {
00094       INDEX       = 0, // Non-unique index of values in named columns
00095       UNIQUE      = 1, // Index of values in named columns required to have at most one entry per pair of valid values.
00096       PRIMARY_KEY = 2 // Like UNIQUE but additionally this serves as the primary key for the table to speed up insertions.
00097     };
00099 
00101 
00102   enum DatabaseTriggerType
00103     {
00104       BEFORE_INSERT = 0, // Just before a row is inserted
00105       AFTER_INSERT  = 1,  // Just after a row is inserted
00106       BEFORE_UPDATE = 2, // Just before a row's values are changed
00107       AFTER_UPDATE  = 3,  // Just after a row's values are changed
00108       BEFORE_DELETE = 4, // Just before a row is deleted
00109       AFTER_DELETE  = 5  // Just after a row is deleted
00110     };
00111   //ETX
00113 
00115 
00126   virtual int AddPreamble(
00127     const char* preName, const char* preAction,
00128     const char* preBackend = VTK_SQL_ALLBACKENDS );
00130 
00132   virtual int AddTable( const char* tblName );
00133 
00135 
00137   virtual int AddColumnToTable(
00138     int tblHandle, int colType, const char* colName,
00139     int colSize, const char* colAttribs );
00140   virtual int AddColumnToTable(
00141     const char* tblName, int colType, const char* colName,
00142     int colSize, const char* colAttribs )
00143     {
00144     return this->AddColumnToTable( this->GetTableHandleFromName( tblName ),
00145       colType, colName, colSize, colAttribs );
00146     }
00148 
00150 
00152   virtual int AddIndexToTable(
00153     int tblHandle, int idxType, const char* idxName );
00154   virtual int AddIndexToTable(
00155     const char* tblName, int idxType, const char* idxName )
00156     {
00157     return this->AddIndexToTable( this->GetTableHandleFromName( tblName ),
00158       idxType, idxName );
00159     }
00161 
00163 
00165   virtual int AddColumnToIndex( int tblHandle, int idxHandle, int colHandle );
00166   virtual int AddColumnToIndex(
00167     const char* tblName, const char* idxName, const char* colName )
00168     {
00169     int tblHandle = this->GetTableHandleFromName( tblName );
00170     return this->AddColumnToIndex( tblHandle,
00171       this->GetIndexHandleFromName( tblName, idxName ),
00172       this->GetColumnHandleFromName( tblName, colName ) );
00173     }
00175 
00177 
00181   virtual int AddTriggerToTable(
00182     int tblHandle, int trgType, const char* trgName,
00183     const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS );
00184   virtual int AddTriggerToTable(
00185     const char* tblName, int trgType, const char* trgName,
00186     const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS )
00187     {
00188     return this->AddTriggerToTable( this->GetTableHandleFromName( tblName ),
00189       trgType, trgName, trgAction, trgBackend );
00190     }
00192 
00194 
00200   virtual int AddOptionToTable(
00201     int tblHandle, const char* optStr,
00202     const char* optBackend = VTK_SQL_ALLBACKENDS );
00203   virtual int AddOptionToTable(
00204     const char* tblName, const char* optStr,
00205     const char* optBackend = VTK_SQL_ALLBACKENDS )
00206     {
00207     return this->AddOptionToTable( this->GetTableHandleFromName( tblName ),
00208       optStr, optBackend );
00209     }
00211 
00213   int GetPreambleHandleFromName( const char* preName );
00214 
00216   const char* GetPreambleNameFromHandle( int preHandle );
00217 
00219   const char* GetPreambleActionFromHandle( int preHandle );
00220 
00222   const char* GetPreambleBackendFromHandle( int preHandle );
00223 
00225   int GetTableHandleFromName( const char* tblName );
00226 
00228   const char* GetTableNameFromHandle( int tblHandle );
00229 
00232   int GetIndexHandleFromName( const char* tblName, const char* idxName );
00233 
00235   const char* GetIndexNameFromHandle( int tblHandle, int idxHandle );
00236 
00238   int GetIndexTypeFromHandle( int tblHandle, int idxHandle );
00239 
00241 
00243   const char* GetIndexColumnNameFromHandle(
00244     int tblHandle, int idxHandle, int cnmHandle );
00246 
00249   int GetColumnHandleFromName( const char* tblName, const char* colName );
00250 
00253   const char* GetColumnNameFromHandle( int tblHandle, int colHandle );
00254 
00257   int GetColumnTypeFromHandle( int tblHandle, int colHandle );
00258 
00261   int GetColumnSizeFromHandle( int tblHandle, int colHandle );
00262 
00265   const char* GetColumnAttributesFromHandle( int tblHandle, int colHandle );
00266 
00269   int GetTriggerHandleFromName( const char* tblName, const char* trgName );
00270 
00273   const char* GetTriggerNameFromHandle( int tblHandle, int trgHandle );
00274 
00277   int GetTriggerTypeFromHandle( int tblHandle, int trgHandle );
00278 
00281   const char* GetTriggerActionFromHandle( int tblHandle, int trgHandle );
00282 
00285   const char* GetTriggerBackendFromHandle( int tblHandle, int trgHandle );
00286 
00289   const char* GetOptionTextFromHandle( int tblHandle, int optHandle );
00290 
00293   const char* GetOptionBackendFromHandle( int tblHandle, int trgHandle );
00294 
00296   void Reset();
00297 
00299   int GetNumberOfPreambles();
00300 
00302   int GetNumberOfTables();
00303 
00305   int GetNumberOfColumnsInTable( int tblHandle );
00306 
00308   int GetNumberOfIndicesInTable( int tblHandle );
00309 
00312   int GetNumberOfColumnNamesInIndex( int tblHandle, int idxHandle );
00313 
00315   int GetNumberOfTriggersInTable( int tblHandle );
00316 
00318   int GetNumberOfOptionsInTable( int tblHandle );
00319 
00321 
00322   vtkSetStringMacro(Name);
00323   vtkGetStringMacro(Name);
00325 
00326   //BTX
00327   // Tokens passed to AddTable to indicate the type of data that follows. Random integers chosen to prevent mishaps.
00328   enum VarargTokens
00329     {
00330       COLUMN_TOKEN       = 58,
00331       INDEX_TOKEN        = 63,
00332       INDEX_COLUMN_TOKEN = 65,
00333       END_INDEX_TOKEN    = 75,
00334       TRIGGER_TOKEN      = 81,
00335       OPTION_TOKEN       = 86,
00336       END_TABLE_TOKEN    = 99
00337     };
00338 
00340 
00365   int AddTableMultipleArguments( const char* tblName, ... );
00366   //ETX
00368 
00369  protected:
00370   vtkSQLDatabaseSchema();
00371   ~vtkSQLDatabaseSchema();
00372 
00373   char* Name;
00374 //BTX
00375   class vtkSQLDatabaseSchemaInternals* Internals;
00376 //ETX
00377 
00378  private:
00379   vtkSQLDatabaseSchema(const vtkSQLDatabaseSchema &); // Not implemented.
00380   void operator=(const vtkSQLDatabaseSchema &); // Not implemented.
00381 };
00382 
00383 #endif // __vtkSQLDatabaseSchema_h