forked from Kitware/VTK
/
vtkQtSQLDatabase.h
212 lines (173 loc) · 5.45 KB
/
vtkQtSQLDatabase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*=========================================================================
Program: Visualization Toolkit
Module: vtkQtSQLDatabase.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
/**
* @class vtkQtSQLDatabase
* @brief maintains a connection to an sql database
*
*
* Implements a vtkSQLDatabase using an underlying Qt QSQLDatabase.
*/
#ifndef vtkQtSQLDatabase_h
#define vtkQtSQLDatabase_h
// Check for Qt SQL module before defining this class.
#include <qglobal.h> // Needed to check if SQL is available
#if (QT_EDITION & QT_MODULE_SQL)
#include "vtkGUISupportQtSQLModule.h" // For export macro
#include "vtkSQLDatabase.h"
#include <QtSql/QSqlDatabase> // For the database member
class vtkSQLQuery;
class vtkStringArray;
class VTKGUISUPPORTQTSQL_EXPORT vtkQtSQLDatabase : public vtkSQLDatabase
{
public:
static vtkQtSQLDatabase* New();
vtkTypeMacro(vtkQtSQLDatabase, vtkSQLDatabase);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Open a new connection to the database.
* You need to set up any database parameters before calling this function.
* Returns true is the database was opened successfully, and false otherwise.
*/
bool Open(const char* password) override;
/**
* Close the connection to the database.
*/
void Close() override;
/**
* Return whether the database has an open connection
*/
bool IsOpen() override;
/**
* Return an empty query on this database.
*/
vtkSQLQuery* GetQueryInstance() override;
/**
* Get the list of tables from the database
*/
vtkStringArray* GetTables() override;
/**
* Get the list of fields for a particular table
*/
vtkStringArray* GetRecord(const char* table) override;
/**
* Returns a list of columns for a particular table.
* Note that this is mainly for use with the VTK parallel server.
* Serial VTK developers should prefer to use GetRecord() instead.
*/
vtkStringArray* GetColumns();
/**
* Set the table used by GetColumns()
* Note that this is mainly for use with the VTK parallel server.
* Serial VTK developers should prefer to use GetRecord() instead.
*/
void SetColumnsTable(const char* table);
/**
* Return whether a feature is supported by the database.
*/
bool IsSupported(int feature) override;
/**
* Did the last operation generate an error
*/
bool HasError() override;
/**
* Get the last error text from the database
*/
const char* GetLastErrorText() override;
//@{
/**
* String representing Qt database type (e.g. "mysql").
*/
const char* GetDatabaseType() override { return this->DatabaseType; }
vtkSetStringMacro(DatabaseType);
//@}
//@{
/**
* The database server host name.
*/
vtkSetStringMacro(HostName);
vtkGetStringMacro(HostName);
//@}
//@{
/**
* The user name for connecting to the database server.
*/
vtkSetStringMacro(UserName);
vtkGetStringMacro(UserName);
//@}
//@{
/**
* The name of the database to connect to.
*/
vtkSetStringMacro(DatabaseName);
vtkGetStringMacro(DatabaseName);
//@}
//@{
/**
* Additional options for the database.
*/
vtkSetStringMacro(ConnectOptions);
vtkGetStringMacro(ConnectOptions);
//@}
//@{
/**
* The port used for connecting to the database.
*/
vtkSetClampMacro(Port, int, 0, 65535);
vtkGetMacro(Port, int);
//@}
/**
* Create a the proper subclass given a URL.
* The URL format for SQL databases is a true URL of the form:
* 'protocol://'[[username[':'password]'@']hostname[':'port]]'/'[dbname] .
*/
static vtkSQLDatabase* CreateFromURL(const char* URL);
/**
* Get the URL of the database.
*/
vtkStdString GetURL() override;
protected:
vtkQtSQLDatabase();
~vtkQtSQLDatabase() override;
char* DatabaseType;
char* HostName;
char* UserName;
char* DatabaseName;
int Port;
char* ConnectOptions;
QSqlDatabase QtDatabase;
friend class vtkQtSQLQuery;
/**
* Overridden to determine connection parameters given the URL.
* This is called by CreateFromURL() to initialize the instance.
* Look at CreateFromURL() for details about the URL format.
*/
bool ParseURL(const char* url) override;
private:
// Storing the tables in the database, this array
// is accessible through GetTables() method
vtkStringArray* myTables;
// Storing the correct record list from any one
// of the tables in the database, this array is
// accessible through GetRecord(const char *table)
vtkStringArray* currentRecord;
// Used to assign unique identifiers for database instances
static int id;
vtkQtSQLDatabase(const vtkQtSQLDatabase&) = delete;
void operator=(const vtkQtSQLDatabase&) = delete;
};
#endif // (QT_EDITION & QT_MODULE_SQL)
#endif // vtkQtSQLDatabase_h
// VTK-HeaderTest-Exclude: vtkQtSQLDatabase.h