00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00048 #ifndef __vtkPostgreSQLDatabase_h
00049 #define __vtkPostgreSQLDatabase_h
00050
00051 #include "vtkSQLDatabase.h"
00052
00053 class vtkPostgreSQLQuery;
00054 class vtkStringArray;
00055 class vtkPostgreSQLDatabasePrivate;
00056 struct PQconn;
00057
00058 class VTK_IO_EXPORT vtkPostgreSQLDatabase : public vtkSQLDatabase
00059 {
00060
00061 friend class vtkPostgreSQLQuery;
00062 friend class vtkPostgreSQLQueryPrivate;
00063
00064
00065 public:
00066 vtkTypeMacro(vtkPostgreSQLDatabase, vtkSQLDatabase);
00067 void PrintSelf(ostream& os, vtkIndent indent);
00068 static vtkPostgreSQLDatabase *New();
00069
00073 bool Open( const char* password = 0 );
00074
00076 void Close();
00077
00079 bool IsOpen();
00080
00082 vtkSQLQuery* GetQueryInstance();
00083
00085 virtual bool HasError();
00086
00088 const char* GetLastErrorText();
00089
00091
00092 vtkGetStringMacro(DatabaseType);
00094
00096
00097 virtual void SetHostName( const char* );
00098 vtkGetStringMacro(HostName);
00100
00102
00103 virtual void SetUser( const char* );
00104 vtkGetStringMacro(User);
00106
00108 virtual void SetPassword( const char* );
00109
00111
00112 virtual void SetDatabaseName( const char* );
00113 vtkGetStringMacro(DatabaseName);
00115
00117
00118 virtual void SetConnectOptions( const char* );
00119 vtkGetStringMacro(ConnectOptions);
00121
00123
00124 virtual void SetServerPort( int );
00125 virtual int GetServerPortMinValue()
00126 {
00127 return 0;
00128 }
00129 virtual int GetServerPortMaxValue()
00130 {
00131 return VTK_INT_MAX;
00132 }
00133 vtkGetMacro(ServerPort, int);
00135
00141 virtual vtkStdString GetURL();
00142
00144 vtkStringArray* GetTables();
00145
00147 vtkStringArray* GetRecord( const char* table );
00148
00150 bool IsSupported( int feature );
00151
00153 vtkStringArray* GetDatabases();
00154
00158 bool CreateDatabase( const char* dbName, bool dropExisting = false );
00159
00162 bool DropDatabase( const char* dbName );
00163
00165
00169 virtual vtkStdString GetColumnSpecification(
00170 vtkSQLDatabaseSchema* schema, int tblHandle, int colHandle );
00172
00173 protected:
00174 vtkPostgreSQLDatabase();
00175 ~vtkPostgreSQLDatabase();
00176
00187 void UpdateDataTypeMap();
00188
00192 virtual bool ParseURL(const char* url);
00193
00194 vtkSetStringMacro(DatabaseType);
00195 vtkSetStringMacro(LastErrorText);
00196 void NullTrailingWhitespace( char* msg );
00197 bool OpenInternal( const char* connectionOptions );
00198
00199 vtkTimeStamp URLMTime;
00200 vtkPostgreSQLDatabasePrivate *Connection;
00201 vtkTimeStamp ConnectionMTime;
00202 vtkStringArray *Tables;
00203 char* DatabaseType;
00204 char* HostName;
00205 char* User;
00206 char* Password;
00207 char* DatabaseName;
00208 int ServerPort;
00209 char* ConnectOptions;
00210 char* LastErrorText;
00211
00212 private:
00213 vtkPostgreSQLDatabase( const vtkPostgreSQLDatabase& );
00214 void operator = ( const vtkPostgreSQLDatabase& );
00215 };
00216
00217
00218
00219
00220 #define vtkSetStringPlusMTimeMacro(className,name,timeStamp) \
00221 inline void className::Set##name (const char* _arg) \
00222 { \
00223 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg?_arg:"(null)") ); \
00224 if ( this->name == NULL && _arg == NULL) { return;} \
00225 if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \
00226 if (this->name) { delete [] this->name; } \
00227 if (_arg) \
00228 { \
00229 size_t n = strlen(_arg) + 1; \
00230 char *cp1 = new char[n]; \
00231 const char *cp2 = (_arg); \
00232 this->name = cp1; \
00233 do { *cp1++ = *cp2++; } while ( --n ); \
00234 } \
00235 else \
00236 { \
00237 this->name = NULL; \
00238 } \
00239 this->Modified(); \
00240 this->timeStamp.Modified(); \
00241 this->Close(); \
00242 }
00243
00244 vtkSetStringPlusMTimeMacro(vtkPostgreSQLDatabase,HostName,URLMTime);
00245 vtkSetStringPlusMTimeMacro(vtkPostgreSQLDatabase,User,URLMTime);
00246 vtkSetStringPlusMTimeMacro(vtkPostgreSQLDatabase,Password,URLMTime);
00247 vtkSetStringPlusMTimeMacro(vtkPostgreSQLDatabase,DatabaseName,URLMTime);
00248 vtkSetStringPlusMTimeMacro(vtkPostgreSQLDatabase,ConnectOptions,URLMTime);
00249
00250 inline void vtkPostgreSQLDatabase::SetServerPort( int _arg )
00251 {
00252 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting ServerPort to " << _arg );
00253 if ( this->ServerPort != ( _arg < 0 ? 0 : ( _arg > VTK_INT_MAX ? VTK_INT_MAX : _arg ) ) )
00254 {
00255 this->ServerPort = ( _arg < 0 ? 0 : ( _arg > VTK_INT_MAX ? VTK_INT_MAX : _arg ) );
00256 this->Modified();
00257 this->URLMTime.Modified();
00258 this->Close();
00259 }
00260 }
00261
00262 #endif // __vtkPostgreSQLDatabase_h