VTK  9.0.2
vtkQtSQLDatabase.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkQtSQLDatabase.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 -------------------------------------------------------------------------*/
28 #ifndef vtkQtSQLDatabase_h
29 #define vtkQtSQLDatabase_h
30 
31 // Check for Qt SQL module before defining this class.
32 #include <qglobal.h> // Needed to check if SQL is available
33 #if (QT_EDITION & QT_MODULE_SQL)
34 
35 #include "vtkGUISupportQtSQLModule.h" // For export macro
36 #include "vtkSQLDatabase.h"
37 
38 #include <QtSql/QSqlDatabase> // For the database member
39 
40 class vtkSQLQuery;
41 class vtkStringArray;
42 
43 class VTKGUISUPPORTQTSQL_EXPORT vtkQtSQLDatabase : public vtkSQLDatabase
44 {
45 public:
46  static vtkQtSQLDatabase* New();
47  vtkTypeMacro(vtkQtSQLDatabase, vtkSQLDatabase);
48  void PrintSelf(ostream& os, vtkIndent indent) override;
49 
55  bool Open(const char* password) override;
56 
60  void Close() override;
61 
65  bool IsOpen() override;
66 
70  vtkSQLQuery* GetQueryInstance() override;
71 
75  vtkStringArray* GetTables() override;
76 
80  vtkStringArray* GetRecord(const char* table) override;
81 
87  vtkStringArray* GetColumns();
88 
94  void SetColumnsTable(const char* table);
95 
99  bool IsSupported(int feature) override;
100 
104  bool HasError() override;
105 
109  const char* GetLastErrorText() override;
110 
112 
115  const char* GetDatabaseType() override { return this->DatabaseType; }
116  vtkSetStringMacro(DatabaseType);
118 
120 
123  vtkSetStringMacro(HostName);
124  vtkGetStringMacro(HostName);
126 
128 
131  vtkSetStringMacro(UserName);
132  vtkGetStringMacro(UserName);
134 
136 
139  vtkSetStringMacro(DatabaseName);
140  vtkGetStringMacro(DatabaseName);
142 
144 
147  vtkSetStringMacro(ConnectOptions);
148  vtkGetStringMacro(ConnectOptions);
150 
152 
155  vtkSetClampMacro(Port, int, 0, 65535);
156  vtkGetMacro(Port, int);
158 
164  static vtkSQLDatabase* CreateFromURL(const char* URL);
165 
169  vtkStdString GetURL() override;
170 
171 protected:
173  ~vtkQtSQLDatabase() override;
174 
175  char* DatabaseType;
176  char* HostName;
177  char* UserName;
178  char* DatabaseName;
179  int Port;
180  char* ConnectOptions;
181 
182  QSqlDatabase QtDatabase;
183 
184  friend class vtkQtSQLQuery;
185 
191  bool ParseURL(const char* url) override;
192 
193 private:
194  // Storing the tables in the database, this array
195  // is accessible through GetTables() method
196  vtkStringArray* myTables;
197 
198  // Storing the correct record list from any one
199  // of the tables in the database, this array is
200  // accessible through GetRecord(const char *table)
201  vtkStringArray* currentRecord;
202 
203  // Used to assign unique identifiers for database instances
204  static int id;
205 
206  vtkQtSQLDatabase(const vtkQtSQLDatabase&) = delete;
207  void operator=(const vtkQtSQLDatabase&) = delete;
208 };
209 
210 #endif // (QT_EDITION & QT_MODULE_SQL)
211 #endif // vtkQtSQLDatabase_h
212 // VTK-HeaderTest-Exclude: vtkQtSQLDatabase.h
a simple class to control print indentation
Definition: vtkIndent.h:34
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
maintains a connection to an sql database
query class associated with vtkQtSQLDatabase
maintain a connection to an sql database
virtual const char * GetDatabaseType()=0
Get the type of the database (e.g.
virtual bool Open(const char *password)=0
Open a new connection to the database.
virtual vtkStdString GetURL()=0
Get the URL of the database.
virtual vtkStringArray * GetRecord(const char *table)=0
Get the list of fields for a particular table.
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 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 vtkSQLQuery * GetQueryInstance()=0
Return an empty query on this database.
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.
virtual bool IsOpen()=0
Return whether the database has an open connection.
static vtkSQLDatabase * CreateFromURL(const char *URL)
Create a the proper subclass given a URL.
virtual vtkStringArray * GetTables()=0
Get the list of tables from the database.
executes an sql query and retrieves results
Definition: vtkSQLQuery.h:69
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:35
a vtkAbstractArray subclass for strings
@ url
Definition: vtkX3D.h:239