VTK  9.4.20241222
vtkSQLDatabaseSchema.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-FileCopyrightText: Copyright 2008 Sandia Corporation
3// SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
30#ifndef vtkSQLDatabaseSchema_h
31#define vtkSQLDatabaseSchema_h
32
33#include "vtkIOSQLModule.h" // For export macro
34#include "vtkObject.h"
35
36#include <cstdarg> // Because one method has a variable list of arguments
37
38// This is a list of known supported VTK SQL backend classes.
39// A particular SQL backend does not have to be listed here to be supported, but
40// these macros allow for the specification of SQL backend-specific database schema items.
41#define VTK_SQL_ALLBACKENDS "*" // works for all backends
42#define VTK_SQL_MYSQL "vtkMySQLDatabase"
43#define VTK_SQL_POSTGRESQL "vtkPostgreSQLDatabase"
44#define VTK_SQL_SQLITE "vtkSQLiteDatabase"
45
46VTK_ABI_NAMESPACE_BEGIN
47class vtkSQLDatabaseSchemaInternals;
48
49class VTKIOSQL_EXPORT vtkSQLDatabaseSchema : public vtkObject
50{
51public:
53 void PrintSelf(ostream& os, vtkIndent indent) override;
55
60 {
61 SERIAL = 0, // specifying the indices explicitly to prevent bad compiler mishaps
62 SMALLINT = 1,
63 INTEGER = 2,
64 BIGINT = 3,
65 VARCHAR = 4,
66 TEXT = 5,
67 REAL = 6,
68 DOUBLE = 7,
69 BLOB = 8,
70 TIME = 9,
71 DATE = 10,
72 TIMESTAMP = 11
73 };
74
79 {
80 INDEX = 0, // Non-unique index of values in named columns
81 UNIQUE = 1, // Index of values in named columns required to have at most one entry per pair of
82 // valid values.
83 PRIMARY_KEY = 2 // Like UNIQUE but additionally this serves as the primary key for the table to
84 // speed up insertions.
85 };
86
91 {
92 BEFORE_INSERT = 0, // Just before a row is inserted
93 AFTER_INSERT = 1, // Just after a row is inserted
94 BEFORE_UPDATE = 2, // Just before a row's values are changed
95 AFTER_UPDATE = 3, // Just after a row's values are changed
96 BEFORE_DELETE = 4, // Just before a row is deleted
97 AFTER_DELETE = 5 // Just after a row is deleted
98 };
99
113 virtual int AddPreamble(
114 const char* preName, const char* preAction, const char* preBackend = VTK_SQL_ALLBACKENDS);
115
119 virtual int AddTable(const char* tblName);
120
122
127 virtual int AddColumnToTable(
128 int tblHandle, int colType, const char* colName, int colSize, const char* colOpts);
129 virtual int AddColumnToTable(
130 const char* tblName, int colType, const char* colName, int colSize, const char* colAttribs)
131 {
132 return this->AddColumnToTable(
133 this->GetTableHandleFromName(tblName), colType, colName, colSize, colAttribs);
134 }
136
138
143 virtual int AddIndexToTable(int tblHandle, int idxType, const char* idxName);
144 virtual int AddIndexToTable(const char* tblName, int idxType, const char* idxName)
145 {
146 return this->AddIndexToTable(this->GetTableHandleFromName(tblName), idxType, idxName);
147 }
149
151
156 virtual int AddColumnToIndex(int tblHandle, int idxHandle, int colHandle);
157 virtual int AddColumnToIndex(const char* tblName, const char* idxName, const char* colName)
158 {
159 int tblHandle = this->GetTableHandleFromName(tblName);
160 return this->AddColumnToIndex(tblHandle, this->GetIndexHandleFromName(tblName, idxName),
161 this->GetColumnHandleFromName(tblName, colName));
162 }
164
166
172 virtual int AddTriggerToTable(int tblHandle, int trgType, const char* trgName,
173 const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS);
174 virtual int AddTriggerToTable(const char* tblName, int trgType, const char* trgName,
175 const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS)
176 {
177 return this->AddTriggerToTable(
178 this->GetTableHandleFromName(tblName), trgType, trgName, trgAction, trgBackend);
179 }
181
183
194 virtual int AddOptionToTable(
195 int tblHandle, const char* optText, const char* optBackend = VTK_SQL_ALLBACKENDS);
196 virtual int AddOptionToTable(
197 const char* tblName, const char* optStr, const char* optBackend = VTK_SQL_ALLBACKENDS)
198 {
199 return this->AddOptionToTable(this->GetTableHandleFromName(tblName), optStr, optBackend);
200 }
202
206 int GetPreambleHandleFromName(const char* preName);
207
211 const char* GetPreambleNameFromHandle(int preHandle);
212
216 const char* GetPreambleActionFromHandle(int preHandle);
217
221 const char* GetPreambleBackendFromHandle(int preHandle);
222
226 int GetTableHandleFromName(const char* tblName);
227
231 const char* GetTableNameFromHandle(int tblHandle);
232
236 int GetIndexHandleFromName(const char* tblName, const char* idxName);
237
241 const char* GetIndexNameFromHandle(int tblHandle, int idxHandle);
242
246 int GetIndexTypeFromHandle(int tblHandle, int idxHandle);
247
251 const char* GetIndexColumnNameFromHandle(int tblHandle, int idxHandle, int cnmHandle);
252
256 int GetColumnHandleFromName(const char* tblName, const char* colName);
257
261 const char* GetColumnNameFromHandle(int tblHandle, int colHandle);
262
266 int GetColumnTypeFromHandle(int tblHandle, int colHandle);
267
271 int GetColumnSizeFromHandle(int tblHandle, int colHandle);
272
276 const char* GetColumnAttributesFromHandle(int tblHandle, int colHandle);
277
281 int GetTriggerHandleFromName(const char* tblName, const char* trgName);
282
286 const char* GetTriggerNameFromHandle(int tblHandle, int trgHandle);
287
291 int GetTriggerTypeFromHandle(int tblHandle, int trgHandle);
292
296 const char* GetTriggerActionFromHandle(int tblHandle, int trgHandle);
297
301 const char* GetTriggerBackendFromHandle(int tblHandle, int trgHandle);
302
306 const char* GetOptionTextFromHandle(int tblHandle, int optHandle);
307
311 const char* GetOptionBackendFromHandle(int tblHandle, int optHandle);
312
316 void Reset();
317
322
327
331 int GetNumberOfColumnsInTable(int tblHandle);
332
336 int GetNumberOfIndicesInTable(int tblHandle);
337
341 int GetNumberOfColumnNamesInIndex(int tblHandle, int idxHandle);
342
346 int GetNumberOfTriggersInTable(int tblHandle);
347
351 int GetNumberOfOptionsInTable(int tblHandle);
352
354
357 vtkSetStringMacro(Name);
358 vtkGetStringMacro(Name);
360
361 // Tokens passed to AddTable to indicate the type of data that follows. Random integers chosen to
362 // prevent mishaps.
364 {
365 COLUMN_TOKEN = 58,
366 INDEX_TOKEN = 63,
367 INDEX_COLUMN_TOKEN = 65,
368 END_INDEX_TOKEN = 75,
369 TRIGGER_TOKEN = 81,
370 OPTION_TOKEN = 86,
371 END_TABLE_TOKEN = 99
372 };
373
403 int AddTableMultipleArguments(const char* tblName, ...);
404
405protected:
408
409 char* Name;
410
411 class vtkSQLDatabaseSchemaInternals* Internals;
412
413private:
415 void operator=(const vtkSQLDatabaseSchema&) = delete;
416};
417
418VTK_ABI_NAMESPACE_END
419#endif // vtkSQLDatabaseSchema_h
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
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