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 -------------------------------------------------------------------------*/
46 #ifndef vtkSQLDatabaseSchema_h
47 #define vtkSQLDatabaseSchema_h
48 
49 #include "vtkIOSQLModule.h" // For export macro
50 #include "vtkObject.h"
51 
52 #include <cstdarg> // Because one method has a variable list of arguments
53 
54 // This is a list of known supported VTK SQL backend classes.
55 // A particular SQL backend does not have to be listed here to be supported, but
56 // these macros allow for the specification of SQL backend-specific database schema items.
57 #define VTK_SQL_ALLBACKENDS "*" // works for all backends
58 #define VTK_SQL_MYSQL "vtkMySQLDatabase"
59 #define VTK_SQL_POSTGRESQL "vtkPostgreSQLDatabase"
60 #define VTK_SQL_SQLITE "vtkSQLiteDatabase"
61 
62 class vtkSQLDatabaseSchemaInternals;
63 
64 class VTKIOSQL_EXPORT vtkSQLDatabaseSchema : public vtkObject
65 {
66  public:
68  void PrintSelf(ostream& os, vtkIndent indent) override;
69  static vtkSQLDatabaseSchema* New();
70 
75  {
76  SERIAL = 0, // specifying the indices explicitly to prevent bad compiler mishaps
77  SMALLINT = 1,
78  INTEGER = 2,
79  BIGINT = 3,
80  VARCHAR = 4,
81  TEXT = 5,
82  REAL = 6,
83  DOUBLE = 7,
84  BLOB = 8,
85  TIME = 9,
86  DATE = 10,
87  TIMESTAMP = 11
88  };
89 
94  {
95  INDEX = 0, // Non-unique index of values in named columns
96  UNIQUE = 1, // Index of values in named columns required to have at most one entry per pair of valid values.
97  PRIMARY_KEY = 2 // Like UNIQUE but additionally this serves as the primary key for the table to speed up insertions.
98  };
99 
104  {
105  BEFORE_INSERT = 0, // Just before a row is inserted
106  AFTER_INSERT = 1, // Just after a row is inserted
107  BEFORE_UPDATE = 2, // Just before a row's values are changed
108  AFTER_UPDATE = 3, // Just after a row's values are changed
109  BEFORE_DELETE = 4, // Just before a row is deleted
110  AFTER_DELETE = 5 // Just after a row is deleted
111  };
112 
130  virtual int AddPreamble(
131  const char* preName, const char* preAction,
132  const char* preBackend = VTK_SQL_ALLBACKENDS );
133 
137  virtual int AddTable( const char* tblName );
138 
140 
145  virtual int AddColumnToTable(
146  int tblHandle, int colType, const char* colName,
147  int colSize, const char* colAttribs );
148  virtual int AddColumnToTable(
149  const char* tblName, int colType, const char* colName,
150  int colSize, const char* colAttribs )
151  {
152  return this->AddColumnToTable( this->GetTableHandleFromName( tblName ),
153  colType, colName, colSize, colAttribs );
154  }
156 
158 
163  virtual int AddIndexToTable(
164  int tblHandle, int idxType, const char* idxName );
165  virtual int AddIndexToTable(
166  const char* tblName, int idxType, const char* idxName )
167  {
168  return this->AddIndexToTable( this->GetTableHandleFromName( tblName ),
169  idxType, idxName );
170  }
172 
174 
179  virtual int AddColumnToIndex( int tblHandle, int idxHandle, int colHandle );
180  virtual int AddColumnToIndex(
181  const char* tblName, const char* idxName, const char* colName )
182  {
183  int tblHandle = this->GetTableHandleFromName( tblName );
184  return this->AddColumnToIndex( tblHandle,
185  this->GetIndexHandleFromName( tblName, idxName ),
186  this->GetColumnHandleFromName( tblName, colName ) );
187  }
189 
191 
197  virtual int AddTriggerToTable(
198  int tblHandle, int trgType, const char* trgName,
199  const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS );
200  virtual int AddTriggerToTable(
201  const char* tblName, int trgType, const char* trgName,
202  const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS )
203  {
204  return this->AddTriggerToTable( this->GetTableHandleFromName( tblName ),
205  trgType, trgName, trgAction, trgBackend );
206  }
208 
210 
221  virtual int AddOptionToTable(
222  int tblHandle, const char* optStr,
223  const char* optBackend = VTK_SQL_ALLBACKENDS );
224  virtual int AddOptionToTable(
225  const char* tblName, const char* optStr,
226  const char* optBackend = VTK_SQL_ALLBACKENDS )
227  {
228  return this->AddOptionToTable( this->GetTableHandleFromName( tblName ),
229  optStr, optBackend );
230  }
232 
236  int GetPreambleHandleFromName( const char* preName );
237 
241  const char* GetPreambleNameFromHandle( int preHandle );
242 
246  const char* GetPreambleActionFromHandle( int preHandle );
247 
251  const char* GetPreambleBackendFromHandle( int preHandle );
252 
256  int GetTableHandleFromName( const char* tblName );
257 
261  const char* GetTableNameFromHandle( int tblHandle );
262 
266  int GetIndexHandleFromName( const char* tblName, const char* idxName );
267 
271  const char* GetIndexNameFromHandle( int tblHandle, int idxHandle );
272 
276  int GetIndexTypeFromHandle( int tblHandle, int idxHandle );
277 
281  const char* GetIndexColumnNameFromHandle(
282  int tblHandle, int idxHandle, int cnmHandle );
283 
287  int GetColumnHandleFromName( const char* tblName, const char* colName );
288 
292  const char* GetColumnNameFromHandle( int tblHandle, int colHandle );
293 
297  int GetColumnTypeFromHandle( int tblHandle, int colHandle );
298 
302  int GetColumnSizeFromHandle( int tblHandle, int colHandle );
303 
307  const char* GetColumnAttributesFromHandle( int tblHandle, int colHandle );
308 
312  int GetTriggerHandleFromName( const char* tblName, const char* trgName );
313 
317  const char* GetTriggerNameFromHandle( int tblHandle, int trgHandle );
318 
322  int GetTriggerTypeFromHandle( int tblHandle, int trgHandle );
323 
327  const char* GetTriggerActionFromHandle( int tblHandle, int trgHandle );
328 
332  const char* GetTriggerBackendFromHandle( int tblHandle, int trgHandle );
333 
337  const char* GetOptionTextFromHandle( int tblHandle, int optHandle );
338 
342  const char* GetOptionBackendFromHandle( int tblHandle, int trgHandle );
343 
347  void Reset();
348 
352  int GetNumberOfPreambles();
353 
357  int GetNumberOfTables();
358 
362  int GetNumberOfColumnsInTable( int tblHandle );
363 
367  int GetNumberOfIndicesInTable( int tblHandle );
368 
372  int GetNumberOfColumnNamesInIndex( int tblHandle, int idxHandle );
373 
377  int GetNumberOfTriggersInTable( int tblHandle );
378 
382  int GetNumberOfOptionsInTable( int tblHandle );
383 
385 
388  vtkSetStringMacro(Name);
389  vtkGetStringMacro(Name);
391 
392  // Tokens passed to AddTable to indicate the type of data that follows. Random integers chosen to prevent mishaps.
394  {
395  COLUMN_TOKEN = 58,
396  INDEX_TOKEN = 63,
397  INDEX_COLUMN_TOKEN = 65,
398  END_INDEX_TOKEN = 75,
399  TRIGGER_TOKEN = 81,
400  OPTION_TOKEN = 86,
401  END_TABLE_TOKEN = 99
402  };
403 
433  int AddTableMultipleArguments( const char* tblName, ... );
434 
435  protected:
437  ~vtkSQLDatabaseSchema() override;
438 
439  char* Name;
440 
441  class vtkSQLDatabaseSchemaInternals* Internals;
442 
443  private:
444  vtkSQLDatabaseSchema(const vtkSQLDatabaseSchema &) = delete;
445  void operator=(const vtkSQLDatabaseSchema &) = delete;
446 };
447 
448 #endif // vtkSQLDatabaseSchema_h
abstract base class for most VTK objects
Definition: vtkObject.h:59
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual int AddTriggerToTable(const char *tblName, int trgType, const char *trgName, const char *trgAction, const char *trgBackend=VTK_SQL_ALLBACKENDS)
Add a (possibly backend-specific) trigger action to a table.
virtual int AddColumnToTable(const char *tblName, int colType, const char *colName, int colSize, const char *colAttribs)
Add a column to table.
represent an SQL database schema
DatabaseColumnType
Basic data types for database columns.
a simple class to control print indentation
Definition: vtkIndent.h:39
DatabaseTriggerType
Events where database triggers can be registered.
#define VTK_SQL_ALLBACKENDS
DatabaseIndexType
Types of indices that can be generated for database tables.
virtual int AddColumnToIndex(const char *tblName, const char *idxName, const char *colName)
Add a column to a table index.
virtual int AddOptionToTable(const char *tblName, const char *optStr, const char *optBackend=VTK_SQL_ALLBACKENDS)
Add (possibly backend-specific) text to the end of a CREATE TABLE (...) statement.
virtual int AddIndexToTable(const char *tblName, int idxType, const char *idxName)
Add an index to table.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
class vtkSQLDatabaseSchemaInternals * Internals