Public Member Functions | Static Public Member Functions

wxPostgreSQL Class Reference

#include <wxPostgreSQL.h>

List of all members.

Public Member Functions

 wxPostgreSQL ()
 wxPostgreSQL (const wxPostgreSQL &pq)
 wxPostgreSQL (char *const constr)
 wxPostgreSQL (const wxString &constr)
 wxPostgreSQL (const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, const char *dbName, const char *login, const char *pwd)
wxPostgresPollingStatusType ConnectPoll ()
void Finish ()
void ConninfoFree ()
int ResetStart ()
wxPostgresPollingStatusType ResetPoll ()
void Reset ()
wxPGcancel * GetCancel ()
int RequestCancel ()
char * GetDatabaseName ()
char * GetUserName ()
char * GetPassword ()
char * GetHost ()
char * GetPort ()
char * GetTTY ()
char * Options ()
wxConnStatusType Status ()
wxPGTransactionStatusType TransactionStatus ()
const char * ParameterStatus (const char *paramName)
int ProtocolVersion () const
int ServerVersion () const
char * ErrorMessage () const
int Socket ()
int BackendPID ()
int IsNeedsPassword ()
int IsUsedPassword ()
int GetClientEncoding ()
int SetClientEncoding (const char *encoding)
void * GetSSL ()
wxVerbosity SetErrorVerbosity (wxVerbosity verbosity)
void Trace (FILE *debug_port)
void UnTrace ()
wxNoticeReceiver SetNoticeReceiver (wxNoticeReceiver proc, void *arg)
wxNoticeProcessor SetNoticeProcessor (wxNoticeProcessor proc, void *arg)
wxPostgreSQLresultExecute (const char *query)
wxPostgreSQLresultExecute (const wxString &query)
wxPostgreSQLresultExecuteParams (const char *command, int nParams, const wxOid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
wxPostgreSQLresultPrepare (const char *stmtName, const char *query, int nParams, const wxOid *paramTypes)
wxPostgreSQLresultExecutePrepared (const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
int SendQuery (const char *query)
int SendQueryParams (const char *command, int nParams, const wxOid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
int SendPrepare (const char *stmtName, const char *query, int nParams, const Oid *paramTypes)
int SendQueryPrepared (const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
wxPostgreSQLresultGetResult ()
int IsBusy ()
int ConsumeInput ()
wxPGnotify * Notifies ()
int PutCopyData (const char *buffer, int nbytes)
int PutCopyEnd (const char *errormsg)
int GetCopyData (char **buffer, int async)
int Getline (char *string, int length)
int Putline (const char *string)
int GetlineAsync (char *buffer, int bufsize)
int PutnBytes (const char *buffer, int nbytes)
int EndCopy ()
int SetNonBlocking (int arg)
int IsNonBlocking ()
int Flush ()
wxPostgreSQLresultfn (int fnid, int *result_buf, int *result_len, int result_is_int, const wxArgBlock *args, int nargs)
wxPostgreSQLresultDescribePrepared (const char *stmt)
wxPostgreSQLresultDescribePortal (const char *portal)
int SendDescribePrepared (const char *stmt)
int SendDescribePortal (const char *portal)
wxPostgreSQLresultMakeEmptyResult (ExecStatusType status)
size_t EscapeStringConn (char *to, const char *from, size_t length, int *error)
unsigned char * EscapeByteaConn (const unsigned char *from, size_t from_length, size_t *to_length)
unsigned char * UnescapeBytea (const unsigned char *strtext, size_t *retbuflen)
int lo_open (wxOid lobjId, int mode)
int lo_close (int fd)
int lo_read (int fd, char *buf, size_t len)
int lo_write (int fd, const char *buf, size_t len)
int lo_lseek (int fd, int offset, int whence)
wxOid lo_creat (int mode)
wxOid lo_create (wxOid lobjId)
int lo_tell (int fd)
int lo_truncate (int fd, size_t len)
int lo_unlink (wxOid lobjId)
wxOid lo_import (const char *filename)
int lo_export (wxOid lobjId, const char *filename)
 ~wxPostgreSQL ()

Static Public Member Functions

static wxConninfoOption * ConnDefaults ()
static void FreeCancel (wxPGcancel *cancel)
static int Cancel (wxPGcancel *cancel, char *errbuf, int errbufsize)
static void InitSSL (int do_init)
static pgthreadlock_t RegisterThreadLock (pgthreadlock_t newhandler)
static int IsThreadSafe ()
static void FreeMemory (void *ptr)
static unsigned char * EscapeBytea (const unsigned char *from, size_t from_length, size_t *to_length)
static size_t EscapeString (char *to, const char *from, size_t length)
static int mblen (const char *s, int encoding)
static int dsplen (const char *s, int encoding)
static int env2encoding ()
static char * EncryptPassword (const char *passwd, const char *user)
static int char2encoding (const char *name)
static const char * encoding2char (int encoding)
static int valid_server_encoding_id (int encoding)

Detailed Description

This is a object that keep connect to PostgreSQL


Constructor & Destructor Documentation

wxPostgreSQL::wxPostgreSQL (  )

Default contructor. This action will set conninfo=""

wxPostgreSQL::wxPostgreSQL ( const wxPostgreSQL pq )

Copy contructor

wxPostgreSQL::wxPostgreSQL ( char *const   constr )

Contructor with connected string

wxPostgreSQL::wxPostgreSQL ( const wxString &  constr )

Contructor with connected wxString

wxPostgreSQL::wxPostgreSQL ( const char *  pghost,
const char *  pgport,
const char *  pgoptions,
const char *  pgtty,
const char *  dbName,
const char *  login,
const char *  pwd 
)

Connect with full parameter

wxPostgreSQL::~wxPostgreSQL (  )

Default Destructor


Member Function Documentation

int wxPostgreSQL::BackendPID (  )

Returns the process ID (PID) of the backend server process handling this connection.

static int wxPostgreSQL::Cancel ( wxPGcancel *  cancel,
char *  errbuf,
int  errbufsize 
) [static]

issue a cancel request

static int wxPostgreSQL::char2encoding ( const char *  name ) [static]

Return encoding from name in string format

static wxConninfoOption* wxPostgreSQL::ConnDefaults (  ) [static]

Returns the default connection options.

wxPostgresPollingStatusType wxPostgreSQL::ConnectPoll (  )

Make a connection to the database server in a nonblocking manner.

void wxPostgreSQL::ConninfoFree (  )

free the data structure returned by ConnDefaults()

int wxPostgreSQL::ConsumeInput (  )

If input is available from the server, consume it.

wxPostgreSQLresult* wxPostgreSQL::DescribePortal ( const char *  portal )

Submits a request to obtain information about the specified portal, and waits for completion.

wxPostgreSQLresult* wxPostgreSQL::DescribePrepared ( const char *  stmt )

Submits a request to obtain information about the specified prepared statement, and waits for completion.

static int wxPostgreSQL::dsplen ( const char *  s,
int  encoding 
) [static]

Determine display length of multibyte encoded char at *s

static const char* wxPostgreSQL::encoding2char ( int  encoding ) [static]

Return name of encoding

static char* wxPostgreSQL::EncryptPassword ( const char *  passwd,
const char *  user 
) [static]

Prepares the encrypted form of a PostgreSQL password.

int wxPostgreSQL::EndCopy (  )

Synchronizes with the server.

static int wxPostgreSQL::env2encoding (  ) [static]

Get encoding id from environment variable PGCLIENTENCODING

char* wxPostgreSQL::ErrorMessage (  ) const

Returns the error message most recently generated by an operation on the connection.

static unsigned char* wxPostgreSQL::EscapeBytea ( const unsigned char *  from,
size_t  from_length,
size_t *  to_length 
) [static]

EscapeBytea is an older, deprecated version of EscapeByteaConn.

unsigned char* wxPostgreSQL::EscapeByteaConn ( const unsigned char *  from,
size_t  from_length,
size_t *  to_length 
)

Escapes binary data for use within an SQL command with the type bytea. As with EscapeStringConn, this is only used when inserting data directly into an SQL command string.

static size_t wxPostgreSQL::EscapeString ( char *  to,
const char *  from,
size_t  length 
) [static]

EscapeStringConn returns the number of bytes written to to, not including the terminating zero byte.

size_t wxPostgreSQL::EscapeStringConn ( char *  to,
const char *  from,
size_t  length,
int *  error 
)

EscapeStringConn escapes a string for use within an SQL command. This is useful when inserting data values as literal constants in SQL commands. Certain characters (such as quotes and backslashes) must be escaped to prevent them from being interpreted specially by the SQL parser. EscapeStringConn performs this operation.

wxPostgreSQLresult* wxPostgreSQL::Execute ( const char *  query )

Submits a command to the server and waits for the result.

wxPostgreSQLresult* wxPostgreSQL::Execute ( const wxString &  query )

Submits a command to the server and waits for the result.

wxPostgreSQLresult* wxPostgreSQL::ExecuteParams ( const char *  command,
int  nParams,
const wxOid *  paramTypes,
const char *const *  paramValues,
const int *  paramLengths,
const int *  paramFormats,
int  resultFormat 
)

Submits a command to the server and waits for the result, with the ability to pass parameters separately from the SQL command text.

wxPostgreSQLresult* wxPostgreSQL::ExecutePrepared ( const char *  stmtName,
int  nParams,
const char *const *  paramValues,
const int *  paramLengths,
const int *  paramFormats,
int  resultFormat 
)

Sends a request to execute a prepared statement with given parameters, and waits for the result.

void wxPostgreSQL::Finish (  )

Close the current connection and free the data of wxPostgreSQL

int wxPostgreSQL::Flush (  )

Attempts to flush any queued output data to the server. Returns 0 if successful (or if the send queue is empty), -1 if it failed for some reason, or 1 if it was unable to send all the data in the send queue yet (this case can only occur if the connection is nonblocking).

wxPostgreSQLresult* wxPostgreSQL::fn ( int  fnid,
int *  result_buf,
int *  result_len,
int  result_is_int,
const wxArgBlock *  args,
int  nargs 
)

The function fn requests execution of a server function via the fast-path interface:

static void wxPostgreSQL::FreeCancel ( wxPGcancel *  cancel ) [static]

free a cancel structure

static void wxPostgreSQL::FreeMemory ( void *  ptr ) [static]

Frees memory allocated by libpq

wxPGcancel* wxPostgreSQL::GetCancel (  )

request a cancel structure

int wxPostgreSQL::GetClientEncoding (  )

Returns the client encoding.

int wxPostgreSQL::GetCopyData ( char **  buffer,
int  async 
)

Receives data from the server during COPY_OUT state.

char* wxPostgreSQL::GetDatabaseName (  )

Returns the database name of the connection.

char* wxPostgreSQL::GetHost (  )

Returns the server host name of the connection.

int wxPostgreSQL::Getline ( char *  string,
int  length 
)

Reads a newline-terminated line of characters (transmitted by the server) into a buffer string of size length.

int wxPostgreSQL::GetlineAsync ( char *  buffer,
int  bufsize 
)

Reads a row of COPY data (transmitted by the server) into a buffer without blocking.

char* wxPostgreSQL::GetPassword (  )

Returns the password of the connection.

char* wxPostgreSQL::GetPort (  )

Returns the port of the connection.

wxPostgreSQLresult* wxPostgreSQL::GetResult (  )

Waits for the next result from a prior SendQuery, SendQueryParams, SendPrepare, or SendQueryPrepared call, and returns it. A null pointer is returned when the command is complete and there will be no more results.

void* wxPostgreSQL::GetSSL (  )

Get the OpenSSL structure associated with a connection. Returns NULL for unencrypted connections or if any other TLS library is in use.

char* wxPostgreSQL::GetTTY (  )

Returns the debug TTY of the connection. (This is obsolete, since the server no longer pays attention to the TTY setting, but the function remains for backwards compatibility.)

char* wxPostgreSQL::GetUserName (  )

Returns the user name of the connection.

static void wxPostgreSQL::InitSSL ( int  do_init ) [static]

Tell libpq whether it needs to initialize OpenSSL

int wxPostgreSQL::IsBusy (  )

Returns 1 if a command is busy, that is, GetResult would block waiting for input. A 0 return indicates that GetResult can be called with assurance of not blocking.

int wxPostgreSQL::IsNeedsPassword (  )

Returns true (1) if the connection authentication method used a caller-supplied password. Returns false (0) if not.

int wxPostgreSQL::IsNonBlocking (  )

Returns the blocking status of the database connection.

static int wxPostgreSQL::IsThreadSafe (  ) [static]

Returns the thread safety status of the libpq library.

int wxPostgreSQL::IsUsedPassword (  )

Returns true (1) if the connection authentication method used a caller-supplied password. Returns false (0) if not.

int wxPostgreSQL::lo_close ( int  fd )

A large object descriptor can be closed by calling

wxOid wxPostgreSQL::lo_creat ( int  mode )

creates a new large object. The return value is the OID that was assigned to the new large object, or InvalidOid (zero) on failure. mode is unused and ignored as of PostgreSQL 8.1; however, for backwards compatibility with earlier releases it is best to set it to INV_READ, INV_WRITE, or INV_READ | INV_WRITE. (These symbolic constants are defined in the header file libpq/libpq-fs.h.)

wxOid wxPostgreSQL::lo_create ( wxOid  lobjId )

also creates a new large object. The OID to be assigned can be specified by lobjId; if so, failure occurs if that OID is already in use for some large object. If lobjId is InvalidOid (zero) then lo_create assigns an unused OID (this is the same behavior as lo_creat). The return value is the OID that was assigned to the new large object, or InvalidOid (zero) on failure.

int wxPostgreSQL::lo_export ( wxOid  lobjId,
const char *  filename 
)

To export a large object into an operating system file, call

wxOid wxPostgreSQL::lo_import ( const char *  filename )

To import an operating system file as a large object, call

int wxPostgreSQL::lo_lseek ( int  fd,
int  offset,
int  whence 
)

This function moves the current location pointer for the large object descriptor identified by fd to the new location specified by offset. The valid values for whence are SEEK_SET (seek from object start), SEEK_CUR (seek from current position), and SEEK_END (seek from object end). The return value is the new location pointer, or -1 on error.

int wxPostgreSQL::lo_open ( wxOid  lobjId,
int  mode 
)

To open an existing large object for reading or writing, call

int wxPostgreSQL::lo_read ( int  fd,
char *  buf,
size_t  len 
)

reads len bytes from large object descriptor fd into buf. The fd argument must have been returned by a previous lo_open. The number of bytes actually read is returned. In the event of an error, the return value is negative.

int wxPostgreSQL::lo_tell ( int  fd )

To obtain the current read or write location of a large object descriptor, call

int wxPostgreSQL::lo_truncate ( int  fd,
size_t  len 
)

truncates the large object descriptor fd to length len. The fd argument must have been returned by a previous lo_open. If len is greater than the current large object length, the large object is extended with null bytes ('\0').

int wxPostgreSQL::lo_unlink ( wxOid  lobjId )

To remove a large object from the database, call

int wxPostgreSQL::lo_write ( int  fd,
const char *  buf,
size_t  len 
)

writes len bytes from buf to large object descriptor fd. The fd argument must have been returned by a previous lo_open. The number of bytes actually written is returned. In the event of an error, the return value is negative.

wxPostgreSQLresult* wxPostgreSQL::MakeEmptyResult ( ExecStatusType  status )

Constructs an empty PGresult object with the given status.

static int wxPostgreSQL::mblen ( const char *  s,
int  encoding 
) [static]

Determine length of multibyte encoded char at *s

wxPGnotify* wxPostgreSQL::Notifies (  )

The function Notifies returns the next notification from a list of unhandled notification messages received from the server. It returns a null pointer if there are no pending notifications. Once a notification is returned from Notifies, it is considered handled and will be removed from the list of notifications.

char* wxPostgreSQL::Options (  )

Returns the command-line options passed in the connection request.

const char* wxPostgreSQL::ParameterStatus ( const char *  paramName )

Looks up a current parameter setting of the server.

wxPostgreSQLresult* wxPostgreSQL::Prepare ( const char *  stmtName,
const char *  query,
int  nParams,
const wxOid *  paramTypes 
)

Submits a request to create a prepared statement with the given parameters, and waits for completion.

int wxPostgreSQL::ProtocolVersion (  ) const

Interrogates the frontend/backend protocol being used.

int wxPostgreSQL::PutCopyData ( const char *  buffer,
int  nbytes 
)

Sends data to the server during COPY_IN state.

int wxPostgreSQL::PutCopyEnd ( const char *  errormsg )

Sends end-of-data indication to the server during COPY_IN state.

int wxPostgreSQL::Putline ( const char *  string )

Sends a null-terminated string to the server. Returns 0 if OK and EOF if unable to send the string.

int wxPostgreSQL::PutnBytes ( const char *  buffer,
int  nbytes 
)

Sends a non-null-terminated string to the server. Returns 0 if OK and EOF if unable to send the string.

static pgthreadlock_t wxPostgreSQL::RegisterThreadLock ( pgthreadlock_t  newhandler ) [static]

a way to do cooperative locking between libpq and your application

int wxPostgreSQL::RequestCancel (  )

backwards compatible version of Cancel; not thread-safe

void wxPostgreSQL::Reset (  )

Synchronous (blocking)

wxPostgresPollingStatusType wxPostgreSQL::ResetPoll (  )

Reset the communication channel to the server, in a nonblocking manner.

int wxPostgreSQL::ResetStart (  )

Reset the communication channel to the server, in a nonblocking manner.

int wxPostgreSQL::SendDescribePortal ( const char *  portal )

Submits a request to obtain information about the specified portal, without waiting for completion.

int wxPostgreSQL::SendDescribePrepared ( const char *  stmt )

Submits a request to obtain information about the specified prepared statement, without waiting for completion.

int wxPostgreSQL::SendPrepare ( const char *  stmtName,
const char *  query,
int  nParams,
const Oid *  paramTypes 
)

Sends a request to create a prepared statement with the given parameters, without waiting for completion.

int wxPostgreSQL::SendQuery ( const char *  query )

Submits a command to the server without waiting for the result(s). 1 is returned if the command was successfully dispatched and 0 if not (in which case, use ErrorMessage to get more information about the failure).

int wxPostgreSQL::SendQueryParams ( const char *  command,
int  nParams,
const wxOid *  paramTypes,
const char *const *  paramValues,
const int *  paramLengths,
const int *  paramFormats,
int  resultFormat 
)

Submits a command and separate parameters to the server without waiting for the result(s).

int wxPostgreSQL::SendQueryPrepared ( const char *  stmtName,
int  nParams,
const char *const *  paramValues,
const int *  paramLengths,
const int *  paramFormats,
int  resultFormat 
)

Sends a request to execute a prepared statement with given parameters, without waiting for the result(s).

int wxPostgreSQL::ServerVersion (  ) const

Returns an integer representing the backend version.

int wxPostgreSQL::SetClientEncoding ( const char *  encoding )

Sets the client encoding.

wxVerbosity wxPostgreSQL::SetErrorVerbosity ( wxVerbosity  verbosity )

Set verbosity for ErrorMessage and ResultErrorMessage

int wxPostgreSQL::SetNonBlocking ( int  arg )

Sets the nonblocking status of the connection.

wxNoticeProcessor wxPostgreSQL::SetNoticeProcessor ( wxNoticeProcessor  proc,
void *  arg 
)

SetNoticeProcessor sets or examines the current notice processor.

wxNoticeReceiver wxPostgreSQL::SetNoticeReceiver ( wxNoticeReceiver  proc,
void *  arg 
)

The function SetNoticeReceiver sets or examines the current notice receiver for a connection object.

int wxPostgreSQL::Socket (  )

Obtains the file descriptor number of the connection socket to the server. A valid descriptor will be greater than or equal to 0; a result of -1 indicates that no server connection is currently open. (This will not change during normal operation, but could change during connection setup or reset.)

wxConnStatusType wxPostgreSQL::Status (  )

Returns the status of the connection. Value are: CONNECTION_OK, CONNECTION_BAD, CONNECTION_STARTED, CONNECTION_MADE, CONNECTION_AWAITING_RESPONSE, CONNECTION_AUTH_OK, CONNECTION_SETENV, CONNECTION_SSL_STARTUP, CONNECTION_NEEDED

void wxPostgreSQL::Trace ( FILE *  debug_port )

Enable tracing

wxPGTransactionStatusType wxPostgreSQL::TransactionStatus (  )

Returns the current in-transaction status of the server. Value are: PQTRANS_IDLE, PQTRANS_ACTIVE, PQTRANS_INTRANS, PQTRANS_INERROR, PQTRANS_UNKNOWN

unsigned char* wxPostgreSQL::UnescapeBytea ( const unsigned char *  strtext,
size_t *  retbuflen 
)

Converts a string representation of binary data into binary data — the reverse of EscapeBytea. This is needed when retrieving bytea data in text format, but not when retrieving it in binary format.

void wxPostgreSQL::UnTrace (  )

Disable tracing

static int wxPostgreSQL::valid_server_encoding_id ( int  encoding ) [static]

Check if encoding is valid from server


The documentation for this class was generated from the following file:



free counters

[ top ]