VTK  9.1.0
vtkPostgreSQLDatabase.h
Go to the documentation of this file.
1/* -*- Mode: C++; -*- */
2/*=========================================================================
3
4 Program: Visualization Toolkit
5 Module: vtkPostgreSQLDatabase.h
6
7 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8 All rights reserved.
9 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16/*-------------------------------------------------------------------------
17 Copyright 2008 Sandia Corporation.
18 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
19 the U.S. Government retains certain rights in this software.
20-------------------------------------------------------------------------*/
46#ifndef vtkPostgreSQLDatabase_h
47#define vtkPostgreSQLDatabase_h
48
49#include "vtkIOPostgreSQLModule.h" // For export macro
50#include "vtkSQLDatabase.h"
51
53class vtkStringArray;
55struct PQconn;
56
57class VTKIOPOSTGRESQL_EXPORT vtkPostgreSQLDatabase : public vtkSQLDatabase
58{
59
60 friend class vtkPostgreSQLQuery;
61 friend class vtkPostgreSQLQueryPrivate;
62
63public:
65 void PrintSelf(ostream& os, vtkIndent indent) override;
67
73 bool Open(const char* password = nullptr) override;
74
78 void Close() override;
79
83 bool IsOpen() override;
84
89
93 bool HasError() override;
94
98 const char* GetLastErrorText() override;
99
101
104 const char* GetDatabaseType() override { return this->DatabaseType; }
106
108
111 virtual void SetHostName(const char*);
112 vtkGetStringMacro(HostName);
114
116
119 virtual void SetUser(const char*);
120 vtkGetStringMacro(User);
122
126 virtual void SetPassword(const char*);
127
129
132 virtual void SetDatabaseName(const char*);
133 vtkGetStringMacro(DatabaseName);
135
137
140 virtual void SetConnectOptions(const char*);
141 vtkGetStringMacro(ConnectOptions);
143
145
148 virtual void SetServerPort(int);
149 virtual int GetServerPortMinValue() { return 0; }
150 virtual int GetServerPortMaxValue() { return VTK_INT_MAX; }
151 vtkGetMacro(ServerPort, int);
153
161
166
170 vtkStringArray* GetRecord(const char* table) override;
171
175 bool IsSupported(int feature) override;
176
181
186 bool CreateDatabase(const char* dbName, bool dropExisting = false);
187
192 bool DropDatabase(const char* dbName);
193
203 vtkSQLDatabaseSchema* schema, int tblHandle, int colHandle) override;
204
210 bool ParseURL(const char* url) override;
211
212protected:
215
231
232 vtkSetStringMacro(DatabaseType);
233 vtkSetStringMacro(LastErrorText);
234 void NullTrailingWhitespace(char* msg);
235 bool OpenInternal(const char* connectionOptions);
236
242 char* HostName;
243 char* User;
244 char* Password;
249
250private:
252 void operator=(const vtkPostgreSQLDatabase&) = delete;
253};
254
255// This is basically the body of the SetStringMacro but with a
256// call to update an additional vtkTimeStamp. We inline the implementation
257// so that wrapping will work.
258#define vtkSetStringPlusMTimeMacro(className, name, timeStamp) \
259 inline void className::Set##name(const char* _arg) \
260 { \
261 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " \
262 << (_arg ? _arg : "(null)")); \
263 if (this->name == nullptr && _arg == nullptr) \
264 { \
265 return; \
266 } \
267 if (this->name && _arg && (!strcmp(this->name, _arg))) \
268 { \
269 return; \
270 } \
271 delete[] this->name; \
272 if (_arg) \
273 { \
274 size_t n = strlen(_arg) + 1; \
275 char* cp1 = new char[n]; \
276 const char* cp2 = (_arg); \
277 this->name = cp1; \
278 do \
279 { \
280 *cp1++ = *cp2++; \
281 } while (--n); \
282 } \
283 else \
284 { \
285 this->name = nullptr; \
286 } \
287 this->Modified(); \
288 this->timeStamp.Modified(); \
289 this->Close(); /* Force a re-open on next query */ \
290 }
291
297
299{
300 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting ServerPort to " << _arg);
301 if (this->ServerPort != (_arg < 0 ? 0 : (_arg > VTK_INT_MAX ? VTK_INT_MAX : _arg)))
302 {
303 this->ServerPort = (_arg < 0 ? 0 : (_arg > VTK_INT_MAX ? VTK_INT_MAX : _arg));
304 this->Modified();
305 this->URLMTime.Modified();
306 this->Close(); // Force a re-open on next query
307 }
308}
309
310#endif // vtkPostgreSQLDatabase_h
a simple class to control print indentation
Definition: vtkIndent.h:113
const char * GetClassName() const
Return the class name as a string.
virtual void Modified()
Update the modification time for this object.
internal details of a connection to a PostgreSQL database
maintain a connection to a PostgreSQL database
virtual int GetServerPortMinValue()
The port used for connecting to the database.
bool Open(const char *password=nullptr) override
Open a new connection to the database.
vtkSQLQuery * GetQueryInstance() override
Return an empty query on this database.
bool IsOpen() override
Return whether the database has an open connection.
virtual void SetServerPort(int)
The port used for connecting to the database.
virtual void SetConnectOptions(const char *)
Additional options for the database.
virtual void SetDatabaseName(const char *)
The name of the database to connect to.
bool HasError() override
Did the last operation generate an error.
void NullTrailingWhitespace(char *msg)
~vtkPostgreSQLDatabase() override
void UpdateDataTypeMap()
Create or refresh the map from Postgres column types to VTK array types.
bool IsSupported(int feature) override
Return whether a feature is supported by the database.
virtual void SetHostName(const char *)
The database server host name.
const char * GetDatabaseType() override
String representing database type (e.g.
static vtkPostgreSQLDatabase * New()
bool ParseURL(const char *url) override
Overridden to determine connection parameters given the URL.
vtkStdString GetColumnSpecification(vtkSQLDatabaseSchema *schema, int tblHandle, int colHandle) override
Return the SQL string with the syntax to create a column inside a "CREATE TABLE" SQL statement.
virtual void SetUser(const char *)
The user name for connecting to the database server.
vtkStringArray * GetRecord(const char *table) override
Get the list of fields for a particular table.
vtkStringArray * GetDatabases()
Return a list of databases on the server.
bool DropDatabase(const char *dbName)
Drop a database if it exists.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool OpenInternal(const char *connectionOptions)
virtual int GetServerPortMaxValue()
The port used for connecting to the database.
const char * GetLastErrorText() override
Get the last error text from the database.
void Close() override
Close the connection to the database.
vtkStdString GetURL() override
Get a URL referencing the current database connection.
vtkPostgreSQLDatabasePrivate * Connection
bool CreateDatabase(const char *dbName, bool dropExisting=false)
Create a new database, optionally dropping any existing database of the same name.
vtkStringArray * GetTables() override
Get the list of tables from the database.
virtual void SetPassword(const char *)
The user's password for connecting to the database server.
vtkSQLQuery implementation for PostgreSQL databases
represent an SQL database schema
maintain a connection to an sql database
executes an sql query and retrieves results
Definition: vtkSQLQuery.h:69
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:105
a vtkAbstractArray subclass for strings
record modification and/or execution time
Definition: vtkTimeStamp.h:52
void Modified()
Set this objects time to the current time.
#define vtkSetStringPlusMTimeMacro(className, name, timeStamp)
#define VTK_INT_MAX
Definition: vtkType.h:155