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 "vtkSQLDatabase.h"
52 
53 class vtkPostgreSQLQuery;
54 class vtkStringArray;
56 struct PQconn;
57 
59 {
60  //BTX
61  friend class vtkPostgreSQLQuery;
62  friend class vtkPostgreSQLQueryPrivate;
63  //ETX
64 
65 public:
67  void PrintSelf(ostream& os, vtkIndent indent);
68  static vtkPostgreSQLDatabase *New();
69 
73  bool Open( const char* password = 0 );
74 
76  void Close();
77 
79  bool IsOpen();
80 
83 
85  virtual bool HasError();
86 
88  const char* GetLastErrorText();
89 
91 
92  vtkGetStringMacro(DatabaseType);
94 
96 
97  virtual void SetHostName( const char* );
98  vtkGetStringMacro(HostName);
100 
102 
103  virtual void SetUser( const char* );
104  vtkGetStringMacro(User);
106 
108  virtual void SetPassword( const char* );
109 
111 
112  virtual void SetDatabaseName( const char* );
113  vtkGetStringMacro(DatabaseName);
115 
117 
118  virtual void SetConnectOptions( const char* );
119  vtkGetStringMacro(ConnectOptions);
121 
123 
124  virtual void SetServerPort( int );
125  virtual int GetServerPortMinValue()
126  {
127  return 0;
128  }
129  virtual int GetServerPortMaxValue()
130  {
131  return VTK_INT_MAX;
132  }
133  vtkGetMacro(ServerPort, int);
135 
141  virtual vtkStdString GetURL();
142 
145 
147  vtkStringArray* GetRecord( const char* table );
148 
150  bool IsSupported( int feature );
151 
153  vtkStringArray* GetDatabases();
154 
158  bool CreateDatabase( const char* dbName, bool dropExisting = false );
159 
162  bool DropDatabase( const char* dbName );
163 
165 
170  vtkSQLDatabaseSchema* schema, int tblHandle, int colHandle );
172 
173 protected:
176 
187  void UpdateDataTypeMap();
188 
192  virtual bool ParseURL(const char* url);
193 
194  vtkSetStringMacro(DatabaseType);
195  vtkSetStringMacro(LastErrorText);
196  void NullTrailingWhitespace( char* msg );
197  bool OpenInternal( const char* connectionOptions );
198 
204  char* HostName;
205  char* User;
206  char* Password;
211 
212 private:
213  vtkPostgreSQLDatabase( const vtkPostgreSQLDatabase& ); // Not implemented.
214  void operator = ( const vtkPostgreSQLDatabase& ); // Not implemented.
215 };
216 
217 // This is basically the body of the SetStringMacro but with a
218 // call to update an additional vtkTimeStamp. We inline the implementation
219 // so that wrapping will work.
220 #define vtkSetStringPlusMTimeMacro(className,name,timeStamp) \
221  inline void className::Set##name (const char* _arg) \
222  { \
223  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg?_arg:"(null)") ); \
224  if ( this->name == NULL && _arg == NULL) { return;} \
225  if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \
226  if (this->name) { delete [] this->name; } \
227  if (_arg) \
228  { \
229  size_t n = strlen(_arg) + 1; \
230  char *cp1 = new char[n]; \
231  const char *cp2 = (_arg); \
232  this->name = cp1; \
233  do { *cp1++ = *cp2++; } while ( --n ); \
234  } \
235  else \
236  { \
237  this->name = NULL; \
238  } \
239  this->Modified(); \
240  this->timeStamp.Modified(); \
241  this->Close(); /* Force a re-open on next query */ \
242  }
243 
248 vtkSetStringPlusMTimeMacro(vtkPostgreSQLDatabase,ConnectOptions,URLMTime);
249 
251 {
252  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting ServerPort to " << _arg );
253  if ( this->ServerPort != ( _arg < 0 ? 0 : ( _arg > VTK_INT_MAX ? VTK_INT_MAX : _arg ) ) )
254  {
255  this->ServerPort = ( _arg < 0 ? 0 : ( _arg > VTK_INT_MAX ? VTK_INT_MAX : _arg ) );
256  this->Modified();
257  this->URLMTime.Modified();
258  this->Close(); // Force a re-open on next query
259  }
260 }
261 
262 #endif // __vtkPostgreSQLDatabase_h