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 -------------------------------------------------------------------------*/
59 #ifndef vtkSQLDatabase_h
60 #define vtkSQLDatabase_h
61 
62 #include "vtkIOSQLModule.h" // For export macro
63 #include "vtkObject.h"
64 
65 #include "vtkStdString.h" // Because at least one method returns a vtkStdString
66 
69 class vtkSQLQuery;
70 class vtkStringArray;
71 
72 // This is a list of features that each database may or may not
73 // support. As yet (April 2008) we don't provide access to most of
74 // them.
75 #define VTK_SQL_FEATURE_TRANSACTIONS 1000
76 #define VTK_SQL_FEATURE_QUERY_SIZE 1001
77 #define VTK_SQL_FEATURE_BLOB 1002
78 #define VTK_SQL_FEATURE_UNICODE 1003
79 #define VTK_SQL_FEATURE_PREPARED_QUERIES 1004
80 #define VTK_SQL_FEATURE_NAMED_PLACEHOLDERS 1005
81 #define VTK_SQL_FEATURE_POSITIONAL_PLACEHOLDERS 1006
82 #define VTK_SQL_FEATURE_LAST_INSERT_ID 1007
83 #define VTK_SQL_FEATURE_BATCH_OPERATIONS 1008
84 #define VTK_SQL_FEATURE_TRIGGERS 1009 // supported
85 
86 // Default size for columns types which require a size to be specified
87 // (i.e., VARCHAR), when no size has been specified
88 #define VTK_SQL_DEFAULT_COLUMN_SIZE 32
89 
90 class VTKIOSQL_EXPORT vtkSQLDatabase : public vtkObject
91 {
92 public:
93  vtkTypeMacro(vtkSQLDatabase, vtkObject);
94  void PrintSelf(ostream& os, vtkIndent indent);
95 
102  virtual bool Open(const char* password) = 0;
103 
107  virtual void Close() = 0;
108 
112  virtual bool IsOpen() = 0;
113 
117  virtual VTK_NEWINSTANCE vtkSQLQuery* GetQueryInstance() = 0;
118 
122  virtual bool HasError() = 0;
123 
131  virtual const char* GetLastErrorText() = 0;
132 
136  virtual char* GetDatabaseType() = 0;
137 
141  virtual vtkStringArray* GetTables() = 0;
142 
146  virtual vtkStringArray* GetRecord(const char *table) = 0;
147 
151  virtual bool IsSupported(int vtkNotUsed(feature)) { return false; }
152 
156  virtual vtkStdString GetURL() = 0;
157 
165  virtual vtkStdString GetTablePreamble( bool ) { return vtkStdString(); }
166 
175  virtual vtkStdString GetColumnSpecification( vtkSQLDatabaseSchema* schema,
176  int tblHandle,
177  int colHandle );
178 
191  virtual vtkStdString GetIndexSpecification( vtkSQLDatabaseSchema* schema,
192  int tblHandle,
193  int idxHandle,
194  bool& skipped );
195 
206  virtual vtkStdString GetTriggerSpecification( vtkSQLDatabaseSchema* schema,
207  int tblHandle,
208  int trgHandle );
209 
215  static VTK_NEWINSTANCE vtkSQLDatabase* CreateFromURL( const char* URL );
216 
220  virtual bool EffectSchema( vtkSQLDatabaseSchema*, bool dropIfExists = false );
221 
225  typedef vtkSQLDatabase* (*CreateFunction)(const char* URL);
226 
228 
233  static void RegisterCreateFromURLCallback(CreateFunction callback);
234  static void UnRegisterCreateFromURLCallback(CreateFunction callback);
235  static void UnRegisterAllCreateFromURLCallbacks();
237 
246  static vtkInformationObjectBaseKey* DATABASE();
247 
248 protected:
249  vtkSQLDatabase();
250  ~vtkSQLDatabase();
251 
257  virtual bool ParseURL( const char* url ) = 0;
258 
259 private:
260  vtkSQLDatabase(const vtkSQLDatabase &) VTK_DELETE_FUNCTION;
261  void operator=(const vtkSQLDatabase &) VTK_DELETE_FUNCTION;
262 
264 
267  class vtkCallbackVector;
268  static vtkCallbackVector* Callbacks;
270 
271 };
272 
273 #endif // vtkSQLDatabase_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:47
abstract base class for most VTK objects
Definition: vtkObject.h:59
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual bool IsSupported(int vtkNotUsed(feature))
Return whether a feature is supported by the database.
a vtkAbstractArray subclass for strings
represent an SQL database schema
virtual vtkStdString GetTablePreamble(bool)
Return the SQL string with the syntax of the preamble following a "CREATE TABLE" SQL statement...
maintain a connection to an sql database
a simple class to control print indentation
Definition: vtkIndent.h:39
Key for vtkObjectBase values.
#define VTK_NEWINSTANCE
executes an sql query and retrieves results
Definition: vtkSQLQuery.h:74