VTK  9.3.1
vtkQtSQLDatabase.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
15 #ifndef vtkQtSQLDatabase_h
16 #define vtkQtSQLDatabase_h
17 
18 #include "vtkGUISupportQtSQLModule.h" // For export macro
19 #include "vtkSQLDatabase.h"
20 
21 #include <QtSql/QSqlDatabase> // For the database member
22 
23 VTK_ABI_NAMESPACE_BEGIN
24 class vtkSQLQuery;
25 class vtkStringArray;
26 
27 class VTKGUISUPPORTQTSQL_EXPORT vtkQtSQLDatabase : public vtkSQLDatabase
28 {
29 public:
30  static vtkQtSQLDatabase* New();
32  void PrintSelf(ostream& os, vtkIndent indent) override;
33 
39  bool Open(const char* password) override;
40 
44  void Close() override;
45 
49  bool IsOpen() override;
50 
54  vtkSQLQuery* GetQueryInstance() override;
55 
59  vtkStringArray* GetTables() override;
60 
64  vtkStringArray* GetRecord(const char* table) override;
65 
71  vtkStringArray* GetColumns();
72 
78  void SetColumnsTable(const char* table);
79 
83  bool IsSupported(int feature) override;
84 
88  bool HasError() override;
89 
93  const char* GetLastErrorText() override;
94 
96 
99  const char* GetDatabaseType() override { return this->DatabaseType; }
100  vtkSetStringMacro(DatabaseType);
102 
104 
107  vtkSetStringMacro(HostName);
108  vtkGetStringMacro(HostName);
110 
112 
115  vtkSetStringMacro(UserName);
116  vtkGetStringMacro(UserName);
118 
120 
123  vtkSetStringMacro(DatabaseName);
124  vtkGetStringMacro(DatabaseName);
126 
128 
131  vtkSetStringMacro(ConnectOptions);
132  vtkGetStringMacro(ConnectOptions);
134 
136 
139  vtkSetClampMacro(DbPort, int, 0, 65535);
140  vtkGetMacro(DbPort, int);
142 
148  static vtkSQLDatabase* CreateFromURL(const char* URL);
149 
153  vtkStdString GetURL() override;
154 
155 protected:
157  ~vtkQtSQLDatabase() override;
158 
160  char* HostName;
161  char* UserName;
163  int DbPort;
165 
166  QSqlDatabase QtDatabase;
167 
168  friend class vtkQtSQLQuery;
169 
175  bool ParseURL(const char* url) override;
176 
177 private:
178  // Storing the tables in the database, this array
179  // is accessible through GetTables() method
180  vtkStringArray* myTables;
181 
182  // Storing the correct record list from any one
183  // of the tables in the database, this array is
184  // accessible through GetRecord(const char *table)
185  vtkStringArray* currentRecord;
186 
187  // Used to assign unique identifiers for database instances
188  static int id;
189 
190  vtkQtSQLDatabase(const vtkQtSQLDatabase&) = delete;
191  void operator=(const vtkQtSQLDatabase&) = delete;
192 };
193 
194 VTK_ABI_NAMESPACE_END
195 #endif // vtkQtSQLDatabase_h
196 // VTK-HeaderTest-Exclude: vtkQtSQLDatabase.h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
static vtkSQLDatabase * CreateFromURL(const char *URL)
Create a the proper subclass given a URL.
const char * GetDatabaseType() override
String representing Qt database type (e.g.
friend class vtkQtSQLDatabase
Definition: vtkQtSQLQuery.h:76
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:22
virtual void Close()=0
Close the connection to the database.
a simple class to control print indentation
Definition: vtkIndent.h:28
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:59
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