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 "vtkIOSQLModule.h" // For export macro
49 #include "vtkObject.h"
50 
51 #include <cstdarg> // Because one method has a variable list of arguments
52 
53 // This is a list of known supported VTK SQL backend classes.
54 // A particular SQL backend does not have to be listed here to be supported, but
55 // these macros allow for the specification of SQL backend-specific database schema items.
56 #define VTK_SQL_ALLBACKENDS "*" // works for all backends
57 #define VTK_SQL_MYSQL "vtkMySQLDatabase"
58 #define VTK_SQL_POSTGRESQL "vtkPostgreSQLDatabase"
59 #define VTK_SQL_SQLITE "vtkSQLiteDatabase"
60 
61 class vtkSQLDatabaseSchemaInternals;
62 
64 {
65  public:
67  void PrintSelf(ostream& os, vtkIndent indent);
68  static vtkSQLDatabaseSchema* New();
69 
70  //BTX
72 
74  {
75  SERIAL = 0, // specifying the indices explicitly to prevent bad compiler mishaps
76  SMALLINT = 1,
77  INTEGER = 2,
78  BIGINT = 3,
79  VARCHAR = 4,
80  TEXT = 5,
81  REAL = 6,
82  DOUBLE = 7,
83  BLOB = 8,
84  TIME = 9,
85  DATE = 10,
86  TIMESTAMP = 11
87  };
89 
91 
93  {
94  INDEX = 0, // Non-unique index of values in named columns
95  UNIQUE = 1, // Index of values in named columns required to have at most one entry per pair of valid values.
96  PRIMARY_KEY = 2 // Like UNIQUE but additionally this serves as the primary key for the table to speed up insertions.
97  };
99 
101 
103  {
104  BEFORE_INSERT = 0, // Just before a row is inserted
105  AFTER_INSERT = 1, // Just after a row is inserted
106  BEFORE_UPDATE = 2, // Just before a row's values are changed
107  AFTER_UPDATE = 3, // Just after a row's values are changed
108  BEFORE_DELETE = 4, // Just before a row is deleted
109  AFTER_DELETE = 5 // Just after a row is deleted
110  };
111  //ETX
113 
115 
126  virtual int AddPreamble(
127  const char* preName, const char* preAction,
128  const char* preBackend = VTK_SQL_ALLBACKENDS );
130 
132  virtual int AddTable( const char* tblName );
133 
135 
137  virtual int AddColumnToTable(
138  int tblHandle, int colType, const char* colName,
139  int colSize, const char* colAttribs );
140  virtual int AddColumnToTable(
141  const char* tblName, int colType, const char* colName,
142  int colSize, const char* colAttribs )
143  {
144  return this->AddColumnToTable( this->GetTableHandleFromName( tblName ),
145  colType, colName, colSize, colAttribs );
146  }
148 
150 
152  virtual int AddIndexToTable(
153  int tblHandle, int idxType, const char* idxName );
154  virtual int AddIndexToTable(
155  const char* tblName, int idxType, const char* idxName )
156  {
157  return this->AddIndexToTable( this->GetTableHandleFromName( tblName ),
158  idxType, idxName );
159  }
161 
163 
165  virtual int AddColumnToIndex( int tblHandle, int idxHandle, int colHandle );
166  virtual int AddColumnToIndex(
167  const char* tblName, const char* idxName, const char* colName )
168  {
169  int tblHandle = this->GetTableHandleFromName( tblName );
170  return this->AddColumnToIndex( tblHandle,
171  this->GetIndexHandleFromName( tblName, idxName ),
172  this->GetColumnHandleFromName( tblName, colName ) );
173  }
175 
177 
181  virtual int AddTriggerToTable(
182  int tblHandle, int trgType, const char* trgName,
183  const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS );
184  virtual int AddTriggerToTable(
185  const char* tblName, int trgType, const char* trgName,
186  const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS )
187  {
188  return this->AddTriggerToTable( this->GetTableHandleFromName( tblName ),
189  trgType, trgName, trgAction, trgBackend );
190  }
192 
194 
200  virtual int AddOptionToTable(
201  int tblHandle, const char* optStr,
202  const char* optBackend = VTK_SQL_ALLBACKENDS );
203  virtual int AddOptionToTable(
204  const char* tblName, const char* optStr,
205  const char* optBackend = VTK_SQL_ALLBACKENDS )
206  {
207  return this->AddOptionToTable( this->GetTableHandleFromName( tblName ),
208  optStr, optBackend );
209  }
211 
213  int GetPreambleHandleFromName( const char* preName );
214 
216  const char* GetPreambleNameFromHandle( int preHandle );
217 
219  const char* GetPreambleActionFromHandle( int preHandle );
220 
222  const char* GetPreambleBackendFromHandle( int preHandle );
223 
225  int GetTableHandleFromName( const char* tblName );
226 
228  const char* GetTableNameFromHandle( int tblHandle );
229 
232  int GetIndexHandleFromName( const char* tblName, const char* idxName );
233 
235  const char* GetIndexNameFromHandle( int tblHandle, int idxHandle );
236 
238  int GetIndexTypeFromHandle( int tblHandle, int idxHandle );
239 
241 
243  const char* GetIndexColumnNameFromHandle(
244  int tblHandle, int idxHandle, int cnmHandle );
246 
249  int GetColumnHandleFromName( const char* tblName, const char* colName );
250 
253  const char* GetColumnNameFromHandle( int tblHandle, int colHandle );
254 
257  int GetColumnTypeFromHandle( int tblHandle, int colHandle );
258 
261  int GetColumnSizeFromHandle( int tblHandle, int colHandle );
262 
265  const char* GetColumnAttributesFromHandle( int tblHandle, int colHandle );
266 
269  int GetTriggerHandleFromName( const char* tblName, const char* trgName );
270 
273  const char* GetTriggerNameFromHandle( int tblHandle, int trgHandle );
274 
277  int GetTriggerTypeFromHandle( int tblHandle, int trgHandle );
278 
281  const char* GetTriggerActionFromHandle( int tblHandle, int trgHandle );
282 
285  const char* GetTriggerBackendFromHandle( int tblHandle, int trgHandle );
286 
289  const char* GetOptionTextFromHandle( int tblHandle, int optHandle );
290 
293  const char* GetOptionBackendFromHandle( int tblHandle, int trgHandle );
294 
296  void Reset();
297 
299  int GetNumberOfPreambles();
300 
302  int GetNumberOfTables();
303 
305  int GetNumberOfColumnsInTable( int tblHandle );
306 
308  int GetNumberOfIndicesInTable( int tblHandle );
309 
312  int GetNumberOfColumnNamesInIndex( int tblHandle, int idxHandle );
313 
315  int GetNumberOfTriggersInTable( int tblHandle );
316 
318  int GetNumberOfOptionsInTable( int tblHandle );
319 
321 
322  vtkSetStringMacro(Name);
323  vtkGetStringMacro(Name);
325 
326  //BTX
327  // Tokens passed to AddTable to indicate the type of data that follows. Random integers chosen to prevent mishaps.
329  {
330  COLUMN_TOKEN = 58,
331  INDEX_TOKEN = 63,
332  INDEX_COLUMN_TOKEN = 65,
333  END_INDEX_TOKEN = 75,
334  TRIGGER_TOKEN = 81,
335  OPTION_TOKEN = 86,
336  END_TABLE_TOKEN = 99
337  };
338 
340 
365  int AddTableMultipleArguments( const char* tblName, ... );
366  //ETX
368 
369  protected:
372 
373  char* Name;
374 //BTX
375  class vtkSQLDatabaseSchemaInternals* Internals;
376 //ETX
377 
378  private:
379  vtkSQLDatabaseSchema(const vtkSQLDatabaseSchema &); // Not implemented.
380  void operator=(const vtkSQLDatabaseSchema &); // Not implemented.
381 };
382 
383 #endif // vtkSQLDatabaseSchema_h
abstract base class for most VTK objects
Definition: vtkObject.h:61
virtual int AddTriggerToTable(const char *tblName, int trgType, const char *trgName, const char *trgAction, const char *trgBackend=VTK_SQL_ALLBACKENDS)
virtual int AddColumnToTable(const char *tblName, int colType, const char *colName, int colSize, const char *colAttribs)
represent an SQL database schema
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
#define VTK_SQL_ALLBACKENDS
virtual int AddColumnToIndex(const char *tblName, const char *idxName, const char *colName)
virtual int AddOptionToTable(const char *tblName, const char *optStr, const char *optBackend=VTK_SQL_ALLBACKENDS)
virtual int AddIndexToTable(const char *tblName, int idxType, const char *idxName)
#define VTKIOSQL_EXPORT
static vtkObject * New()
class vtkSQLDatabaseSchemaInternals * Internals