VTK
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 // Check for Qt SQL module before defining this class.
35 #include <qglobal.h> // Needed to check if SQL is available
36 #if (QT_EDITION & QT_MODULE_SQL)
37 
38 #include "vtkGUISupportQtSQLModule.h" // For export macro
39 #include "vtkSQLDatabase.h"
40 
41 #include <QtSql/QSqlDatabase> // For the database member
42 
43 class vtkSQLQuery;
44 class vtkStringArray;
45 
46 class VTKGUISUPPORTQTSQL_EXPORT vtkQtSQLDatabase : public vtkSQLDatabase
47 {
48 public:
49  static vtkQtSQLDatabase* New();
50  vtkTypeMacro(vtkQtSQLDatabase, vtkSQLDatabase);
51  void PrintSelf(ostream& os, vtkIndent indent) override;
52 
58  bool Open(const char* password) override;
59 
63  void Close() override;
64 
68  bool IsOpen() override;
69 
73  vtkSQLQuery* GetQueryInstance() override;
74 
78  vtkStringArray* GetTables() override;
79 
83  vtkStringArray* GetRecord(const char *table) override;
84 
90  vtkStringArray* GetColumns();
91 
97  void SetColumnsTable(const char* table);
98 
102  bool IsSupported(int feature) override;
103 
107  bool HasError() override;
108 
112  const char* GetLastErrorText() override;
113 
115 
118  const char* GetDatabaseType() override
119  {
120  return this->DatabaseType;
121  }
122  vtkSetStringMacro(DatabaseType);
124 
126 
129  vtkSetStringMacro(HostName);
130  vtkGetStringMacro(HostName);
132 
134 
137  vtkSetStringMacro(UserName);
138  vtkGetStringMacro(UserName);
140 
142 
145  vtkSetStringMacro(DatabaseName);
146  vtkGetStringMacro(DatabaseName);
148 
150 
153  vtkSetStringMacro(ConnectOptions);
154  vtkGetStringMacro(ConnectOptions);
156 
158 
161  vtkSetClampMacro(Port, int, 0, 65535);
162  vtkGetMacro(Port, int);
164 
170  static vtkSQLDatabase* CreateFromURL( const char* URL );
171 
175  vtkStdString GetURL() override;
176 
177 protected:
179  ~vtkQtSQLDatabase();
180 
181  char* DatabaseType;
182  char* HostName;
183  char* UserName;
184  char* DatabaseName;
185  int Port;
186  char* ConnectOptions;
187 
188  QSqlDatabase QtDatabase;
189 
190  friend class vtkQtSQLQuery;
191 
197  bool ParseURL(const char* url) override;
198 private:
199 
200  // Storing the tables in the database, this array
201  // is accessible through GetTables() method
202  vtkStringArray *myTables;
203 
204  // Storing the correct record list from any one
205  // of the tables in the database, this array is
206  // accessible through GetRecord(const char *table)
207  vtkStringArray *currentRecord;
208 
209  // Used to assign unique identifiers for database instances
210  static int id;
211 
212  vtkQtSQLDatabase(const vtkQtSQLDatabase &) = delete;
213  void operator=(const vtkQtSQLDatabase &) = delete;
214 };
215 
216 #endif // (QT_EDITION & QT_MODULE_SQL)
217 #endif // vtkQtSQLDatabase_h
218 
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
static vtkSQLDatabase * CreateFromURL(const char *URL)
Create a the proper subclass given a URL.
virtual const char * GetDatabaseType()=0
Get the type of the database (e.g.
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
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&#39;m using const so that people do NOT use the standard vtkG...
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