00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00037 #ifndef __vtkSQLDatabaseSchema_h
00038 #define __vtkSQLDatabaseSchema_h
00039
00040 #include "vtkObject.h"
00041
00042 #include <cstdarg>
00043
00044
00045
00046
00047 #define VTK_SQL_ALLBACKENDS "*" // works for all backends
00048 #define VTK_SQL_MYSQL "vtkMySQLDatabase"
00049 #define VTK_SQL_POSTGRESQL "vtkPostgreSQLDatabase"
00050 #define VTK_SQL_SQLITE "vtkSQLiteDatabase"
00051
00052 class vtkSQLDatabaseSchemaInternals;
00053
00054 class VTK_IO_EXPORT vtkSQLDatabaseSchema : public vtkObject
00055 {
00056 public:
00057 vtkTypeMacro(vtkSQLDatabaseSchema, vtkObject);
00058 void PrintSelf(ostream& os, vtkIndent indent);
00059 static vtkSQLDatabaseSchema *New();
00060
00061
00063
00064 enum DatabaseColumnType
00065 {
00066 SERIAL = 0,
00067 SMALLINT = 1,
00068 INTEGER = 2,
00069 BIGINT = 3,
00070 VARCHAR = 4,
00071 TEXT = 5,
00072 REAL = 6,
00073 DOUBLE = 7,
00074 BLOB = 8,
00075 TIME = 9,
00076 DATE = 10,
00077 TIMESTAMP = 11
00078 };
00080
00082
00083 enum DatabaseIndexType
00084 {
00085 INDEX = 0,
00086 UNIQUE = 1,
00087 PRIMARY_KEY = 2
00088 };
00090
00092
00093 enum DatabaseTriggerType
00094 {
00095 BEFORE_INSERT = 0,
00096 AFTER_INSERT = 1,
00097 BEFORE_UPDATE = 2,
00098 AFTER_UPDATE = 3,
00099 BEFORE_DELETE = 4,
00100 AFTER_DELETE = 5
00101 };
00102
00104
00117 virtual int AddPreamble( const char* preName,
00118 const char* preAction,
00119 const char* preBackend = VTK_SQL_ALLBACKENDS );
00120
00122 virtual int AddTable( const char* tblName );
00123
00124 virtual int AddColumnToTable( int tblHandle,
00125 int colType,
00126 const char* colName,
00127 int colSize,
00128 const char* colAttribs );
00129
00130 virtual int AddColumnToTable( const char* tblName,
00131 int colType,
00132 const char* colName,
00133 int colSize,
00134 const char* colAttribs )
00135 {
00136 return this->AddColumnToTable( this->GetTableHandleFromName( tblName ),
00137 colType,
00138 colName,
00139 colSize,
00140 colAttribs );
00141 }
00142
00143 virtual int AddIndexToTable( int tblHandle,
00144 int idxType,
00145 const char* idxName );
00146
00147 virtual int AddIndexToTable( const char* tblName,
00148 int idxType,
00149 const char* idxName )
00150 {
00151 return this->AddIndexToTable( this->GetTableHandleFromName( tblName ),
00152 idxType,
00153 idxName );
00154 }
00155
00156 virtual int AddColumnToIndex( int tblHandle,
00157 int idxHandle,
00158 int colHandle );
00159
00160 virtual int AddColumnToIndex( const char* tblName,
00161 const char* idxName,
00162 const char* colName )
00163 {
00164 int tblHandle = this->GetTableHandleFromName( tblName );
00165 return this->AddColumnToIndex( tblHandle,
00166 this->GetIndexHandleFromName( tblName, idxName ),
00167 this->GetColumnHandleFromName( tblName, colName ) );
00168 }
00169
00170 virtual int AddTriggerToTable( int tblHandle,
00171 int trgType,
00172 const char* trgName,
00173 const char* trgAction,
00174 const char* trgBackend = VTK_SQL_ALLBACKENDS );
00175
00176 virtual int AddTriggerToTable( const char* tblName,
00177 int trgType,
00178 const char* trgName,
00179 const char* trgAction,
00180 const char* trgBackend = VTK_SQL_ALLBACKENDS )
00181 {
00182 return this->AddTriggerToTable( this->GetTableHandleFromName( tblName ),
00183 trgType,
00184 trgName,
00185 trgAction,
00186 trgBackend );
00187 }
00188
00190 int GetPreambleHandleFromName( const char* preName );
00191
00193 const char* GetPreambleNameFromHandle( int preHandle );
00194
00196 const char* GetPreambleActionFromHandle( int preHandle );
00197
00199 const char* GetPreambleBackendFromHandle( int preHandle );
00200
00202 int GetTableHandleFromName( const char* tblName );
00203
00205 const char* GetTableNameFromHandle( int tblHandle );
00206
00208
00210 int GetIndexHandleFromName( const char* tblName,
00211 const char* idxName );
00213
00215
00216 const char* GetIndexNameFromHandle( int tblHandle,
00217 int idxHandle );
00219
00221
00222 int GetIndexTypeFromHandle( int tblHandle,
00223 int idxHandle );
00225
00227
00229 const char* GetIndexColumnNameFromHandle( int tblHandle,
00230 int idxHandle,
00231 int cnmHandle );
00233
00235
00237 int GetColumnHandleFromName( const char* tblName,
00238 const char* colName );
00240
00242
00244 const char* GetColumnNameFromHandle( int tblHandle,
00245 int colHandle );
00247
00249
00251 int GetColumnTypeFromHandle( int tblHandle,
00252 int colHandle );
00254
00256
00258 int GetColumnSizeFromHandle( int tblHandle,
00259 int colHandle );
00261
00263
00265 const char* GetColumnAttributesFromHandle( int tblHandle,
00266 int colHandle );
00268
00270
00272 int GetTriggerHandleFromName( const char* tblName,
00273 const char* trgName );
00275
00277
00279 const char* GetTriggerNameFromHandle( int tblHandle,
00280 int trgHandle );
00282
00284
00286 int GetTriggerTypeFromHandle( int tblHandle,
00287 int trgHandle );
00289
00291
00293 const char* GetTriggerActionFromHandle( int tblHandle,
00294 int trgHandle );
00296
00298
00300 const char* GetTriggerBackendFromHandle( int tblHandle,
00301 int trgHandle );
00303
00305 void Reset();
00306
00308 int GetNumberOfPreambles();
00309
00311 int GetNumberOfTables();
00312
00314 int GetNumberOfColumnsInTable( int tblHandle );
00315
00317 int GetNumberOfIndicesInTable( int tblHandle );
00318
00320
00322 int GetNumberOfColumnNamesInIndex( int tblHandle,
00323 int idxHandle );
00325
00327 int GetNumberOfTriggersInTable( int tblHandle );
00328
00330
00331 vtkSetStringMacro(Name);
00332 vtkGetStringMacro(Name);
00334
00335
00336
00337 enum VarargTokens
00338 {
00339 COLUMN_TOKEN = 58,
00340 INDEX_TOKEN = 63,
00341 INDEX_COLUMN_TOKEN = 65,
00342 END_INDEX_TOKEN = 75,
00343 TRIGGER_TOKEN = 81,
00344 END_TABLE_TOKEN = 99
00345 };
00346
00348
00373 int AddTableMultipleArguments( const char* tblName, ... );
00374
00376
00377 protected:
00378 vtkSQLDatabaseSchema();
00379 ~vtkSQLDatabaseSchema();
00380
00381 char* Name;
00382
00383 class vtkSQLDatabaseSchemaInternals* Internals;
00384
00385
00386 private:
00387 vtkSQLDatabaseSchema(const vtkSQLDatabaseSchema &);
00388 void operator=(const vtkSQLDatabaseSchema &);
00389 };
00390
00391 #endif // __vtkSQLDatabaseSchema_h