00001 /* Name: wx/wxPostgreSQL.h 00002 * Purpose: connect to PostgreSQL database. 00003 * Sever version: 8.3 00004 * Author: Trần Ngọc Quân 00005 * Modified by: 00006 * Created: 20/10/2010 00007 * RCS-ID: 00008 * Copyright: (c) 2010 wxPostgreSQL team 00009 * Licence: GPL 00010 */ 00011 #ifndef WX_POSTGRESQL_H 00012 #define WX_POSTGRESQL_H 00013 #if !WX_PRECOMP 00014 #include <wx/wx.h> 00015 #else 00016 // basic wxWidgets headers 00017 #include <wx/wxprec.h> 00018 #endif 00019 #include <libpq-fe.h> 00020 00021 typedef ConnStatusType wxConnStatusType; 00022 typedef PostgresPollingStatusType wxPostgresPollingStatusType; 00023 typedef ExecStatusType wxExecStatusType; 00024 typedef PGTransactionStatusType wxPGTransactionStatusType; 00025 typedef PGVerbosity wxVerbosity; 00026 typedef PGconn wxPGconn; 00027 typedef PGresult wxResult; 00028 typedef PGcancel wxPGcancel; 00029 typedef PGnotify wxPGnotify; 00030 typedef PQprintOpt wxPrintOpt; 00031 typedef PQconninfoOption wxConninfoOption; 00032 typedef PQArgBlock wxArgBlock; 00033 typedef PQnoticeReceiver wxNoticeReceiver; 00034 typedef PQnoticeProcessor wxNoticeProcessor; 00035 typedef pgthreadlock_t wxpgthreadlock_t; 00036 typedef Oid wxOid; 00037 00038 class wxPostgreSQLresult; 00039 00041 class wxPostgreSQL 00042 { 00043 public: 00045 wxPostgreSQL(); 00047 wxPostgreSQL(const wxPostgreSQL& pq); 00049 wxPostgreSQL(char* const constr); 00051 wxPostgreSQL(const wxString& constr); 00053 wxPostgreSQL(const char *pghost, 00054 const char *pgport, 00055 const char *pgoptions, 00056 const char *pgtty, 00057 const char *dbName, 00058 const char *login, 00059 const char *pwd); 00061 wxPostgresPollingStatusType ConnectPoll(); 00063 void Finish(); 00065 static wxConninfoOption* ConnDefaults(); 00067 void ConninfoFree(); 00069 int ResetStart(); 00071 wxPostgresPollingStatusType ResetPoll(); 00073 void Reset(); 00075 wxPGcancel* GetCancel(); 00077 static void FreeCancel(wxPGcancel *cancel); 00079 static int Cancel(wxPGcancel *cancel, char *errbuf, int errbufsize); 00081 int RequestCancel(); 00082 00083 /* Accessor functions for PGconn objects */ 00085 char* GetDatabaseName(); 00087 char* GetUserName(); 00089 char* GetPassword(); 00091 char* GetHost(); 00093 char* GetPort(); 00095 char* GetTTY(); 00097 char* Options(); 00099 wxConnStatusType Status(); 00101 wxPGTransactionStatusType TransactionStatus(); 00103 const char* ParameterStatus(const char* paramName); 00105 int ProtocolVersion()const; 00107 int ServerVersion()const; 00109 char* ErrorMessage() const; 00111 int Socket(); 00113 int BackendPID(); 00115 int IsNeedsPassword(); 00117 int IsUsedPassword(); 00119 int GetClientEncoding(); 00121 int SetClientEncoding(const char *encoding); 00122 00125 void* GetSSL(); 00126 00128 static void InitSSL(int do_init); 00129 00131 wxVerbosity SetErrorVerbosity(wxVerbosity verbosity); 00132 00134 void Trace(FILE *debug_port); 00136 void UnTrace(); 00137 00138 /* Override default notice handling routines */ 00140 wxNoticeReceiver SetNoticeReceiver(wxNoticeReceiver proc, void *arg); 00142 wxNoticeProcessor SetNoticeProcessor(wxNoticeProcessor proc, void *arg); 00144 static pgthreadlock_t RegisterThreadLock(pgthreadlock_t newhandler); 00146 wxPostgreSQLresult* Execute(const char *query); 00148 wxPostgreSQLresult* Execute(const wxString& query); 00150 wxPostgreSQLresult* ExecuteParams(const char *command, 00151 int nParams, 00152 const wxOid *paramTypes, 00153 const char *const * paramValues, 00154 const int *paramLengths, 00155 const int *paramFormats, 00156 int resultFormat); 00158 wxPostgreSQLresult* Prepare(const char *stmtName, 00159 const char *query, 00160 int nParams, 00161 const wxOid *paramTypes); 00163 wxPostgreSQLresult* ExecutePrepared(const char *stmtName, 00164 int nParams, 00165 const char *const * paramValues, 00166 const int *paramLengths, 00167 const int *paramFormats, 00168 int resultFormat); 00169 00171 int SendQuery(const char *query); 00173 int SendQueryParams(const char *command, 00174 int nParams, 00175 const wxOid *paramTypes, 00176 const char *const * paramValues, 00177 const int *paramLengths, 00178 const int *paramFormats, 00179 int resultFormat); 00181 int SendPrepare(const char *stmtName, 00182 const char *query, 00183 int nParams, 00184 const Oid *paramTypes); 00186 int SendQueryPrepared(const char *stmtName, 00187 int nParams, 00188 const char *const * paramValues, 00189 const int *paramLengths, 00190 const int *paramFormats, 00191 int resultFormat); 00193 wxPostgreSQLresult* GetResult(); 00194 00196 int IsBusy(); 00198 int ConsumeInput(); 00199 00201 wxPGnotify* Notifies(); 00202 00204 int PutCopyData(const char *buffer, int nbytes); 00206 int PutCopyEnd(const char *errormsg); 00207 00209 int GetCopyData(char **buffer, int async); 00211 int Getline(char *string, int length); 00213 int Putline(const char *string); 00215 int GetlineAsync(char *buffer, int bufsize); 00217 int PutnBytes(const char *buffer, int nbytes); 00219 int EndCopy(); 00220 00222 int SetNonBlocking(int arg); 00224 int IsNonBlocking(); 00226 static int IsThreadSafe(); 00227 00229 int Flush(); 00230 00232 wxPostgreSQLresult* fn(int fnid, 00233 int *result_buf, 00234 int *result_len, 00235 int result_is_int, 00236 const wxArgBlock *args, 00237 int nargs); 00239 wxPostgreSQLresult* DescribePrepared(const char *stmt); 00241 wxPostgreSQLresult* DescribePortal(const char *portal); 00243 int SendDescribePrepared(const char *stmt); 00245 int SendDescribePortal(const char *portal); 00246 00248 static void FreeMemory(void *ptr); 00249 00251 wxPostgreSQLresult* MakeEmptyResult(ExecStatusType status); 00252 00254 size_t EscapeStringConn(char *to, const char *from, size_t length, int *error); 00256 unsigned char* EscapeByteaConn(const unsigned char *from, size_t from_length, size_t *to_length); 00258 static unsigned char* EscapeBytea(const unsigned char *from, size_t from_length, size_t *to_length); 00260 unsigned char* UnescapeBytea(const unsigned char *strtext, size_t *retbuflen); 00261 00263 static size_t EscapeString(char *to, const char *from, size_t length); 00264 00265 /* === in fe-lobj.c === */ 00266 /* Large-object access routines */ 00268 int lo_open(wxOid lobjId, int mode); 00270 int lo_close(int fd); 00272 int lo_read(int fd, char *buf, size_t len); 00274 int lo_write(int fd, const char *buf, size_t len); 00276 int lo_lseek(int fd, int offset, int whence); 00278 wxOid lo_creat(int mode); 00280 wxOid lo_create(wxOid lobjId); 00282 int lo_tell(int fd); 00284 int lo_truncate(int fd, size_t len); 00286 int lo_unlink(wxOid lobjId); 00288 wxOid lo_import(const char *filename); 00290 int lo_export(wxOid lobjId, const char *filename); 00291 00292 /* === in fe-misc.c === */ 00294 static int mblen(const char *s, int encoding); 00295 00297 static int dsplen(const char *s, int encoding); 00298 00300 static int env2encoding(); 00301 00302 /* === in fe-auth.c === */ 00304 static char* EncryptPassword(const char *passwd, const char *user); 00305 00306 /* === in encnames.c === */ 00307 00309 static int char2encoding(const char *name); 00311 static const char* encoding2char(int encoding); 00313 static int valid_server_encoding_id(int encoding); 00315 ~wxPostgreSQL(); 00316 00317 private: 00318 00319 char* conninfo; 00320 wxPGconn* conn; 00321 wxConninfoOption* connOptions; 00322 }; 00323 //End of declaration wxPostgreSQL class 00324 00326 class wxPostgreSQLresult 00327 { 00328 public: 00330 wxPostgreSQLresult(); 00332 wxPostgreSQLresult(wxResult* res); 00334 ~wxPostgreSQLresult(); 00336 wxExecStatusType Status(); 00338 void Clear(); 00340 char* StatusMessage(wxExecStatusType status); 00342 char* ErrorMessage(); 00344 char* ErrorFieldMessage(int fieldcode); 00346 int GetNumberRows(); 00348 int GetNumberFields(); 00350 int IsBinary(); 00352 char* FieldName(int field_num); 00354 int FieldNumber(const char *field_name); 00356 wxOid FieldTable(int field_num); 00358 int FieldTableColumn(int field_num); 00360 int FieldFormat(int field_num); 00362 wxOid FieldType(int field_num); 00364 int FieldSize(int field_num); 00366 int FieldModifier(int field_num); 00368 char* CommandStatus(); 00370 char* OIDStatus(); /* old and ugly */ 00372 wxOid OIDValue(); /* new and improved */ 00374 char* CommandNumberRows(); 00376 char* GetValue(int tup_num, int field_num); 00378 int GetLength(int tup_num, int field_num); 00380 int IsNull(int tup_num, int field_num); 00382 int NumberParams(); 00384 wxOid ParamType(int param_num); 00386 void Print(FILE *fout, /* output stream */ 00387 const wxPrintOpt *ps); /* option structure */ 00389 void DisplayRows(FILE *fp, /* where to send the output */ 00390 int fillAlign, /* pad the fields with spaces */ 00391 const char *fieldSep, /* field separator */ 00392 int printHeader, /* display headers? */ 00393 int quiet); 00394 00396 void PrintRows(FILE *fout, /* output stream */ 00397 int printAttName, /* print attribute names */ 00398 int terseOutput, /* delimiter bars */ 00399 int width); /* width of column, if 0, use variable width */ 00400 00401 protected: 00402 00403 private: 00404 wxResult* res; 00405 00406 }; 00407 00408 #endif // End wxPostgreSQL.h
Page generated on Wed Nov 24 2010 13:29:49 by Doxygen 1.7.2 Copyleft wxPostgreSQL 2010 All rights reserved |
[ top ] |