VTK  9.1.0
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 #include "vtkDeprecation.h" // For deprecation macros
32 #include "vtkGUISupportQtSQLModule.h" // For export macro
33 #include "vtkSQLDatabase.h"
34 
35 #include <QtSql/QSqlDatabase> // For the database member
36 
37 class vtkSQLQuery;
38 class vtkStringArray;
39 
40 class VTKGUISUPPORTQTSQL_EXPORT vtkQtSQLDatabase : public vtkSQLDatabase
41 {
42 public:
43  static vtkQtSQLDatabase* New();
45  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
52  bool Open(const char* password) override;
53 
57  void Close() override;
58 
62  bool IsOpen() override;
63 
68 
73 
77  vtkStringArray* GetRecord(const char* table) override;
78 
85 
91  void SetColumnsTable(const char* table);
92 
96  bool IsSupported(int feature) override;
97 
101  bool HasError() override;
102 
106  const char* GetLastErrorText() override;
107 
109 
112  const char* GetDatabaseType() override { return this->DatabaseType; }
113  vtkSetStringMacro(DatabaseType);
115 
117 
120  vtkSetStringMacro(HostName);
121  vtkGetStringMacro(HostName);
123 
125 
128  vtkSetStringMacro(UserName);
129  vtkGetStringMacro(UserName);
131 
133 
136  vtkSetStringMacro(DatabaseName);
137  vtkGetStringMacro(DatabaseName);
139 
141 
144  vtkSetStringMacro(ConnectOptions);
145  vtkGetStringMacro(ConnectOptions);
147 
148  // VTK_DEPRECATED_IN_9_1_0: Remove header test exclusion when this is removed.
150  VTK_DEPRECATED_IN_9_1_0("Renamed to DbPort to avoid Windows macro collisions")
151  void SetPort(int port) { this->SetDbPort(port); }
152  VTK_DEPRECATED_IN_9_1_0("Renamed to DbPort to avoid Windows macro collisions")
153  int GetPort() { return this->GetDbPort(); }
155 
157 
160  vtkSetClampMacro(DbPort, int, 0, 65535);
161  vtkGetMacro(DbPort, int);
163 
169  static vtkSQLDatabase* CreateFromURL(const char* URL);
170 
174  vtkStdString GetURL() override;
175 
176 protected:
178  ~vtkQtSQLDatabase() override;
179 
181  char* HostName;
182  char* UserName;
184  int DbPort;
186 
187  QSqlDatabase QtDatabase;
188 
189  friend class vtkQtSQLQuery;
190 
196  bool ParseURL(const char* url) override;
197 
198 private:
199  // Storing the tables in the database, this array
200  // is accessible through GetTables() method
201  vtkStringArray* myTables;
202 
203  // Storing the correct record list from any one
204  // of the tables in the database, this array is
205  // accessible through GetRecord(const char *table)
206  vtkStringArray* currentRecord;
207 
208  // Used to assign unique identifiers for database instances
209  static int id;
210 
211  vtkQtSQLDatabase(const vtkQtSQLDatabase&) = delete;
212  void operator=(const vtkQtSQLDatabase&) = delete;
213 };
214 
215 #endif // vtkQtSQLDatabase_h
216 // VTK-HeaderTest-Exclude: vtkQtSQLDatabase.h
a simple class to control print indentation
Definition: vtkIndent.h:34
maintains a connection to an sql database
vtkStringArray * GetTables() override
Get the list of tables from the database.
vtkStringArray * GetRecord(const char *table) override
Get the list of fields for a particular table.
vtkSQLQuery * GetQueryInstance() override
Return an empty query on this database.
bool Open(const char *password) override
Open a new connection to the database.
bool IsOpen() override
Return whether the database has an open connection.
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.
vtkStdString GetURL() override
Get the URL of the database.
bool HasError() override
Did the last operation generate an error.
const char * GetLastErrorText() override
Get the last error text from the database.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkQtSQLDatabase * New()
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.
vtkStringArray * GetColumns()
Returns a list of columns for a particular table.
~vtkQtSQLDatabase() override
bool ParseURL(const char *url) override
Overridden to determine connection parameters given the URL.
QSqlDatabase QtDatabase
void Close() override
Close the connection to the database.
query class associated with vtkQtSQLDatabase
Definition: vtkQtSQLQuery.h:38
friend class vtkQtSQLDatabase
Definition: vtkQtSQLQuery.h:91
maintain a connection to an sql database
executes an sql query and retrieves results
Definition: vtkSQLQuery.h:69
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:36
a vtkAbstractArray subclass for strings
@ port
Definition: vtkX3D.h:453
@ url
Definition: vtkX3D.h:239
#define VTK_DEPRECATED_IN_9_1_0(reason)