VTK  9.2.6
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 -------------------------------------------------------------------------*/
31 #ifndef vtkQtSQLDatabase_h
32 #define vtkQtSQLDatabase_h
33 
34 #include "vtkDeprecation.h" // For deprecation macros
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();
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 
151  // VTK_DEPRECATED_IN_9_1_0: Remove header test exclusion when this is removed.
153  VTK_DEPRECATED_IN_9_1_0("Renamed to DbPort to avoid Windows macro collisions")
154  void SetPort(int port) { this->SetDbPort(port); }
155  VTK_DEPRECATED_IN_9_1_0("Renamed to DbPort to avoid Windows macro collisions")
156  int GetPort() { return this->GetDbPort(); }
158 
160 
163  vtkSetClampMacro(DbPort, int, 0, 65535);
164  vtkGetMacro(DbPort, int);
166 
172  static vtkSQLDatabase* CreateFromURL(const char* URL);
173 
177  vtkStdString GetURL() override;
178 
179 protected:
181  ~vtkQtSQLDatabase() override;
182 
184  char* HostName;
185  char* UserName;
187  int DbPort;
189 
190  QSqlDatabase QtDatabase;
191 
192  friend class vtkQtSQLQuery;
193 
199  bool ParseURL(const char* url) override;
200 
201 private:
202  // Storing the tables in the database, this array
203  // is accessible through GetTables() method
204  vtkStringArray* myTables;
205 
206  // Storing the correct record list from any one
207  // of the tables in the database, this array is
208  // accessible through GetRecord(const char *table)
209  vtkStringArray* currentRecord;
210 
211  // Used to assign unique identifiers for database instances
212  static int id;
213 
214  vtkQtSQLDatabase(const vtkQtSQLDatabase&) = delete;
215  void operator=(const vtkQtSQLDatabase&) = delete;
216 };
217 
218 #endif // vtkQtSQLDatabase_h
219 // VTK-HeaderTest-Exclude: vtkQtSQLDatabase.h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
static vtkSQLDatabase * CreateFromURL(const char *URL)
Create a the proper subclass given a URL.
#define VTK_DEPRECATED_IN_9_1_0(reason)
const char * GetDatabaseType() override
String representing Qt database type (e.g.
friend class vtkQtSQLDatabase
Definition: vtkQtSQLQuery.h:91
virtual bool IsSupported(int vtkNotUsed(feature))
Return whether a feature is supported by the database.
virtual bool Open(const char *password)=0
Open a new connection to the database.
virtual bool ParseURL(const char *url)=0
Subclasses should override this method to determine connection parameters given the URL...
virtual bool HasError()=0
Did the last operation generate an error.
a vtkAbstractArray subclass for strings
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.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
maintain a connection to an sql database
query class associated with vtkQtSQLDatabase
Definition: vtkQtSQLQuery.h:37
virtual void Close()=0
Close the connection to the database.
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual vtkSQLQuery * GetQueryInstance()=0
Return an empty query on this database.
virtual bool IsOpen()=0
Return whether the database has an open connection.
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...
QSqlDatabase QtDatabase
executes an sql query and retrieves results
Definition: vtkSQLQuery.h:74
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
virtual vtkStringArray * GetTables()=0
Get the list of tables from the database.
maintains a connection to an sql database