VTK  9.2.6
vtkSQLDatabaseSchema.h
Go to the documentation of this file.
1/*=========================================================================
2
3Program: Visualization Toolkit
4Module: vtkSQLDatabaseSchema.h
5
6Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7All rights reserved.
8See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10This software is distributed WITHOUT ANY WARRANTY; without even
11the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12PURPOSE. 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
62class vtkSQLDatabaseSchemaInternals;
63
64class VTKIOSQL_EXPORT vtkSQLDatabaseSchema : public vtkObject
65{
66public:
68 void PrintSelf(ostream& os, vtkIndent indent) override;
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
97 // valid values.
98 PRIMARY_KEY = 2 // Like UNIQUE but additionally this serves as the primary key for the table to
99 // speed up insertions.
100 };
101
106 {
107 BEFORE_INSERT = 0, // Just before a row is inserted
108 AFTER_INSERT = 1, // Just after a row is inserted
109 BEFORE_UPDATE = 2, // Just before a row's values are changed
110 AFTER_UPDATE = 3, // Just after a row's values are changed
111 BEFORE_DELETE = 4, // Just before a row is deleted
112 AFTER_DELETE = 5 // Just after a row is deleted
113 };
114
128 virtual int AddPreamble(
129 const char* preName, const char* preAction, const char* preBackend = VTK_SQL_ALLBACKENDS);
130
134 virtual int AddTable(const char* tblName);
135
137
142 virtual int AddColumnToTable(
143 int tblHandle, int colType, const char* colName, int colSize, const char* colOpts);
144 virtual int AddColumnToTable(
145 const char* tblName, int colType, const char* colName, int colSize, const char* colAttribs)
146 {
147 return this->AddColumnToTable(
148 this->GetTableHandleFromName(tblName), colType, colName, colSize, colAttribs);
149 }
151
153
158 virtual int AddIndexToTable(int tblHandle, int idxType, const char* idxName);
159 virtual int AddIndexToTable(const char* tblName, int idxType, const char* idxName)
160 {
161 return this->AddIndexToTable(this->GetTableHandleFromName(tblName), idxType, idxName);
162 }
164
166
171 virtual int AddColumnToIndex(int tblHandle, int idxHandle, int colHandle);
172 virtual int AddColumnToIndex(const char* tblName, const char* idxName, const char* colName)
173 {
174 int tblHandle = this->GetTableHandleFromName(tblName);
175 return this->AddColumnToIndex(tblHandle, this->GetIndexHandleFromName(tblName, idxName),
176 this->GetColumnHandleFromName(tblName, colName));
177 }
179
181
187 virtual int AddTriggerToTable(int tblHandle, int trgType, const char* trgName,
188 const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS);
189 virtual int AddTriggerToTable(const char* tblName, int trgType, const char* trgName,
190 const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS)
191 {
192 return this->AddTriggerToTable(
193 this->GetTableHandleFromName(tblName), trgType, trgName, trgAction, trgBackend);
194 }
196
198
209 virtual int AddOptionToTable(
210 int tblHandle, const char* optText, const char* optBackend = VTK_SQL_ALLBACKENDS);
211 virtual int AddOptionToTable(
212 const char* tblName, const char* optStr, const char* optBackend = VTK_SQL_ALLBACKENDS)
213 {
214 return this->AddOptionToTable(this->GetTableHandleFromName(tblName), optStr, optBackend);
215 }
217
221 int GetPreambleHandleFromName(const char* preName);
222
226 const char* GetPreambleNameFromHandle(int preHandle);
227
231 const char* GetPreambleActionFromHandle(int preHandle);
232
236 const char* GetPreambleBackendFromHandle(int preHandle);
237
241 int GetTableHandleFromName(const char* tblName);
242
246 const char* GetTableNameFromHandle(int tblHandle);
247
251 int GetIndexHandleFromName(const char* tblName, const char* idxName);
252
256 const char* GetIndexNameFromHandle(int tblHandle, int idxHandle);
257
261 int GetIndexTypeFromHandle(int tblHandle, int idxHandle);
262
266 const char* GetIndexColumnNameFromHandle(int tblHandle, int idxHandle, int cnmHandle);
267
271 int GetColumnHandleFromName(const char* tblName, const char* colName);
272
276 const char* GetColumnNameFromHandle(int tblHandle, int colHandle);
277
281 int GetColumnTypeFromHandle(int tblHandle, int colHandle);
282
286 int GetColumnSizeFromHandle(int tblHandle, int colHandle);
287
291 const char* GetColumnAttributesFromHandle(int tblHandle, int colHandle);
292
296 int GetTriggerHandleFromName(const char* tblName, const char* trgName);
297
301 const char* GetTriggerNameFromHandle(int tblHandle, int trgHandle);
302
306 int GetTriggerTypeFromHandle(int tblHandle, int trgHandle);
307
311 const char* GetTriggerActionFromHandle(int tblHandle, int trgHandle);
312
316 const char* GetTriggerBackendFromHandle(int tblHandle, int trgHandle);
317
321 const char* GetOptionTextFromHandle(int tblHandle, int optHandle);
322
326 const char* GetOptionBackendFromHandle(int tblHandle, int optHandle);
327
331 void Reset();
332
337
342
346 int GetNumberOfColumnsInTable(int tblHandle);
347
351 int GetNumberOfIndicesInTable(int tblHandle);
352
356 int GetNumberOfColumnNamesInIndex(int tblHandle, int idxHandle);
357
361 int GetNumberOfTriggersInTable(int tblHandle);
362
366 int GetNumberOfOptionsInTable(int tblHandle);
367
369
372 vtkSetStringMacro(Name);
373 vtkGetStringMacro(Name);
375
376 // Tokens passed to AddTable to indicate the type of data that follows. Random integers chosen to
377 // prevent mishaps.
379 {
380 COLUMN_TOKEN = 58,
381 INDEX_TOKEN = 63,
382 INDEX_COLUMN_TOKEN = 65,
383 END_INDEX_TOKEN = 75,
384 TRIGGER_TOKEN = 81,
385 OPTION_TOKEN = 86,
386 END_TABLE_TOKEN = 99
387 };
388
418 int AddTableMultipleArguments(const char* tblName, ...);
419
420protected:
423
424 char* Name;
425
426 class vtkSQLDatabaseSchemaInternals* Internals;
427
428private:
430 void operator=(const vtkSQLDatabaseSchema&) = delete;
431};
432
433#endif // vtkSQLDatabaseSchema_h
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:63
represent an SQL database schema
virtual int AddColumnToTable(int tblHandle, int colType, const char *colName, int colSize, const char *colOpts)
Add a column to table.
const char * GetPreambleBackendFromHandle(int preHandle)
Given a preamble handle, get its backend.
const char * GetTriggerNameFromHandle(int tblHandle, int trgHandle)
Given the handles of a table and a trigger, get the name of the trigger.
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.
static vtkSQLDatabaseSchema * New()
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.
const char * GetColumnNameFromHandle(int tblHandle, int colHandle)
Given the handles of a table and a column, get the name of the column.
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.
const char * GetTriggerActionFromHandle(int tblHandle, int trgHandle)
Given the handles of a table and a trigger, get the action of the trigger.
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.
const char * GetOptionTextFromHandle(int tblHandle, int optHandle)
Given the handles of a table and one of its options, return the text of the option.
int GetTriggerTypeFromHandle(int tblHandle, int trgHandle)
Given the handles of a table and a trigger, get the type of the trigger.
const char * GetColumnAttributesFromHandle(int tblHandle, int colHandle)
Given the handles of a table and a column, get the attributes of the column.
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.
const char * GetIndexNameFromHandle(int tblHandle, int idxHandle)
Given the handles of a table and an index, get the name of the index.
const char * GetTableNameFromHandle(int tblHandle)
Given a table handle, get its name.
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 * GetPreambleNameFromHandle(int preHandle)
Given a preamble handle, get its name.
int GetNumberOfColumnsInTable(int tblHandle)
Get the number of columns in 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.
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 GetNumberOfTriggersInTable(int tblHandle)
Get the number of triggers defined for a particular table.
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 * GetPreambleActionFromHandle(int preHandle)
Given a preamble handle, get its action.
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.
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.
int GetColumnSizeFromHandle(int tblHandle, int colHandle)
Given the handles of a table and a column, get the size of the column.
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