VTK  9.0.1
vtkMySQLDatabase.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMySQLDatabase.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 -------------------------------------------------------------------------*/
36 #ifndef vtkMySQLDatabase_h
37 #define vtkMySQLDatabase_h
38 
39 #include "vtkIOMySQLModule.h" // For export macro
40 #include "vtkSQLDatabase.h"
41 
42 class vtkSQLQuery;
43 class vtkMySQLQuery;
44 class vtkStringArray;
46 
47 class VTKIOMYSQL_EXPORT vtkMySQLDatabase : public vtkSQLDatabase
48 {
49 
50  friend class vtkMySQLQuery;
51 
52 public:
54  void PrintSelf(ostream& os, vtkIndent indent) override;
55  static vtkMySQLDatabase* New();
56 
62  bool Open(const char* password = 0) override;
63 
67  void Close() override;
68 
72  bool IsOpen() override;
73 
77  vtkSQLQuery* GetQueryInstance() override;
78 
82  vtkStringArray* GetTables() override;
83 
87  vtkStringArray* GetRecord(const char* table) override;
88 
92  bool IsSupported(int feature) override;
93 
97  bool HasError() override;
98 
102  const char* GetLastErrorText() override;
103 
105 
108  const char* GetDatabaseType() override { return this->DatabaseType; }
110 
112 
115  vtkSetStringMacro(HostName);
116  vtkGetStringMacro(HostName);
118 
120 
123  vtkSetStringMacro(User);
124  vtkGetStringMacro(User);
126 
128 
131  vtkSetStringMacro(Password);
133 
135 
138  vtkSetStringMacro(DatabaseName);
139  vtkGetStringMacro(DatabaseName);
141 
143 
148  vtkSetMacro(Reconnect, int);
149  vtkGetMacro(Reconnect, int);
150  vtkBooleanMacro(Reconnect, int);
152 
154 
157  vtkSetClampMacro(ServerPort, int, 0, VTK_INT_MAX);
158  vtkGetMacro(ServerPort, int);
160 
164  vtkStdString GetURL() override;
165 
172  vtkStdString GetTablePreamble(bool b) override { return b ? vtkStdString() : "IF NOT EXISTS "; }
173 
186  vtkSQLDatabaseSchema* schema, int tblHandle, int colHandle) override;
187 
199  vtkSQLDatabaseSchema* schema, int tblHandle, int idxHandle, bool& skipped) override;
200 
205  bool CreateDatabase(const char* dbName, bool dropExisting);
206 
211  bool DropDatabase(const char* dbName);
212 
218  bool ParseURL(const char* url) override;
219 
220 protected:
222  ~vtkMySQLDatabase() override;
223 
224 private:
225  // We want this to be private, a user of this class
226  // should not be setting this for any reason
227  vtkSetStringMacro(DatabaseType);
228 
229  vtkStringArray* Tables;
230  vtkStringArray* Record;
231 
232  char* DatabaseType;
233  char* HostName;
234  char* User;
235  char* Password;
236  char* DatabaseName;
237  int ServerPort;
238  int Reconnect;
239 
240  vtkMySQLDatabasePrivate* const Private;
241 
242  vtkMySQLDatabase(const vtkMySQLDatabase&) = delete;
243  void operator=(const vtkMySQLDatabase&) = delete;
244 };
245 
246 #endif // vtkMySQLDatabase_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
virtual vtkStdString GetColumnSpecification(vtkSQLDatabaseSchema *schema, int tblHandle, int colHandle)
Return the SQL string with the syntax to create a column inside a "CREATE TABLE" SQL statement...
virtual bool IsSupported(int vtkNotUsed(feature))
Return whether a feature is supported by the database.
#define VTK_INT_MAX
Definition: vtkType.h:155
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.
represent an SQL database schema
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 a MySQL database
maintain a connection to an sql database
friend class vtkMySQLDatabase
Definition: vtkMySQLQuery.h:50
virtual void Close()=0
Close the connection to the database.
virtual vtkStdString GetIndexSpecification(vtkSQLDatabaseSchema *schema, int tblHandle, int idxHandle, bool &skipped)
Return the SQL string with the syntax to create an index inside a "CREATE TABLE" SQL statement...
a simple class to control print indentation
Definition: vtkIndent.h:33
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'm using const so that people do NOT use the standard vtkG...
vtkStdString GetTablePreamble(bool b) override
Return the SQL string with the syntax of the preamble following a "CREATE TABLE" SQL statement...
executes an sql query and retrieves results
Definition: vtkSQLQuery.h:68
const char * GetDatabaseType() override
String representing database type (e.g.
vtkSQLQuery implementation for MySQL databases
Definition: vtkMySQLQuery.h:47
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.