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 -------------------------------------------------------------------------*/
48 #ifndef vtkPostgreSQLDatabase_h
49 #define vtkPostgreSQLDatabase_h
50 
51 #include "vtkIOPostgreSQLModule.h" // For export macro
52 #include "vtkSQLDatabase.h"
53 
54 class vtkPostgreSQLQuery;
55 class vtkStringArray;
57 struct PQconn;
58 
59 class VTKIOPOSTGRESQL_EXPORT vtkPostgreSQLDatabase : public vtkSQLDatabase
60 {
61  //BTX
62  friend class vtkPostgreSQLQuery;
63  friend class vtkPostgreSQLQueryPrivate;
64  //ETX
65 
66 public:
68  void PrintSelf(ostream& os, vtkIndent indent);
69  static vtkPostgreSQLDatabase *New();
70 
74  bool Open( const char* password = 0 );
75 
77  void Close();
78 
80  bool IsOpen();
81 
84 
86  virtual bool HasError();
87 
89  const char* GetLastErrorText();
90 
92 
93  vtkGetStringMacro(DatabaseType);
95 
97 
98  virtual void SetHostName( const char* );
99  vtkGetStringMacro(HostName);
101 
103 
104  virtual void SetUser( const char* );
105  vtkGetStringMacro(User);
107 
109  virtual void SetPassword( const char* );
110 
112 
113  virtual void SetDatabaseName( const char* );
114  vtkGetStringMacro(DatabaseName);
116 
118 
119  virtual void SetConnectOptions( const char* );
120  vtkGetStringMacro(ConnectOptions);
122 
124 
125  virtual void SetServerPort( int );
126  virtual int GetServerPortMinValue()
127  {
128  return 0;
129  }
130  virtual int GetServerPortMaxValue()
131  {
132  return VTK_INT_MAX;
133  }
134  vtkGetMacro(ServerPort, int);
136 
142  virtual vtkStdString GetURL();
143 
146 
148  vtkStringArray* GetRecord( const char* table );
149 
151  bool IsSupported( int feature );
152 
154  vtkStringArray* GetDatabases();
155 
159  bool CreateDatabase( const char* dbName, bool dropExisting = false );
160 
163  bool DropDatabase( const char* dbName );
164 
166 
171  vtkSQLDatabaseSchema* schema, int tblHandle, int colHandle );
173 
177  virtual bool ParseURL(const char* url);
178 
179 protected:
182 
193  void UpdateDataTypeMap();
194 
195  vtkSetStringMacro(DatabaseType);
196  vtkSetStringMacro(LastErrorText);
197  void NullTrailingWhitespace( char* msg );
198  bool OpenInternal( const char* connectionOptions );
199 
205  char* HostName;
206  char* User;
207  char* Password;
212 
213 private:
214  vtkPostgreSQLDatabase( const vtkPostgreSQLDatabase& ); // Not implemented.
215  void operator = ( const vtkPostgreSQLDatabase& ); // Not implemented.
216 };
217 
218 // This is basically the body of the SetStringMacro but with a
219 // call to update an additional vtkTimeStamp. We inline the implementation
220 // so that wrapping will work.
221 #define vtkSetStringPlusMTimeMacro(className,name,timeStamp) \
222  inline void className::Set##name (const char* _arg) \
223  { \
224  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg?_arg:"(null)") ); \
225  if ( this->name == NULL && _arg == NULL) { return;} \
226  if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \
227  delete [] this->name; \
228  if (_arg) \
229  { \
230  size_t n = strlen(_arg) + 1; \
231  char *cp1 = new char[n]; \
232  const char *cp2 = (_arg); \
233  this->name = cp1; \
234  do { *cp1++ = *cp2++; } while ( --n ); \
235  } \
236  else \
237  { \
238  this->name = NULL; \
239  } \
240  this->Modified(); \
241  this->timeStamp.Modified(); \
242  this->Close(); /* Force a re-open on next query */ \
243  }
244 
249 vtkSetStringPlusMTimeMacro(vtkPostgreSQLDatabase,ConnectOptions,URLMTime);
250 
252 {
253  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting ServerPort to " << _arg );
254  if ( this->ServerPort != ( _arg < 0 ? 0 : ( _arg > VTK_INT_MAX ? VTK_INT_MAX : _arg ) ) )
255  {
256  this->ServerPort = ( _arg < 0 ? 0 : ( _arg > VTK_INT_MAX ? VTK_INT_MAX : _arg ) );
257  this->Modified();
258  this->URLMTime.Modified();
259  this->Close(); // Force a re-open on next query
260  }
261 }
262 
263 #endif // vtkPostgreSQLDatabase_h
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
virtual vtkStdString GetColumnSpecification(vtkSQLDatabaseSchema *schema, int tblHandle, int colHandle)
maintain a connection to a PostgreSQL database
virtual bool IsSupported(int vtkNotUsed(feature))
#define VTK_INT_MAX
Definition: vtkType.h:132
void PrintSelf(ostream &os, vtkIndent indent)
record modification and/or execution time
Definition: vtkTimeStamp.h:34
virtual bool Open(const char *password)=0
virtual bool ParseURL(const char *url)=0
internal details of a connection to a PostgreSQL database
void Modified()
virtual bool HasError()=0
a vtkAbstractArray subclass for strings
virtual vtkStdString GetURL()=0
represent an SQL database schema
virtual vtkStringArray * GetRecord(const char *table)=0
#define vtkSetStringPlusMTimeMacro(className, name, timeStamp)
maintain a connection to an sql database
virtual void Close()=0
vtkPostgreSQLDatabasePrivate * Connection
a simple class to control print indentation
Definition: vtkIndent.h:38
const char * GetClassName() const
vtkSQLQuery implementation for PostgreSQL databases
virtual vtkSQLQuery * GetQueryInstance()=0
virtual bool IsOpen()=0
virtual void Modified()
virtual const char * GetLastErrorText()=0
executes an sql query and retrieves results
Definition: vtkSQLQuery.h:73
static vtkObject * New()
virtual vtkStringArray * GetTables()=0
virtual void SetServerPort(int)