VTK  9.3.20240424
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
23VTK_ABI_NAMESPACE_BEGIN
24class vtkSQLQuery;
25class vtkStringArray;
26
27class VTKGUISUPPORTQTSQL_EXPORT vtkQtSQLDatabase : public vtkSQLDatabase
28{
29public:
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
55
60
64 vtkStringArray* GetRecord(const char* table) override;
65
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
154
155protected:
158
160 char* HostName;
161 char* UserName;
165
166 QSqlDatabase QtDatabase;
167
168 friend class vtkQtSQLQuery;
169
175 bool ParseURL(const char* url) override;
176
177private:
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
194VTK_ABI_NAMESPACE_END
195#endif // vtkQtSQLDatabase_h
196// VTK-HeaderTest-Exclude: vtkQtSQLDatabase.h
a simple class to control print indentation
Definition vtkIndent.h:108
maintains a connection to an sql database
vtkStringArray * GetTables() override
Get the list of tables from the database.
const char * GetDatabaseType() override
String representing Qt database type (e.g.
bool Open(const char *password) override
Open a new connection to the database.
bool IsOpen() override
Return whether the database has an open connection.
vtkStringArray * GetColumns()
Returns a list of columns for a particular table.
vtkStdString GetURL() override
Get the URL of the database.
vtkSQLQuery * GetQueryInstance() override
Return an empty query on this database.
bool HasError() override
Did the last operation generate an error.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkSQLDatabase * CreateFromURL(const char *URL)
Create a the proper subclass given a URL.
bool IsSupported(int feature) override
Return whether a feature is supported by the database.
void SetColumnsTable(const char *table)
Set the table used by GetColumns() Note that this is mainly for use with the VTK parallel server.
const char * GetLastErrorText() override
Get the last error text from the database.
~vtkQtSQLDatabase() override
bool ParseURL(const char *url) override
Overridden to determine connection parameters given the URL.
vtkStringArray * GetRecord(const char *table) override
Get the list of fields for a particular table.
QSqlDatabase QtDatabase
static vtkQtSQLDatabase * New()
void Close() override
Close the connection to the database.
query class associated with vtkQtSQLDatabase
maintain a connection to an sql database
executes an sql query and retrieves results
Definition vtkSQLQuery.h:60
Wrapper around std::string to keep symbols short.
a vtkAbstractArray subclass for strings