VTK  9.0.1
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 -------------------------------------------------------------------------*/
43 #ifndef vtkSQLDatabaseSchema_h
44 #define vtkSQLDatabaseSchema_h
45 
46 #include "vtkIOSQLModule.h" // For export macro
47 #include "vtkObject.h"
48 
49 #include <cstdarg> // Because one method has a variable list of arguments
50 
51 // This is a list of known supported VTK SQL backend classes.
52 // A particular SQL backend does not have to be listed here to be supported, but
53 // these macros allow for the specification of SQL backend-specific database schema items.
54 #define VTK_SQL_ALLBACKENDS "*" // works for all backends
55 #define VTK_SQL_MYSQL "vtkMySQLDatabase"
56 #define VTK_SQL_POSTGRESQL "vtkPostgreSQLDatabase"
57 #define VTK_SQL_SQLITE "vtkSQLiteDatabase"
58 
59 class vtkSQLDatabaseSchemaInternals;
60 
61 class VTKIOSQL_EXPORT vtkSQLDatabaseSchema : public vtkObject
62 {
63 public:
65  void PrintSelf(ostream& os, vtkIndent indent) override;
67 
72  {
73  SERIAL = 0, // specifying the indices explicitly to prevent bad compiler mishaps
74  SMALLINT = 1,
75  INTEGER = 2,
76  BIGINT = 3,
77  VARCHAR = 4,
78  TEXT = 5,
79  REAL = 6,
80  DOUBLE = 7,
81  BLOB = 8,
82  TIME = 9,
83  DATE = 10,
84  TIMESTAMP = 11
85  };
86 
91  {
92  INDEX = 0, // Non-unique index of values in named columns
93  UNIQUE = 1, // Index of values in named columns required to have at most one entry per pair of
94  // valid values.
95  PRIMARY_KEY = 2 // Like UNIQUE but additionally this serves as the primary key for the table to
96  // speed up insertions.
97  };
98 
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 
125  virtual int AddPreamble(
126  const char* preName, const char* preAction, const char* preBackend = VTK_SQL_ALLBACKENDS);
127 
131  virtual int AddTable(const char* tblName);
132 
134 
139  virtual int AddColumnToTable(
140  int tblHandle, int colType, const char* colName, int colSize, const char* colAttribs);
141  virtual int AddColumnToTable(
142  const char* tblName, int colType, const char* colName, int colSize, const char* colAttribs)
143  {
144  return this->AddColumnToTable(
145  this->GetTableHandleFromName(tblName), colType, colName, colSize, colAttribs);
146  }
148 
150 
155  virtual int AddIndexToTable(int tblHandle, int idxType, const char* idxName);
156  virtual int AddIndexToTable(const char* tblName, int idxType, const char* idxName)
157  {
158  return this->AddIndexToTable(this->GetTableHandleFromName(tblName), idxType, idxName);
159  }
161 
163 
168  virtual int AddColumnToIndex(int tblHandle, int idxHandle, int colHandle);
169  virtual int AddColumnToIndex(const char* tblName, const char* idxName, const char* colName)
170  {
171  int tblHandle = this->GetTableHandleFromName(tblName);
172  return this->AddColumnToIndex(tblHandle, this->GetIndexHandleFromName(tblName, idxName),
173  this->GetColumnHandleFromName(tblName, colName));
174  }
176 
178 
184  virtual int AddTriggerToTable(int tblHandle, int trgType, const char* trgName,
185  const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS);
186  virtual int AddTriggerToTable(const char* tblName, int trgType, const char* trgName,
187  const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS)
188  {
189  return this->AddTriggerToTable(
190  this->GetTableHandleFromName(tblName), trgType, trgName, trgAction, trgBackend);
191  }
193 
195 
206  virtual int AddOptionToTable(
207  int tblHandle, const char* optStr, const char* optBackend = VTK_SQL_ALLBACKENDS);
208  virtual int AddOptionToTable(
209  const char* tblName, const char* optStr, const char* optBackend = VTK_SQL_ALLBACKENDS)
210  {
211  return this->AddOptionToTable(this->GetTableHandleFromName(tblName), optStr, optBackend);
212  }
214 
218  int GetPreambleHandleFromName(const char* preName);
219 
223  const char* GetPreambleNameFromHandle(int preHandle);
224 
228  const char* GetPreambleActionFromHandle(int preHandle);
229 
233  const char* GetPreambleBackendFromHandle(int preHandle);
234 
238  int GetTableHandleFromName(const char* tblName);
239 
243  const char* GetTableNameFromHandle(int tblHandle);
244 
248  int GetIndexHandleFromName(const char* tblName, const char* idxName);
249 
253  const char* GetIndexNameFromHandle(int tblHandle, int idxHandle);
254 
258  int GetIndexTypeFromHandle(int tblHandle, int idxHandle);
259 
263  const char* GetIndexColumnNameFromHandle(int tblHandle, int idxHandle, int cnmHandle);
264 
268  int GetColumnHandleFromName(const char* tblName, const char* colName);
269 
273  const char* GetColumnNameFromHandle(int tblHandle, int colHandle);
274 
278  int GetColumnTypeFromHandle(int tblHandle, int colHandle);
279 
283  int GetColumnSizeFromHandle(int tblHandle, int colHandle);
284 
288  const char* GetColumnAttributesFromHandle(int tblHandle, int colHandle);
289 
293  int GetTriggerHandleFromName(const char* tblName, const char* trgName);
294 
298  const char* GetTriggerNameFromHandle(int tblHandle, int trgHandle);
299 
303  int GetTriggerTypeFromHandle(int tblHandle, int trgHandle);
304 
308  const char* GetTriggerActionFromHandle(int tblHandle, int trgHandle);
309 
313  const char* GetTriggerBackendFromHandle(int tblHandle, int trgHandle);
314 
318  const char* GetOptionTextFromHandle(int tblHandle, int optHandle);
319 
323  const char* GetOptionBackendFromHandle(int tblHandle, int trgHandle);
324 
328  void Reset();
329 
334 
339 
343  int GetNumberOfColumnsInTable(int tblHandle);
344 
348  int GetNumberOfIndicesInTable(int tblHandle);
349 
353  int GetNumberOfColumnNamesInIndex(int tblHandle, int idxHandle);
354 
358  int GetNumberOfTriggersInTable(int tblHandle);
359 
363  int GetNumberOfOptionsInTable(int tblHandle);
364 
366 
369  vtkSetStringMacro(Name);
370  vtkGetStringMacro(Name);
372 
373  // Tokens passed to AddTable to indicate the type of data that follows. Random integers chosen to
374  // prevent mishaps.
376  {
377  COLUMN_TOKEN = 58,
378  INDEX_TOKEN = 63,
379  INDEX_COLUMN_TOKEN = 65,
380  END_INDEX_TOKEN = 75,
381  TRIGGER_TOKEN = 81,
382  OPTION_TOKEN = 86,
383  END_TABLE_TOKEN = 99
384  };
385 
415  int AddTableMultipleArguments(const char* tblName, ...);
416 
417 protected:
420 
421  char* Name;
422 
423  class vtkSQLDatabaseSchemaInternals* Internals;
424 
425 private:
427  void operator=(const vtkSQLDatabaseSchema&) = delete;
428 };
429 
430 #endif // vtkSQLDatabaseSchema_h
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObject.h:54
represent an SQL database schema
const char * GetIndexNameFromHandle(int tblHandle, int idxHandle)
Given the handles of a table and an index, get the name of the index.
virtual int AddColumnToTable(int tblHandle, int colType, const char *colName, int colSize, const char *colAttribs)
Add a column to table.
virtual int AddColumnToTable(const char *tblName, int colType, const char *colName, int colSize, const char *colAttribs)
int AddTableMultipleArguments(const char *tblName,...)
An unwrappable but useful routine to construct built-in schema.
int GetNumberOfColumnNamesInIndex(int tblHandle, int idxHandle)
Get the number of column names associated to a particular index in a particular table .
class vtkSQLDatabaseSchemaInternals * Internals
int GetNumberOfTables()
Get the number of tables.
virtual int AddColumnToIndex(const char *tblName, const char *idxName, const char *colName)
virtual int AddIndexToTable(const char *tblName, int idxType, const char *idxName)
virtual int AddTable(const char *tblName)
Add a table to the schema.
int GetNumberOfOptionsInTable(int tblHandle)
Get the number of options associated with a particular table.
virtual int AddTriggerToTable(int tblHandle, int trgType, const char *trgName, const char *trgAction, const char *trgBackend=VTK_SQL_ALLBACKENDS)
Add a (possibly backend-specific) trigger action to a table.
int GetTableHandleFromName(const char *tblName)
Given a table name, get its handle.
int GetNumberOfIndicesInTable(int tblHandle)
Get the number of indices in a particular table .
DatabaseColumnType
Basic data types for database columns.
const char * GetOptionBackendFromHandle(int tblHandle, int trgHandle)
Given the handles of a table and one of its options, get the backend of the option.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int GetIndexTypeFromHandle(int tblHandle, int idxHandle)
Given the handles of a table and an index, get the type of the index.
virtual int AddIndexToTable(int tblHandle, int idxType, const char *idxName)
Add an index to table.
int GetColumnHandleFromName(const char *tblName, const char *colName)
Given the names of a table and a column, get the handle of the column in this table.
virtual int AddOptionToTable(int tblHandle, const char *optStr, const char *optBackend=VTK_SQL_ALLBACKENDS)
Add (possibly backend-specific) text to the end of a CREATE TABLE (...) statement.
int GetTriggerTypeFromHandle(int tblHandle, int trgHandle)
Given the handles of a table and a trigger, get the type of the trigger.
const char * GetTableNameFromHandle(int tblHandle)
Given a table handle, get its name.
static vtkSQLDatabaseSchema * New()
int GetTriggerHandleFromName(const char *tblName, const char *trgName)
Given the names of a trigger and a table, get the handle of the trigger in this table.
void Reset()
Reset the schema to its initial, empty state.
virtual int AddPreamble(const char *preName, const char *preAction, const char *preBackend=VTK_SQL_ALLBACKENDS)
Add a preamble to the schema This can be used, in particular, to create functions and/or load languag...
const char * GetPreambleActionFromHandle(int preHandle)
Given a preamble handle, get its action.
const char * GetTriggerNameFromHandle(int tblHandle, int trgHandle)
Given the handles of a table and a trigger, get the name of the trigger.
const char * GetOptionTextFromHandle(int tblHandle, int optHandle)
Given the handles of a table and one of its options, return the text of the option.
const char * GetColumnNameFromHandle(int tblHandle, int colHandle)
Given the handles of a table and a column, get the name of the column.
const char * GetTriggerActionFromHandle(int tblHandle, int trgHandle)
Given the handles of a table and a trigger, get the action of the trigger.
int GetNumberOfColumnsInTable(int tblHandle)
Get the number of columns in a particular table .
int GetNumberOfTriggersInTable(int tblHandle)
Get the number of triggers defined for a particular table.
const char * GetTriggerBackendFromHandle(int tblHandle, int trgHandle)
Given the handles of a table and a trigger, get the backend of the trigger.
virtual int AddColumnToIndex(int tblHandle, int idxHandle, int colHandle)
Add a column to a table index.
~vtkSQLDatabaseSchema() override
virtual int AddTriggerToTable(const char *tblName, int trgType, const char *trgName, const char *trgAction, const char *trgBackend=VTK_SQL_ALLBACKENDS)
int GetColumnTypeFromHandle(int tblHandle, int colHandle)
Given the handles of a table and a column, get the type of the column.
const char * GetPreambleBackendFromHandle(int preHandle)
Given a preamble handle, get its backend.
virtual int AddOptionToTable(const char *tblName, const char *optStr, const char *optBackend=VTK_SQL_ALLBACKENDS)
const char * GetColumnAttributesFromHandle(int tblHandle, int colHandle)
Given the handles of a table and a column, get the attributes of the column.
DatabaseIndexType
Types of indices that can be generated for database tables.
int GetPreambleHandleFromName(const char *preName)
Given a preamble name, get its handle.
int GetIndexHandleFromName(const char *tblName, const char *idxName)
Given the names of a table and an index, get the handle of the index in this table.
const char * GetIndexColumnNameFromHandle(int tblHandle, int idxHandle, int cnmHandle)
Given the handles of a table, an index, and a column name, get the column name.
int GetColumnSizeFromHandle(int tblHandle, int colHandle)
Given the handles of a table and a column, get the size of the column.
const char * GetPreambleNameFromHandle(int preHandle)
Given a preamble handle, get its name.
int GetNumberOfPreambles()
Get the number of preambles.
DatabaseTriggerType
Events where database triggers can be registered.
#define VTK_SQL_ALLBACKENDS