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 -------------------------------------------------------------------------*/
28 #ifndef vtkQtSQLDatabase_h
29 #define vtkQtSQLDatabase_h
30 
31 // Check for Qt SQL module before defining this class.
32 #include <qglobal.h> // Needed to check if SQL is available
33 #if (QT_EDITION & QT_MODULE_SQL)
34 
35 #include "vtkGUISupportQtSQLModule.h" // For export macro
36 #include "vtkSQLDatabase.h"
37 
38 #include <QtSql/QSqlDatabase> // For the database member
39 
40 class vtkSQLQuery;
41 class vtkStringArray;
42 
43 class VTKGUISUPPORTQTSQL_EXPORT vtkQtSQLDatabase : public vtkSQLDatabase
44 {
45 public:
46  static vtkQtSQLDatabase* New();
47  vtkTypeMacro(vtkQtSQLDatabase, vtkSQLDatabase);
48  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
49 
55  bool Open(const char* password) VTK_OVERRIDE;
56 
60  void Close() VTK_OVERRIDE;
61 
65  bool IsOpen() VTK_OVERRIDE;
66 
70  vtkSQLQuery* GetQueryInstance() VTK_OVERRIDE;
71 
75  vtkStringArray* GetTables() VTK_OVERRIDE;
76 
80  vtkStringArray* GetRecord(const char *table) VTK_OVERRIDE;
81 
87  vtkStringArray* GetColumns();
88 
94  void SetColumnsTable(const char* table);
95 
99  bool IsSupported(int feature) VTK_OVERRIDE;
100 
104  bool HasError() VTK_OVERRIDE;
105 
109  const char* GetLastErrorText() VTK_OVERRIDE;
110 
112 
115  const char* GetDatabaseType() VTK_OVERRIDE
116  {
117  return this->DatabaseType;
118  }
119  vtkSetStringMacro(DatabaseType);
121 
123 
126  vtkSetStringMacro(HostName);
127  vtkGetStringMacro(HostName);
129 
131 
134  vtkSetStringMacro(UserName);
135  vtkGetStringMacro(UserName);
137 
139 
142  vtkSetStringMacro(DatabaseName);
143  vtkGetStringMacro(DatabaseName);
145 
147 
150  vtkSetStringMacro(ConnectOptions);
151  vtkGetStringMacro(ConnectOptions);
153 
155 
158  vtkSetClampMacro(Port, int, 0, 65535);
159  vtkGetMacro(Port, int);
161 
167  static vtkSQLDatabase* CreateFromURL( const char* URL );
168 
172  vtkStdString GetURL() VTK_OVERRIDE;
173 
174 protected:
176  ~vtkQtSQLDatabase();
177 
178  char* DatabaseType;
179  char* HostName;
180  char* UserName;
181  char* DatabaseName;
182  int Port;
183  char* ConnectOptions;
184 
185  QSqlDatabase QtDatabase;
186 
187  friend class vtkQtSQLQuery;
188 
194  bool ParseURL(const char* url) VTK_OVERRIDE;
195 private:
196 
197  // Storing the tables in the database, this array
198  // is accessible through GetTables() method
199  vtkStringArray *myTables;
200 
201  // Storing the currect record list from any one
202  // of the tables in the database, this array is
203  // accessible through GetRecord(const char *table)
204  vtkStringArray *currentRecord;
205 
206  // Used to assign unique identifiers for database instances
207  static int id;
208 
209  vtkQtSQLDatabase(const vtkQtSQLDatabase &) VTK_DELETE_FUNCTION;
210  void operator=(const vtkQtSQLDatabase &) VTK_DELETE_FUNCTION;
211 };
212 
213 #endif // (QT_EDITION & QT_MODULE_SQL)
214 #endif // vtkQtSQLDatabase_h
215 
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:41
virtual bool Open(const char *password)=0
Open a new connection to the database.
a vtkAbstractArray subclass for strings
virtual vtkStdString GetURL()=0
Get the URL of the database.
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:33
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
static VTK_NEWINSTANCE vtkSQLDatabase * CreateFromURL(const char *URL)
Create a the proper subclass given a URL.
executes an sql query and retrieves results
Definition: vtkSQLQuery.h:68
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
maintains a connection to an sql database