VTK  9.3.20240422
vtkSQLDatabase.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
43#ifndef vtkSQLDatabase_h
44#define vtkSQLDatabase_h
45
46#include "vtkIOSQLModule.h" // For export macro
47#include "vtkObject.h"
48
49#include "vtkStdString.h" // Because at least one method returns a vtkStdString
50
51VTK_ABI_NAMESPACE_BEGIN
54class vtkSQLQuery;
55class vtkStringArray;
56
57// This is a list of features that each database may or may not
58// support. As yet (April 2008) we don't provide access to most of
59// them.
60#define VTK_SQL_FEATURE_TRANSACTIONS 1000
61#define VTK_SQL_FEATURE_QUERY_SIZE 1001
62#define VTK_SQL_FEATURE_BLOB 1002
63#define VTK_SQL_FEATURE_UNICODE 1003
64#define VTK_SQL_FEATURE_PREPARED_QUERIES 1004
65#define VTK_SQL_FEATURE_NAMED_PLACEHOLDERS 1005
66#define VTK_SQL_FEATURE_POSITIONAL_PLACEHOLDERS 1006
67#define VTK_SQL_FEATURE_LAST_INSERT_ID 1007
68#define VTK_SQL_FEATURE_BATCH_OPERATIONS 1008
69#define VTK_SQL_FEATURE_TRIGGERS 1009 // supported
70
71// Default size for columns types which require a size to be specified
72// (i.e., VARCHAR), when no size has been specified
73#define VTK_SQL_DEFAULT_COLUMN_SIZE 32
74
75class VTKIOSQL_EXPORT vtkSQLDatabase : public vtkObject
76{
77public:
78 vtkTypeMacro(vtkSQLDatabase, vtkObject);
79 void PrintSelf(ostream& os, vtkIndent indent) override;
80
87 virtual bool Open(const char* password) = 0;
88
92 virtual void Close() = 0;
93
97 virtual bool IsOpen() = 0;
98
103
107 virtual bool HasError() = 0;
108
116 virtual const char* GetLastErrorText() = 0;
117
121 virtual const char* GetDatabaseType() = 0;
122
126 virtual vtkStringArray* GetTables() = 0;
127
131 virtual vtkStringArray* GetRecord(const char* table) = 0;
132
136 virtual bool IsSupported(int vtkNotUsed(feature)) { return false; }
137
141 virtual vtkStdString GetURL() = 0;
142
150 virtual vtkStdString GetTablePreamble(bool) { return vtkStdString(); }
151
163 vtkSQLDatabaseSchema* schema, int tblHandle, int colHandle);
164
180 vtkSQLDatabaseSchema* schema, int tblHandle, int idxHandle, bool& skipped);
181
195 vtkSQLDatabaseSchema* schema, int tblHandle, int trgHandle);
196
203
207 virtual bool EffectSchema(vtkSQLDatabaseSchema*, bool dropIfExists = false);
208
212 typedef vtkSQLDatabase* (*CreateFunction)(const char* URL);
213
215
220 static void RegisterCreateFromURLCallback(CreateFunction callback);
221 static void UnRegisterCreateFromURLCallback(CreateFunction callback);
224
234
235protected:
237 ~vtkSQLDatabase() override;
238
244 virtual bool ParseURL(const char* url) = 0;
245
246private:
247 vtkSQLDatabase(const vtkSQLDatabase&) = delete;
248 void operator=(const vtkSQLDatabase&) = delete;
249
251
254 class vtkCallbackVector;
255 static vtkCallbackVector* Callbacks;
257};
258
259VTK_ABI_NAMESPACE_END
260#endif // vtkSQLDatabase_h
a simple class to control print indentation
Definition vtkIndent.h:108
Key for vtkObjectBase values.
abstract base class for most VTK objects
Definition vtkObject.h:162
represent an SQL database schema
maintain a connection to an sql database
virtual vtkSQLQuery * GetQueryInstance()=0
Return an empty query on this database.
static vtkInformationObjectBaseKey * DATABASE()
Stores the database class pointer as an information key.
virtual bool Open(const char *password)=0
Open a new connection to the database.
virtual vtkStdString GetTriggerSpecification(vtkSQLDatabaseSchema *schema, int tblHandle, int trgHandle)
Return the SQL string with the syntax to create a trigger using a "CREATE TRIGGER" SQL statement.
virtual vtkStringArray * GetRecord(const char *table)=0
Get the list of fields for a particular table.
virtual const char * GetDatabaseType()=0
Get the type of the database (e.g.
virtual vtkStdString GetTablePreamble(bool)
Return the SQL string with the syntax of the preamble following a "CREATE TABLE" SQL statement.
virtual vtkStdString GetURL()=0
Get the URL of the database.
virtual vtkStdString GetColumnSpecification(vtkSQLDatabaseSchema *schema, int tblHandle, int colHandle)
Return the SQL string with the syntax to create a column inside a "CREATE TABLE" SQL statement.
virtual bool ParseURL(const char *url)=0
Subclasses should override this method to determine connection parameters given the URL.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual vtkStdString GetIndexSpecification(vtkSQLDatabaseSchema *schema, int tblHandle, int idxHandle, bool &skipped)
Return the SQL string with the syntax to create an index inside a "CREATE TABLE" SQL statement.
~vtkSQLDatabase() override
static vtkSQLDatabase * CreateFromURL(const char *URL)
Create a the proper subclass given a URL.
static void UnRegisterCreateFromURLCallback(CreateFunction callback)
Provides mechanism to register/unregister additional callbacks to create concrete subclasses of vtkSQ...
virtual bool HasError()=0
Did the last operation generate an error.
virtual bool IsSupported(int vtkNotUsed(feature))
Return whether a feature is supported by the database.
virtual void Close()=0
Close the connection to the database.
static void RegisterCreateFromURLCallback(CreateFunction callback)
Provides mechanism to register/unregister additional callbacks to create concrete subclasses of vtkSQ...
virtual const char * GetLastErrorText()=0
Get the last error text from the database I'm using const so that people do NOT use the standard vtkG...
virtual vtkStringArray * GetTables()=0
Get the list of tables from the database.
virtual bool IsOpen()=0
Return whether the database has an open connection.
static void UnRegisterAllCreateFromURLCallbacks()
Provides mechanism to register/unregister additional callbacks to create concrete subclasses of vtkSQ...
virtual bool EffectSchema(vtkSQLDatabaseSchema *, bool dropIfExists=false)
Effect a database schema.
executes an sql query and retrieves results
Definition vtkSQLQuery.h:60
Wrapper around std::string to keep symbols short.
a vtkAbstractArray subclass for strings
#define VTK_NEWINSTANCE