VTK  9.2.20221001
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 VTK_ABI_NAMESPACE_BEGIN
63 class vtkSQLDatabaseSchemaInternals;
64 
65 class VTKIOSQL_EXPORT vtkSQLDatabaseSchema : public vtkObject
66 {
67 public:
69  void PrintSelf(ostream& os, vtkIndent indent) override;
71 
76  {
77  SERIAL = 0, // specifying the indices explicitly to prevent bad compiler mishaps
78  SMALLINT = 1,
79  INTEGER = 2,
80  BIGINT = 3,
81  VARCHAR = 4,
82  TEXT = 5,
83  REAL = 6,
84  DOUBLE = 7,
85  BLOB = 8,
86  TIME = 9,
87  DATE = 10,
88  TIMESTAMP = 11
89  };
90 
95  {
96  INDEX = 0, // Non-unique index of values in named columns
97  UNIQUE = 1, // Index of values in named columns required to have at most one entry per pair of
98  // valid values.
99  PRIMARY_KEY = 2 // Like UNIQUE but additionally this serves as the primary key for the table to
100  // speed up insertions.
101  };
102 
107  {
108  BEFORE_INSERT = 0, // Just before a row is inserted
109  AFTER_INSERT = 1, // Just after a row is inserted
110  BEFORE_UPDATE = 2, // Just before a row's values are changed
111  AFTER_UPDATE = 3, // Just after a row's values are changed
112  BEFORE_DELETE = 4, // Just before a row is deleted
113  AFTER_DELETE = 5 // Just after a row is deleted
114  };
115 
129  virtual int AddPreamble(
130  const char* preName, const char* preAction, const char* preBackend = VTK_SQL_ALLBACKENDS);
131 
135  virtual int AddTable(const char* tblName);
136 
138 
143  virtual int AddColumnToTable(
144  int tblHandle, int colType, const char* colName, int colSize, const char* colOpts);
145  virtual int AddColumnToTable(
146  const char* tblName, int colType, const char* colName, int colSize, const char* colAttribs)
147  {
148  return this->AddColumnToTable(
149  this->GetTableHandleFromName(tblName), colType, colName, colSize, colAttribs);
150  }
152 
154 
159  virtual int AddIndexToTable(int tblHandle, int idxType, const char* idxName);
160  virtual int AddIndexToTable(const char* tblName, int idxType, const char* idxName)
161  {
162  return this->AddIndexToTable(this->GetTableHandleFromName(tblName), idxType, idxName);
163  }
165 
167 
172  virtual int AddColumnToIndex(int tblHandle, int idxHandle, int colHandle);
173  virtual int AddColumnToIndex(const char* tblName, const char* idxName, const char* colName)
174  {
175  int tblHandle = this->GetTableHandleFromName(tblName);
176  return this->AddColumnToIndex(tblHandle, this->GetIndexHandleFromName(tblName, idxName),
177  this->GetColumnHandleFromName(tblName, colName));
178  }
180 
182 
188  virtual int AddTriggerToTable(int tblHandle, int trgType, const char* trgName,
189  const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS);
190  virtual int AddTriggerToTable(const char* tblName, int trgType, const char* trgName,
191  const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS)
192  {
193  return this->AddTriggerToTable(
194  this->GetTableHandleFromName(tblName), trgType, trgName, trgAction, trgBackend);
195  }
197 
199 
210  virtual int AddOptionToTable(
211  int tblHandle, const char* optText, const char* optBackend = VTK_SQL_ALLBACKENDS);
212  virtual int AddOptionToTable(
213  const char* tblName, const char* optStr, const char* optBackend = VTK_SQL_ALLBACKENDS)
214  {
215  return this->AddOptionToTable(this->GetTableHandleFromName(tblName), optStr, optBackend);
216  }
218 
222  int GetPreambleHandleFromName(const char* preName);
223 
227  const char* GetPreambleNameFromHandle(int preHandle);
228 
232  const char* GetPreambleActionFromHandle(int preHandle);
233 
237  const char* GetPreambleBackendFromHandle(int preHandle);
238 
242  int GetTableHandleFromName(const char* tblName);
243 
247  const char* GetTableNameFromHandle(int tblHandle);
248 
252  int GetIndexHandleFromName(const char* tblName, const char* idxName);
253 
257  const char* GetIndexNameFromHandle(int tblHandle, int idxHandle);
258 
262  int GetIndexTypeFromHandle(int tblHandle, int idxHandle);
263 
267  const char* GetIndexColumnNameFromHandle(int tblHandle, int idxHandle, int cnmHandle);
268 
272  int GetColumnHandleFromName(const char* tblName, const char* colName);
273 
277  const char* GetColumnNameFromHandle(int tblHandle, int colHandle);
278 
282  int GetColumnTypeFromHandle(int tblHandle, int colHandle);
283 
287  int GetColumnSizeFromHandle(int tblHandle, int colHandle);
288 
292  const char* GetColumnAttributesFromHandle(int tblHandle, int colHandle);
293 
297  int GetTriggerHandleFromName(const char* tblName, const char* trgName);
298 
302  const char* GetTriggerNameFromHandle(int tblHandle, int trgHandle);
303 
307  int GetTriggerTypeFromHandle(int tblHandle, int trgHandle);
308 
312  const char* GetTriggerActionFromHandle(int tblHandle, int trgHandle);
313 
317  const char* GetTriggerBackendFromHandle(int tblHandle, int trgHandle);
318 
322  const char* GetOptionTextFromHandle(int tblHandle, int optHandle);
323 
327  const char* GetOptionBackendFromHandle(int tblHandle, int optHandle);
328 
332  void Reset();
333 
338 
343 
347  int GetNumberOfColumnsInTable(int tblHandle);
348 
352  int GetNumberOfIndicesInTable(int tblHandle);
353 
357  int GetNumberOfColumnNamesInIndex(int tblHandle, int idxHandle);
358 
362  int GetNumberOfTriggersInTable(int tblHandle);
363 
367  int GetNumberOfOptionsInTable(int tblHandle);
368 
370 
373  vtkSetStringMacro(Name);
374  vtkGetStringMacro(Name);
376 
377  // Tokens passed to AddTable to indicate the type of data that follows. Random integers chosen to
378  // prevent mishaps.
380  {
381  COLUMN_TOKEN = 58,
382  INDEX_TOKEN = 63,
383  INDEX_COLUMN_TOKEN = 65,
384  END_INDEX_TOKEN = 75,
385  TRIGGER_TOKEN = 81,
386  OPTION_TOKEN = 86,
387  END_TABLE_TOKEN = 99
388  };
389 
419  int AddTableMultipleArguments(const char* tblName, ...);
420 
421 protected:
424 
425  char* Name;
426 
427  class vtkSQLDatabaseSchemaInternals* Internals;
428 
429 private:
431  void operator=(const vtkSQLDatabaseSchema&) = delete;
432 };
433 
434 VTK_ABI_NAMESPACE_END
435 #endif // vtkSQLDatabaseSchema_h
a simple class to control print indentation
Definition: vtkIndent.h:120
abstract base class for most VTK objects
Definition: vtkObject.h:83
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 *colOpts)
Add a column to table.
virtual int AddColumnToTable(const char *tblName, int colType, const char *colName, int colSize, const char *colAttribs)
Add a column to table.
int AddTableMultipleArguments(const char *tblName,...)
An unwrappable but useful routine to construct built-in schema.
const char * GetOptionBackendFromHandle(int tblHandle, int optHandle)
Given the handles of a table and one of its options, get the backend of the option.
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)
Add a column to a table index.
virtual int AddIndexToTable(const char *tblName, int idxType, const char *idxName)
Add an index to table.
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.
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.
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)
Add a (possibly backend-specific) trigger action to a table.
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)
Add (possibly backend-specific) text to the end of a CREATE TABLE (...) statement.
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.
virtual int AddOptionToTable(int tblHandle, const char *optText, const char *optBackend=VTK_SQL_ALLBACKENDS)
Add (possibly backend-specific) text to the end of a CREATE TABLE (...) statement.
DatabaseTriggerType
Events where database triggers can be registered.
#define VTK_SQL_ALLBACKENDS