VTK  9.3.1
vtkMySQLDatabase.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright 2008 Sandia Corporation
3 // SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
23 #ifndef vtkMySQLDatabase_h
24 #define vtkMySQLDatabase_h
25 
26 #include "vtkIOMySQLModule.h" // For export macro
27 #include "vtkSQLDatabase.h"
28 
29 VTK_ABI_NAMESPACE_BEGIN
30 class vtkSQLQuery;
31 class vtkMySQLQuery;
32 class vtkStringArray;
34 
35 class VTKIOMYSQL_EXPORT vtkMySQLDatabase : public vtkSQLDatabase
36 {
37 
38  friend class vtkMySQLQuery;
39 
40 public:
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43  static vtkMySQLDatabase* New();
44 
50  bool Open(const char* password = nullptr) override;
51 
55  void Close() override;
56 
60  bool IsOpen() override;
61 
65  vtkSQLQuery* GetQueryInstance() override;
66 
70  vtkStringArray* GetTables() override;
71 
75  vtkStringArray* GetRecord(const char* table) override;
76 
80  bool IsSupported(int feature) override;
81 
85  bool HasError() override;
86 
90  const char* GetLastErrorText() override;
91 
93 
96  const char* GetDatabaseType() override { return this->DatabaseType; }
98 
100 
103  vtkSetStringMacro(HostName);
104  vtkGetStringMacro(HostName);
106 
108 
111  vtkSetStringMacro(User);
112  vtkGetStringMacro(User);
114 
116 
119  vtkSetStringMacro(Password);
121 
123 
126  vtkSetStringMacro(DatabaseName);
127  vtkGetStringMacro(DatabaseName);
129 
131 
136  vtkSetMacro(Reconnect, int);
137  vtkGetMacro(Reconnect, int);
138  vtkBooleanMacro(Reconnect, int);
140 
142 
145  vtkSetClampMacro(ServerPort, int, 0, VTK_INT_MAX);
146  vtkGetMacro(ServerPort, int);
148 
152  vtkStdString GetURL() override;
153 
160  vtkStdString GetTablePreamble(bool b) override { return b ? vtkStdString() : "IF NOT EXISTS "; }
161 
174  vtkSQLDatabaseSchema* schema, int tblHandle, int colHandle) override;
175 
187  vtkSQLDatabaseSchema* schema, int tblHandle, int idxHandle, bool& skipped) override;
188 
193  bool CreateDatabase(const char* dbName, bool dropExisting);
194 
199  bool DropDatabase(const char* dbName);
200 
206  bool ParseURL(const char* url) override;
207 
208 protected:
210  ~vtkMySQLDatabase() override;
211 
212 private:
213  // We want this to be private, a user of this class
214  // should not be setting this for any reason
215  vtkSetStringMacro(DatabaseType);
216 
217  vtkStringArray* Tables;
218  vtkStringArray* Record;
219 
220  char* DatabaseType;
221  char* HostName;
222  char* User;
223  char* Password;
224  char* DatabaseName;
225  int ServerPort;
226  int Reconnect;
227 
228  vtkMySQLDatabasePrivate* const Private;
229 
230  vtkMySQLDatabase(const vtkMySQLDatabase&) = delete;
231  void operator=(const vtkMySQLDatabase&) = delete;
232 };
233 
234 VTK_ABI_NAMESPACE_END
235 #endif // vtkMySQLDatabase_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
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:144
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:39
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:28
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:59
const char * GetDatabaseType() override
String representing database type (e.g.
vtkSQLQuery implementation for MySQL databases
Definition: vtkMySQLQuery.h:36
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.