VTK
vtkSQLDatabaseSchema.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Visualization Toolkit
4 Module: vtkSQLDatabaseSchema.h
5 
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16  Copyright 2008 Sandia Corporation.
17  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18  the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
45 #ifndef __vtkSQLDatabaseSchema_h
46 #define __vtkSQLDatabaseSchema_h
47 
48 #include "vtkObject.h"
49 
50 #include <cstdarg> // Because one method has a variable list of arguments
51 
52 // This is a list of known supported VTK SQL backend classes.
53 // A particular SQL backend does not have to be listed here to be supported, but
54 // these macros allow for the specification of SQL backend-specific database schema items.
55 #define VTK_SQL_ALLBACKENDS "*" // works for all backends
56 #define VTK_SQL_MYSQL "vtkMySQLDatabase"
57 #define VTK_SQL_POSTGRESQL "vtkPostgreSQLDatabase"
58 #define VTK_SQL_SQLITE "vtkSQLiteDatabase"
59 
60 class vtkSQLDatabaseSchemaInternals;
61 
63 {
64  public:
66  void PrintSelf(ostream& os, vtkIndent indent);
67  static vtkSQLDatabaseSchema* New();
68 
69  //BTX
71 
73  {
74  SERIAL = 0, // specifying the indices explicitly to prevent bad compiler mishaps
75  SMALLINT = 1,
76  INTEGER = 2,
77  BIGINT = 3,
78  VARCHAR = 4,
79  TEXT = 5,
80  REAL = 6,
81  DOUBLE = 7,
82  BLOB = 8,
83  TIME = 9,
84  DATE = 10,
85  TIMESTAMP = 11
86  };
88 
90 
92  {
93  INDEX = 0, // Non-unique index of values in named columns
94  UNIQUE = 1, // Index of values in named columns required to have at most one entry per pair of valid values.
95  PRIMARY_KEY = 2 // Like UNIQUE but additionally this serves as the primary key for the table to speed up insertions.
96  };
98 
100 
102  {
103  BEFORE_INSERT = 0, // Just before a row is inserted
104  AFTER_INSERT = 1, // Just after a row is inserted
105  BEFORE_UPDATE = 2, // Just before a row's values are changed
106  AFTER_UPDATE = 3, // Just after a row's values are changed
107  BEFORE_DELETE = 4, // Just before a row is deleted
108  AFTER_DELETE = 5 // Just after a row is deleted
109  };
110  //ETX
112 
114 
125  virtual int AddPreamble(
126  const char* preName, const char* preAction,
127  const char* preBackend = VTK_SQL_ALLBACKENDS );
129 
131  virtual int AddTable( const char* tblName );
132 
134 
136  virtual int AddColumnToTable(
137  int tblHandle, int colType, const char* colName,
138  int colSize, const char* colAttribs );
139  virtual int AddColumnToTable(
140  const char* tblName, int colType, const char* colName,
141  int colSize, const char* colAttribs )
142  {
143  return this->AddColumnToTable( this->GetTableHandleFromName( tblName ),
144  colType, colName, colSize, colAttribs );
145  }
147 
149 
151  virtual int AddIndexToTable(
152  int tblHandle, int idxType, const char* idxName );
153  virtual int AddIndexToTable(
154  const char* tblName, int idxType, const char* idxName )
155  {
156  return this->AddIndexToTable( this->GetTableHandleFromName( tblName ),
157  idxType, idxName );
158  }
160 
162 
164  virtual int AddColumnToIndex( int tblHandle, int idxHandle, int colHandle );
165  virtual int AddColumnToIndex(
166  const char* tblName, const char* idxName, const char* colName )
167  {
168  int tblHandle = this->GetTableHandleFromName( tblName );
169  return this->AddColumnToIndex( tblHandle,
170  this->GetIndexHandleFromName( tblName, idxName ),
171  this->GetColumnHandleFromName( tblName, colName ) );
172  }
174 
176 
180  virtual int AddTriggerToTable(
181  int tblHandle, int trgType, const char* trgName,
182  const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS );
183  virtual int AddTriggerToTable(
184  const char* tblName, int trgType, const char* trgName,
185  const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS )
186  {
187  return this->AddTriggerToTable( this->GetTableHandleFromName( tblName ),
188  trgType, trgName, trgAction, trgBackend );
189  }
191 
193 
199  virtual int AddOptionToTable(
200  int tblHandle, const char* optStr,
201  const char* optBackend = VTK_SQL_ALLBACKENDS );
202  virtual int AddOptionToTable(
203  const char* tblName, const char* optStr,
204  const char* optBackend = VTK_SQL_ALLBACKENDS )
205  {
206  return this->AddOptionToTable( this->GetTableHandleFromName( tblName ),
207  optStr, optBackend );
208  }
210 
212  int GetPreambleHandleFromName( const char* preName );
213 
215  const char* GetPreambleNameFromHandle( int preHandle );
216 
218  const char* GetPreambleActionFromHandle( int preHandle );
219 
221  const char* GetPreambleBackendFromHandle( int preHandle );
222 
224  int GetTableHandleFromName( const char* tblName );
225 
227  const char* GetTableNameFromHandle( int tblHandle );
228 
231  int GetIndexHandleFromName( const char* tblName, const char* idxName );
232 
234  const char* GetIndexNameFromHandle( int tblHandle, int idxHandle );
235 
237  int GetIndexTypeFromHandle( int tblHandle, int idxHandle );
238 
240 
242  const char* GetIndexColumnNameFromHandle(
243  int tblHandle, int idxHandle, int cnmHandle );
245 
248  int GetColumnHandleFromName( const char* tblName, const char* colName );
249 
252  const char* GetColumnNameFromHandle( int tblHandle, int colHandle );
253 
256  int GetColumnTypeFromHandle( int tblHandle, int colHandle );
257 
260  int GetColumnSizeFromHandle( int tblHandle, int colHandle );
261 
264  const char* GetColumnAttributesFromHandle( int tblHandle, int colHandle );
265 
268  int GetTriggerHandleFromName( const char* tblName, const char* trgName );
269 
272  const char* GetTriggerNameFromHandle( int tblHandle, int trgHandle );
273 
276  int GetTriggerTypeFromHandle( int tblHandle, int trgHandle );
277 
280  const char* GetTriggerActionFromHandle( int tblHandle, int trgHandle );
281 
284  const char* GetTriggerBackendFromHandle( int tblHandle, int trgHandle );
285 
288  const char* GetOptionTextFromHandle( int tblHandle, int optHandle );
289 
292  const char* GetOptionBackendFromHandle( int tblHandle, int trgHandle );
293 
295  void Reset();
296 
298  int GetNumberOfPreambles();
299 
301  int GetNumberOfTables();
302 
304  int GetNumberOfColumnsInTable( int tblHandle );
305 
307  int GetNumberOfIndicesInTable( int tblHandle );
308 
311  int GetNumberOfColumnNamesInIndex( int tblHandle, int idxHandle );
312 
314  int GetNumberOfTriggersInTable( int tblHandle );
315 
317  int GetNumberOfOptionsInTable( int tblHandle );
318 
320 
321  vtkSetStringMacro(Name);
322  vtkGetStringMacro(Name);
324 
325  //BTX
326  // Tokens passed to AddTable to indicate the type of data that follows. Random integers chosen to prevent mishaps.
328  {
329  COLUMN_TOKEN = 58,
330  INDEX_TOKEN = 63,
331  INDEX_COLUMN_TOKEN = 65,
332  END_INDEX_TOKEN = 75,
333  TRIGGER_TOKEN = 81,
334  OPTION_TOKEN = 86,
335  END_TABLE_TOKEN = 99
336  };
337 
339 
364  int AddTableMultipleArguments( const char* tblName, ... );
365  //ETX
367 
368  protected:
371 
372  char* Name;
373 //BTX
374  class vtkSQLDatabaseSchemaInternals* Internals;
375 //ETX
376 
377  private:
378  vtkSQLDatabaseSchema(const vtkSQLDatabaseSchema &); // Not implemented.
379  void operator=(const vtkSQLDatabaseSchema &); // Not implemented.
380 };
381 
382 #endif // __vtkSQLDatabaseSchema_h