VTK
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-------------------------------------------------------------------------*/
49#ifndef vtkPostgreSQLDatabase_h
50#define vtkPostgreSQLDatabase_h
51
52#include "vtkIOPostgreSQLModule.h" // For export macro
53#include "vtkSQLDatabase.h"
54
56class vtkStringArray;
58struct PQconn;
59
60class VTKIOPOSTGRESQL_EXPORT vtkPostgreSQLDatabase : public vtkSQLDatabase
61{
62
63 friend class vtkPostgreSQLQuery;
64 friend class vtkPostgreSQLQueryPrivate;
65
66public:
68 void PrintSelf(ostream& os, vtkIndent indent);
70
76 bool Open( const char* password = 0 );
77
81 void Close();
82
86 bool IsOpen();
87
92
96 virtual bool HasError();
97
101 const char* GetLastErrorText();
102
104
107 vtkGetStringMacro(DatabaseType);
109
111
114 virtual void SetHostName( const char* );
117
119
122 virtual void SetUser( const char* );
125
129 virtual void SetPassword( const char* );
130
132
135 virtual void SetDatabaseName( const char* );
136 vtkGetStringMacro(DatabaseName);
138
140
143 virtual void SetConnectOptions( const char* );
144 vtkGetStringMacro(ConnectOptions);
146
148
151 virtual void SetServerPort( int );
153 {
154 return 0;
155 }
157 {
158 return VTK_INT_MAX;
159 }
160 vtkGetMacro(ServerPort, int);
162
170
175
179 vtkStringArray* GetRecord( const char* table );
180
184 bool IsSupported( int feature );
185
190
195 bool CreateDatabase( const char* dbName, bool dropExisting = false );
196
201 bool DropDatabase( const char* dbName );
202
210 vtkSQLDatabaseSchema* schema, int tblHandle, int colHandle );
211
217 virtual bool ParseURL(const char* url);
218
219protected:
222
238
239 vtkSetStringMacro(DatabaseType);
240 vtkSetStringMacro(LastErrorText);
241 void NullTrailingWhitespace( char* msg );
242 bool OpenInternal( const char* connectionOptions );
243
249 char* HostName;
250 char* User;
251 char* Password;
256
257private:
258 vtkPostgreSQLDatabase( const vtkPostgreSQLDatabase& ) VTK_DELETE_FUNCTION;
259 void operator = ( const vtkPostgreSQLDatabase& ) VTK_DELETE_FUNCTION;
260};
261
262// This is basically the body of the SetStringMacro but with a
263// call to update an additional vtkTimeStamp. We inline the implementation
264// so that wrapping will work.
265#define vtkSetStringPlusMTimeMacro(className,name,timeStamp) \
266 inline void className::Set##name (const char* _arg) \
267 { \
268 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg?_arg:"(null)") ); \
269 if ( this->name == NULL && _arg == NULL) { return;} \
270 if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \
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 { *cp1++ = *cp2++; } while ( --n ); \
279 } \
280 else \
281 { \
282 this->name = NULL; \
283 } \
284 this->Modified(); \
285 this->timeStamp.Modified(); \
286 this->Close(); /* Force a re-open on next query */ \
287 }
288
294
296{
297 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting ServerPort to " << _arg );
298 if ( this->ServerPort != ( _arg < 0 ? 0 : ( _arg > VTK_INT_MAX ? VTK_INT_MAX : _arg ) ) )
299 {
300 this->ServerPort = ( _arg < 0 ? 0 : ( _arg > VTK_INT_MAX ? VTK_INT_MAX : _arg ) );
301 this->Modified();
302 this->URLMTime.Modified();
303 this->Close(); // Force a re-open on next query
304 }
305}
306
307#endif // vtkPostgreSQLDatabase_h
a simple class to control print indentation
Definition: vtkIndent.h:40
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 bool ParseURL(const char *url)
Overridden to determine connection parameters given the URL.
vtkStringArray * GetTables()
Get the list of tables from the database.
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.
void NullTrailingWhitespace(char *msg)
void UpdateDataTypeMap()
Create or refresh the map from Postgres column types to VTK array types.
const char * GetLastErrorText()
Get the last error text from the database.
virtual void SetHostName(const char *)
The database server host name.
static vtkPostgreSQLDatabase * New()
bool IsOpen()
Return whether the database has an open connection.
vtkStringArray * GetRecord(const char *table)
Get the list of fields for a particular table.
virtual void SetUser(const char *)
The user name for connecting to the database server.
virtual bool HasError()
Did the last operation generate an error.
vtkStringArray * GetDatabases()
Return a list of databases on the server.
void Close()
Close the connection to the database.
bool DropDatabase(const char *dbName)
Drop a database if it exists.
bool OpenInternal(const char *connectionOptions)
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 vtkStdString GetURL()
Get a URL referencing the current database connection.
bool Open(const char *password=0)
Open a new connection to the database.
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkPostgreSQLDatabasePrivate * Connection
bool CreateDatabase(const char *dbName, bool dropExisting=false)
Create a new database, optionally dropping any existing database of the same name.
vtkSQLQuery * GetQueryInstance()
Return an empty query on this database.
bool IsSupported(int feature)
Return whether a feature is supported by 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:75
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:49
a vtkAbstractArray subclass for strings
record modification and/or execution time
Definition: vtkTimeStamp.h:36
void Modified()
Set this objects time to the current time.
@ url
Definition: vtkX3D.h:233
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
#define vtkSetStringPlusMTimeMacro(className, name, timeStamp)
#define VTK_INT_MAX
Definition: vtkType.h:153