VTK
vtkSQLDatabase.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Visualization Toolkit
4 Module: vtkSQLDatabase.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 -------------------------------------------------------------------------*/
53 #ifndef vtkSQLDatabase_h
54 #define vtkSQLDatabase_h
55 
56 #include "vtkIOSQLModule.h" // For export macro
57 #include "vtkObject.h"
58 
59 #include "vtkStdString.h" // Because at least one method returns a vtkStdString
60 
63 class vtkSQLQuery;
64 class vtkStringArray;
65 
66 // This is a list of features that each database may or may not
67 // support. As yet (April 2008) we don't provide access to most of
68 // them.
69 #define VTK_SQL_FEATURE_TRANSACTIONS 1000
70 #define VTK_SQL_FEATURE_QUERY_SIZE 1001
71 #define VTK_SQL_FEATURE_BLOB 1002
72 #define VTK_SQL_FEATURE_UNICODE 1003
73 #define VTK_SQL_FEATURE_PREPARED_QUERIES 1004
74 #define VTK_SQL_FEATURE_NAMED_PLACEHOLDERS 1005
75 #define VTK_SQL_FEATURE_POSITIONAL_PLACEHOLDERS 1006
76 #define VTK_SQL_FEATURE_LAST_INSERT_ID 1007
77 #define VTK_SQL_FEATURE_BATCH_OPERATIONS 1008
78 #define VTK_SQL_FEATURE_TRIGGERS 1009 // supported
79 
80 // Default size for columns types which require a size to be specified
81 // (i.e., VARCHAR), when no size has been specified
82 #define VTK_SQL_DEFAULT_COLUMN_SIZE 32
83 
84 class VTKIOSQL_EXPORT vtkSQLDatabase : public vtkObject
85 {
86 public:
87  vtkTypeMacro(vtkSQLDatabase, vtkObject);
88  void PrintSelf(ostream& os, vtkIndent indent) override;
89 
96  virtual bool Open(const char* password) = 0;
97 
101  virtual void Close() = 0;
102 
106  virtual bool IsOpen() = 0;
107 
111  virtual VTK_NEWINSTANCE vtkSQLQuery* GetQueryInstance() = 0;
112 
116  virtual bool HasError() = 0;
117 
125  virtual const char* GetLastErrorText() = 0;
126 
130  virtual const char* GetDatabaseType() = 0;
131 
135  virtual vtkStringArray* GetTables() = 0;
136 
140  virtual vtkStringArray* GetRecord(const char *table) = 0;
141 
145  virtual bool IsSupported(int vtkNotUsed(feature)) { return false; }
146 
150  virtual vtkStdString GetURL() = 0;
151 
159  virtual vtkStdString GetTablePreamble( bool ) { return vtkStdString(); }
160 
169  virtual vtkStdString GetColumnSpecification( vtkSQLDatabaseSchema* schema,
170  int tblHandle,
171  int colHandle );
172 
185  virtual vtkStdString GetIndexSpecification( vtkSQLDatabaseSchema* schema,
186  int tblHandle,
187  int idxHandle,
188  bool& skipped );
189 
200  virtual vtkStdString GetTriggerSpecification( vtkSQLDatabaseSchema* schema,
201  int tblHandle,
202  int trgHandle );
203 
209  static VTK_NEWINSTANCE vtkSQLDatabase* CreateFromURL( const char* URL );
210 
214  virtual bool EffectSchema( vtkSQLDatabaseSchema*, bool dropIfExists = false );
215 
219  typedef vtkSQLDatabase* (*CreateFunction)(const char* URL);
220 
222 
227  static void RegisterCreateFromURLCallback(CreateFunction callback);
228  static void UnRegisterCreateFromURLCallback(CreateFunction callback);
229  static void UnRegisterAllCreateFromURLCallbacks();
231 
240  static vtkInformationObjectBaseKey* DATABASE();
241 
242 protected:
243  vtkSQLDatabase();
244  ~vtkSQLDatabase() override;
245 
251  virtual bool ParseURL( const char* url ) = 0;
252 
253 private:
254  vtkSQLDatabase(const vtkSQLDatabase &) = delete;
255  void operator=(const vtkSQLDatabase &) = delete;
256 
258 
261  class vtkCallbackVector;
262  static vtkCallbackVector* Callbacks;
264 
265 };
266 
267 #endif // vtkSQLDatabase_h
vtkStdString.h
vtkSQLDatabase::IsSupported
virtual bool IsSupported(int vtkNotUsed(feature))
Return whether a feature is supported by the database.
Definition: vtkSQLDatabase.h:145
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkInformationObjectBaseKey
Key for vtkObjectBase values.
Definition: vtkInformationObjectBaseKey.h:33
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkX3D::url
Definition: vtkX3D.h:233
vtkObject.h
vtkSQLDatabaseSchema
represent an SQL database schema
Definition: vtkSQLDatabaseSchema.h:61
vtkStringArray
a vtkAbstractArray subclass for strings
Definition: vtkStringArray.h:36
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:39
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
vtkSQLDatabase::GetTablePreamble
virtual vtkStdString GetTablePreamble(bool)
Return the SQL string with the syntax of the preamble following a "CREATE TABLE" SQL statement.
Definition: vtkSQLDatabase.h:159
vtkSQLQuery
executes an sql query and retrieves results
Definition: vtkSQLQuery.h:68
vtkSQLDatabase
maintain a connection to an sql database
Definition: vtkSQLDatabase.h:84