/usr/include/vtk-7.1/vtkSQLDatabaseSchema.h is in libvtk7-dev 7.1.1+dfsg1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | /*=========================================================================
Program: Visualization Toolkit
Module: vtkSQLDatabaseSchema.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
/**
* @class vtkSQLDatabaseSchema
* @brief represent an SQL database schema
*
*
* This class stores the information required to create
* an SQL database from scratch.
* Information on each table's columns, indices, and triggers is stored.
* You may also store an arbitrary number of preamble statements, intended
* to be executed before any tables are created;
* this provides a way to create procedures or functions that may be
* invoked as part of a trigger action.
* Triggers and table options may be specified differently for each backend
* database type you wish to support.
*
* @par Thanks:
* Thanks to Philippe Pebay and David Thompson from Sandia National
* Laboratories for implementing this class.
*
* @sa
* vtkSQLDatabase
*/
#ifndef vtkSQLDatabaseSchema_h
#define vtkSQLDatabaseSchema_h
#include "vtkIOSQLModule.h" // For export macro
#include "vtkObject.h"
#include <cstdarg> // Because one method has a variable list of arguments
// This is a list of known supported VTK SQL backend classes.
// A particular SQL backend does not have to be listed here to be supported, but
// these macros allow for the specification of SQL backend-specific database schema items.
#define VTK_SQL_ALLBACKENDS "*" // works for all backends
#define VTK_SQL_MYSQL "vtkMySQLDatabase"
#define VTK_SQL_POSTGRESQL "vtkPostgreSQLDatabase"
#define VTK_SQL_SQLITE "vtkSQLiteDatabase"
class vtkSQLDatabaseSchemaInternals;
class VTKIOSQL_EXPORT vtkSQLDatabaseSchema : public vtkObject
{
public:
vtkTypeMacro(vtkSQLDatabaseSchema, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
static vtkSQLDatabaseSchema* New();
/**
* Basic data types for database columns
*/
enum DatabaseColumnType
{
SERIAL = 0, // specifying the indices explicitly to prevent bad compiler mishaps
SMALLINT = 1,
INTEGER = 2,
BIGINT = 3,
VARCHAR = 4,
TEXT = 5,
REAL = 6,
DOUBLE = 7,
BLOB = 8,
TIME = 9,
DATE = 10,
TIMESTAMP = 11
};
/**
* Types of indices that can be generated for database tables
*/
enum DatabaseIndexType
{
INDEX = 0, // Non-unique index of values in named columns
UNIQUE = 1, // Index of values in named columns required to have at most one entry per pair of valid values.
PRIMARY_KEY = 2 // Like UNIQUE but additionally this serves as the primary key for the table to speed up insertions.
};
/**
* Events where database triggers can be registered.
*/
enum DatabaseTriggerType
{
BEFORE_INSERT = 0, // Just before a row is inserted
AFTER_INSERT = 1, // Just after a row is inserted
BEFORE_UPDATE = 2, // Just before a row's values are changed
AFTER_UPDATE = 3, // Just after a row's values are changed
BEFORE_DELETE = 4, // Just before a row is deleted
AFTER_DELETE = 5 // Just after a row is deleted
};
/**
* Add a preamble to the schema
* This can be used, in particular, to create functions and/or
* load languages in a backend-specific manner.
* Example usage:
* vtkSQLDatabaseSchema* schema = vtkSQLDatabaseSchema::New();
* schema->SetName( "Example" );
* schema->AddPreamble( "dropPLPGSQL", "DROP LANGUAGE IF EXISTS PLPGSQL CASCADE", VTK_SQL_POSTGRESQL );
* schema->AddPreamble( "loadPLPGSQL", "CREATE LANGUAGE PLPGSQL", VTK_SQL_POSTGRESQL );
* schema->AddPreamble( "createsomefunction",
* "CREATE OR REPLACE FUNCTION somefunction() RETURNS TRIGGER AS $btable$ "
* "BEGIN "
* "INSERT INTO btable (somevalue) VALUES (NEW.somenmbr); "
* "RETURN NEW; "
* "END; $btable$ LANGUAGE PLPGSQL",
* VTK_SQL_POSTGRESQL );
*/
virtual int AddPreamble(
const char* preName, const char* preAction,
const char* preBackend = VTK_SQL_ALLBACKENDS );
/**
* Add a table to the schema
*/
virtual int AddTable( const char* tblName );
//@{
/**
* Add a column to table.
* The returned value is a column handle or -1 if an error occurred.
*/
virtual int AddColumnToTable(
int tblHandle, int colType, const char* colName,
int colSize, const char* colAttribs );
virtual int AddColumnToTable(
const char* tblName, int colType, const char* colName,
int colSize, const char* colAttribs )
{
return this->AddColumnToTable( this->GetTableHandleFromName( tblName ),
colType, colName, colSize, colAttribs );
}
//@}
//@{
/**
* Add an index to table.
* The returned value is an index handle or -1 if an error occurred.
*/
virtual int AddIndexToTable(
int tblHandle, int idxType, const char* idxName );
virtual int AddIndexToTable(
const char* tblName, int idxType, const char* idxName )
{
return this->AddIndexToTable( this->GetTableHandleFromName( tblName ),
idxType, idxName );
}
//@}
//@{
/**
* Add a column to a table index.
* The returned value is an index-column handle or -1 if an error occurred.
*/
virtual int AddColumnToIndex( int tblHandle, int idxHandle, int colHandle );
virtual int AddColumnToIndex(
const char* tblName, const char* idxName, const char* colName )
{
int tblHandle = this->GetTableHandleFromName( tblName );
return this->AddColumnToIndex( tblHandle,
this->GetIndexHandleFromName( tblName, idxName ),
this->GetColumnHandleFromName( tblName, colName ) );
}
//@}
//@{
/**
* Add a (possibly backend-specific) trigger action to a table.
* Triggers must be given unique, non-NULL names as some database backends require them.
* The returned value is a trigger handle or -1 if an error occurred.
*/
virtual int AddTriggerToTable(
int tblHandle, int trgType, const char* trgName,
const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS );
virtual int AddTriggerToTable(
const char* tblName, int trgType, const char* trgName,
const char* trgAction, const char* trgBackend = VTK_SQL_ALLBACKENDS )
{
return this->AddTriggerToTable( this->GetTableHandleFromName( tblName ),
trgType, trgName, trgAction, trgBackend );
}
//@}
//@{
/**
* Add (possibly backend-specific) text to the end of a
* CREATE TABLE (...) statement.
* This is most useful for specifying storage semantics of tables
* that are specific to the backend. For example, table options
* can be used to specify the TABLESPACE of a PostgreSQL table or
* the ENGINE of a MySQL table.
* The returned value is an option handle or -1 if an error occurred.
*/
virtual int AddOptionToTable(
int tblHandle, const char* optStr,
const char* optBackend = VTK_SQL_ALLBACKENDS );
virtual int AddOptionToTable(
const char* tblName, const char* optStr,
const char* optBackend = VTK_SQL_ALLBACKENDS )
{
return this->AddOptionToTable( this->GetTableHandleFromName( tblName ),
optStr, optBackend );
}
//@}
/**
* Given a preamble name, get its handle.
*/
int GetPreambleHandleFromName( const char* preName );
/**
* Given a preamble handle, get its name.
*/
const char* GetPreambleNameFromHandle( int preHandle );
/**
* Given a preamble handle, get its action.
*/
const char* GetPreambleActionFromHandle( int preHandle );
/**
* Given a preamble handle, get its backend.
*/
const char* GetPreambleBackendFromHandle( int preHandle );
/**
* Given a table name, get its handle.
*/
int GetTableHandleFromName( const char* tblName );
/**
* Given a table hanlde, get its name.
*/
const char* GetTableNameFromHandle( int tblHandle );
/**
* Given the names of a table and an index, get the handle of the index in this table.
*/
int GetIndexHandleFromName( const char* tblName, const char* idxName );
/**
* Given the handles of a table and an index, get the name of the index.
*/
const char* GetIndexNameFromHandle( int tblHandle, int idxHandle );
/**
* Given the handles of a table and an index, get the type of the index.
*/
int GetIndexTypeFromHandle( int tblHandle, int idxHandle );
/**
* Given the handles of a table, an index, and a column name, get the column name.
*/
const char* GetIndexColumnNameFromHandle(
int tblHandle, int idxHandle, int cnmHandle );
/**
* Given the names of a table and a column, get the handle of the column in this table.
*/
int GetColumnHandleFromName( const char* tblName, const char* colName );
/**
* Given the handles of a table and a column, get the name of the column.
*/
const char* GetColumnNameFromHandle( int tblHandle, int colHandle );
/**
* Given the handles of a table and a column, get the type of the column.
*/
int GetColumnTypeFromHandle( int tblHandle, int colHandle );
/**
* Given the handles of a table and a column, get the size of the column.
*/
int GetColumnSizeFromHandle( int tblHandle, int colHandle );
/**
* Given the handles of a table and a column, get the attributes of the column.
*/
const char* GetColumnAttributesFromHandle( int tblHandle, int colHandle );
/**
* Given the names of a trigger and a table, get the handle of the trigger in this table.
*/
int GetTriggerHandleFromName( const char* tblName, const char* trgName );
/**
* Given the handles of a table and a trigger, get the name of the trigger.
*/
const char* GetTriggerNameFromHandle( int tblHandle, int trgHandle );
/**
* Given the handles of a table and a trigger, get the type of the trigger.
*/
int GetTriggerTypeFromHandle( int tblHandle, int trgHandle );
/**
* Given the handles of a table and a trigger, get the action of the trigger.
*/
const char* GetTriggerActionFromHandle( int tblHandle, int trgHandle );
/**
* Given the handles of a table and a trigger, get the backend of the trigger.
*/
const char* GetTriggerBackendFromHandle( int tblHandle, int trgHandle );
/**
* Given the handles of a table and one of its options, return the text of the option.
*/
const char* GetOptionTextFromHandle( int tblHandle, int optHandle );
/**
* Given the handles of a table and one of its options, get the backend of the option.
*/
const char* GetOptionBackendFromHandle( int tblHandle, int trgHandle );
/**
* Reset the schema to its initial, empty state.
*/
void Reset();
/**
* Get the number of preambles.
*/
int GetNumberOfPreambles();
/**
* Get the number of tables.
*/
int GetNumberOfTables();
/**
* Get the number of columns in a particular table .
*/
int GetNumberOfColumnsInTable( int tblHandle );
/**
* Get the number of indices in a particular table .
*/
int GetNumberOfIndicesInTable( int tblHandle );
/**
* Get the number of column names associated to a particular index in a particular table .
*/
int GetNumberOfColumnNamesInIndex( int tblHandle, int idxHandle );
/**
* Get the number of triggers defined for a particular table.
*/
int GetNumberOfTriggersInTable( int tblHandle );
/**
* Get the number of options associated with a particular table.
*/
int GetNumberOfOptionsInTable( int tblHandle );
//@{
/**
* Set/Get the name of the schema.
*/
vtkSetStringMacro(Name);
vtkGetStringMacro(Name);
//@}
// Tokens passed to AddTable to indicate the type of data that follows. Random integers chosen to prevent mishaps.
enum VarargTokens
{
COLUMN_TOKEN = 58,
INDEX_TOKEN = 63,
INDEX_COLUMN_TOKEN = 65,
END_INDEX_TOKEN = 75,
TRIGGER_TOKEN = 81,
OPTION_TOKEN = 86,
END_TABLE_TOKEN = 99
};
/**
* An unwrappable but useful routine to construct built-in schema.
* Example usage:
* int main()
* {
* vtkSQLDatabaseSchema* schema = vtkSQLDatabaseSchema::New();
* schema->SetName( "Example" );
* schema->AddTableMultipleArguments( "atable",
* vtkSQLDatabaseSchema::COLUMN_TOKEN, vtkSQLDatabaseSchema::INTEGER, "tablekey", 0, "",
* vtkSQLDatabaseSchema::COLUMN_TOKEN, vtkSQLDatabaseSchema::VARCHAR, "somename", 11, "NOT NULL",
* vtkSQLDatabaseSchema::COLUMN_TOKEN, vtkSQLDatabaseSchema::BIGINT, "somenmbr", 17, "DEFAULT 0",
* vtkSQLDatabaseSchema::INDEX_TOKEN, vtkSQLDatabaseSchema::PRIMARY_KEY, "bigkey",
* vtkSQLDatabaseSchema::INDEX_COLUMN_TOKEN, "tablekey",
* vtkSQLDatabaseSchema::END_INDEX_TOKEN,
* vtkSQLDatabaseSchema::INDEX_TOKEN, vtkSQLDatabaseSchema::UNIQUE, "reverselookup",
* vtkSQLDatabaseSchema::INDEX_COLUMN_TOKEN, "somename",
* vtkSQLDatabaseSchema::INDEX_COLUMN_TOKEN, "somenmbr",
* vtkSQLDatabaseSchema::END_INDEX_TOKEN,
* vtkSQLDatabaseSchema::TRIGGER_TOKEN, vtkSQLDatabaseSchema::AFTER_INSERT,
* "InsertTrigger", "DO NOTHING", VTK_SQL_SQLITE,
* vtkSQLDatabaseSchema::TRIGGER_TOKEN, vtkSQLDatabaseSchema::AFTER_INSERT,
* "InsertTrigger", "FOR EACH ROW EXECUTE PROCEDURE somefunction ()", VTK_SQL_POSTGRESQL,
* vtkSQLDatabaseSchema::TRIGGER_TOKEN, vtkSQLDatabaseSchema::AFTER_INSERT,
* "InsertTrigger", "FOR EACH ROW INSERT INTO btable SET SomeValue = NEW.SomeNmbr", VTK_SQL_MYSQL,
* vtkSQLDatabaseSchema::END_TABLE_TOKEN
* );
* return 0;
* }
*/
int AddTableMultipleArguments( const char* tblName, ... );
protected:
vtkSQLDatabaseSchema();
~vtkSQLDatabaseSchema();
char* Name;
class vtkSQLDatabaseSchemaInternals* Internals;
private:
vtkSQLDatabaseSchema(const vtkSQLDatabaseSchema &) VTK_DELETE_FUNCTION;
void operator=(const vtkSQLDatabaseSchema &) VTK_DELETE_FUNCTION;
};
#endif // vtkSQLDatabaseSchema_h
|