## wxDatabase

Every database object represents an ODBC connection. The connection may be closed and reopened.

Derived from

wxObject

Include files

<wx/odbc.h>

See also

wxDatabase overview, wxRecordSet

A much more robust and feature-rich set of ODBC classes is now available and recommended for use in place of the wxDatabase class.

See details of these classes in: wxDB, wxDbTable

Members

wxDatabase::wxDatabase
wxDatabase::~wxDatabase
wxDatabase::BeginTrans
wxDatabase::Cancel
wxDatabase::CanTransact
wxDatabase::CanUpdate
wxDatabase::Close
wxDatabase::CommitTrans
wxDatabase::ErrorOccured
wxDatabase::ErrorSnapshot
wxDatabase::GetDatabaseName
wxDatabase::GetDataSource
wxDatabase::GetErrorClass
wxDatabase::GetErrorCode
wxDatabase::GetErrorMessage
wxDatabase::GetErrorNumber
wxDatabase::GetHDBC
wxDatabase::GetHENV
wxDatabase::GetInfo
wxDatabase::GetPassword
wxDatabase::GetUsername
wxDatabase::GetODBCVersionFloat
wxDatabase::GetODBCVersionString
wxDatabase::InWaitForDataSource
wxDatabase::IsOpen
wxDatabase::Open
wxDatabase::OnSetOptions
wxDatabase::OnWaitForDataSource
wxDatabase::RollbackTrans
wxDatabase::SetDataSource
wxDatabase::SetLoginTimeout
wxDatabase::SetPassword
wxDatabase::SetSynchronousMode
wxDatabase::SetQueryTimeout
wxDatabase::SetUsername

### wxDatabase::wxDatabase

wxDatabase()

Constructor. The constructor of the first wxDatabase instance of an application initializes the ODBC manager.

### wxDatabase::~wxDatabase

~wxDatabase()

Destructor. Resets and destroys any associated wxRecordSet instances.

The destructor of the last wxDatabase instance will deinitialize the ODBC manager.

### wxDatabase::BeginTrans

bool BeginTrans()

Not implemented.

### wxDatabase::Cancel

void Cancel()

Not implemented.

### wxDatabase::CanTransact

bool CanTransact()

Not implemented.

### wxDatabase::CanUpdate

bool CanUpdate()

Not implemented.

### wxDatabase::Close

bool Close()

Resets the statement handles of any associated wxRecordSet objects, and disconnects from the current data source.

### wxDatabase::CommitTrans

bool CommitTrans()

Commits previous transactions. Not implemented.

### wxDatabase::ErrorOccured

bool ErrorOccured()

Returns TRUE if the last action caused an error.

### wxDatabase::ErrorSnapshot

void ErrorSnapshot(HSTMT statement = SQL_NULL_HSTMT)

This function will be called whenever an ODBC error occured. It stores the error related information returned by ODBC. If a statement handle of the concerning ODBC action is available it should be passed to the function.

### wxDatabase::GetDatabaseName

wxString GetDatabaseName()

Returns the name of the database associated with the current connection.

### wxDatabase::GetDataSource

wxString GetDataSource()

Returns the name of the connected data source.

### wxDatabase::GetErrorClass

wxString GetErrorClass()

Returns the error class of the last error. The error class consists of five characters where the first two characters contain the class and the other three characters contain the subclass of the ODBC error. See ODBC documentation for further details.

### wxDatabase::GetErrorCode

wxRETCODE GetErrorCode()

Returns the error code of the last ODBC function call. This will be one of:

SQL_ERROR | General error.
SQL_INVALID_HANDLE | An invalid handle was passed to an ODBC function.
SQL_NEED_DATA | ODBC expected some data.
SQL_NO_DATA_FOUND | No data was found by this ODBC call.
SQL_SUCCESS | The call was successful.
SQL_SUCCESS_WITH_INFO | The call was successful, but further information can be obtained from the ODBC manager.

### wxDatabase::GetErrorMessage

wxString GetErrorMessage()

Returns the last error message returned by the ODBC manager.

### wxDatabase::GetErrorNumber

long GetErrorNumber()

Returns the last native error. A native error is an ODBC driver dependent error number.

### wxDatabase::GetHDBC

HDBC GetHDBC()

Returns the current ODBC database handle.

### wxDatabase::GetHENV

HENV GetHENV()

Returns the ODBC environment handle.

### wxDatabase::GetInfo

bool GetInfo(long infoType, long *buf)

bool GetInfo(long infoType, const wxString& buf, int bufSize=-1)

Returns requested information. The return value is TRUE if successful, FALSE otherwise.

infoType is an ODBC identifier specifying the type of information to be returned.

buf is a character or long integer pointer to storage which must be allocated by the application, and which will contain the information if the function is successful.

bufSize is the size of the character buffer. A value of -1 indicates that the size should be computed by the GetInfo function.

### wxDatabase::GetPassword

wxString GetPassword()

Returns the password of the current user.

### wxDatabase::GetUsername

wxString GetUsername()

Returns the current username.

### wxDatabase::GetODBCVersionFloat

float GetODBCVersionFloat(bool implementation=TRUE)

Returns the version of ODBC in floating point format, e.g. 2.50.

implementation should be TRUE to get the DLL version, or FALSE to get the version defined in the `sql.h` header file.

This function can return the value 0.0 if the header version number is not defined (for early versions of ODBC).

### wxDatabase::GetODBCVersionString

wxString GetODBCVersionString(bool implementation=TRUE)

Returns the version of ODBC in string format, e.g. "02.50".

implementation should be TRUE to get the DLL version, or FALSE to get the version defined in the `sql.h` header file.

This function can return the value "00.00" if the header version number is not defined (for early versions of ODBC).

### wxDatabase::InWaitForDataSource

bool InWaitForDataSource()

Not implemented.

### wxDatabase::IsOpen

bool IsOpen()

Returns TRUE if a connection is open.

### wxDatabase::Open

bool Open(const wxString& datasource, bool exclusive = FALSE, bool readOnly = TRUE, const wxString& username = "ODBC", const wxString& password = "")

Connect to a data source. datasource contains the name of the ODBC data source. The parameters exclusive and readOnly are not used.

### wxDatabase::OnSetOptions

void OnSetOptions(wxRecordSet *recordSet)

Not implemented.

### wxDatabase::OnWaitForDataSource

void OnWaitForDataSource(bool stillExecuting)

Not implemented.

### wxDatabase::RollbackTrans

bool RollbackTrans()

Sends a rollback to the ODBC driver. Not implemented.

### wxDatabase::SetDataSource

void SetDataSource(const wxString& s)

Sets the name of the data source. Not implemented.

### wxDatabase::SetLoginTimeout

void SetLoginTimeout(long seconds)

Sets the time to wait for an user login. Not implemented.

### wxDatabase::SetPassword

void SetPassword(const wxString& s)

Sets the password of the current user. Not implemented.

### wxDatabase::SetSynchronousMode

void SetSynchronousMode(bool synchronous)

Toggles between synchronous and asynchronous mode. Currently only synchronous mode is supported, so this function has no effect.

### wxDatabase::SetQueryTimeout

void SetQueryTimeout(long seconds)

Sets the time to wait for a response to a query. Not implemented.

### wxDatabase::SetUsername

void SetUsername(const wxString& s)

Sets the name of the current user. Not implemented.