Each wxRecordSet represents an ODBC database query. You can make multiple queries at a time by using multiple wxRecordSets with a wxDatabase or you can make your queries in sequential order using the same wxRecordSet.
Note: this class is considered obsolete, replaced by the Remstar wxDB/wxDbTable classes
Derived from
Include files
<wx/odbc.h>
See also
wxRecordSet overview, wxDatabase overview
Members
wxRecordSet::wxRecordSet
wxRecordSet::~wxRecordSet
wxRecordSet::AddNew
wxRecordSet::BeginQuery
wxRecordSet::BindVar
wxRecordSet::CanAppend
wxRecordSet::Cancel
wxRecordSet::CanRestart
wxRecordSet::CanScroll
wxRecordSet::CanTransact
wxRecordSet::CanUpdate
wxRecordSet::ConstructDefaultSQL
wxRecordSet::Delete
wxRecordSet::Edit
wxRecordSet::EndQuery
wxRecordSet::ExecuteSQL
wxRecordSet::FillVars
wxRecordSet::GetColName
wxRecordSet::GetColType
wxRecordSet::GetColumns
wxRecordSet::GetCurrentRecord
wxRecordSet::GetDatabase
wxRecordSet::GetDataSources
wxRecordSet::GetDefaultConnect
wxRecordSet::GetDefaultSQL
wxRecordSet::GetErrorCode
wxRecordSet::GetFieldData
wxRecordSet::GetFieldDataPtr
wxRecordSet::GetFilter
wxRecordSet::GetForeignKeys
wxRecordSet::GetNumberCols
wxRecordSet::GetNumberFields
wxRecordSet::GetNumberParams
wxRecordSet::GetNumberRecords
wxRecordSet::GetPrimaryKeys
wxRecordSet::GetOptions
wxRecordSet::GetResultSet
wxRecordSet::GetSortString
wxRecordSet::GetSQL
wxRecordSet::GetTableName
wxRecordSet::GetTables
wxRecordSet::GetType
wxRecordSet::GoTo
wxRecordSet::IsBOF
wxRecordSet::IsFieldDirty
wxRecordSet::IsFieldNull
wxRecordSet::IsColNullable
wxRecordSet::IsEOF
wxRecordSet::IsDeleted
wxRecordSet::IsOpen
wxRecordSet::Move
wxRecordSet::MoveFirst
wxRecordSet::MoveLast
wxRecordSet::MoveNext
wxRecordSet::MovePrev
wxRecordSet::Query
wxRecordSet::RecordCountFinal
wxRecordSet::Requery
wxRecordSet::SetFieldDirty
wxRecordSet::SetDefaultSQL
wxRecordSet::SetFieldNull
wxRecordSet::SetOptions
wxRecordSet::SetTableName
wxRecordSet::SetType
wxRecordSet::Update
wxRecordSet(wxDatabase *db, int type = wxOPEN_TYPE_DYNASET, int opt = wxOPTION_DEFAULT)
Constructor. db is a pointer to the wxDatabase instance you wish to use the wxRecordSet with. Currently there are two possible values of type:
The option parameter is not used yet.
The constructor appends the wxRecordSet object to the parent database's list of wxRecordSet objects, for later destruction when the wxDatabase is destroyed.
~wxRecordSet()
Destructor. All data except that stored in user-defined variables will be lost. It also unlinks the wxRecordSet object from the parent database's list of wxRecordSet objects.
void AddNew()
Not implemented.
bool BeginQuery(int openType, const wxString& sql = NULL, int options = wxOPTION_DEFAULT)
Not implemented.
void * BindVar(int col, void *buf, long size)
Binds a user-defined variable to the column col. Whenever the current field's data changes, it will be copied into buf (maximum size bytes).
void * BindVar(const wxString& col, void *buf, long size)
The same as above, but uses the column name as the identifier.
bool CanAppend()
Not implemented.
void Cancel()
Not implemented.
bool CanRestart()
Not implemented.
bool CanScroll()
Not implemented.
bool CanTransact()
Not implemented.
bool CanUpdate()
Not implemented.
bool ConstructDefaultSQL()
Not implemented.
bool Delete()
Deletes the current record. Not implemented.
void Edit()
Not implemented.
bool EndQuery()
Not implemented.
bool ExecuteSQL(const wxString& sql)
Directly executes a SQL statement. The data will be presented as a normal result set. Note that the recordset must have been created as a snapshot, not dynaset. Dynasets will be implemented in the near future.
Examples of common SQL statements are given in A selection of SQL commands.
void FillVars(int recnum)
Fills in the user-defined variables of the columns. You can set these variables with wxQueryCol::BindVar. This function will be automatically called after every successful database operation.
wxString GetColName(int col)
Returns the name of the column at position col. Returns NULL if col does not exist.
short GetColType(int col)
Returns the data type of the column at position col. Returns SQL_TYPE_NULL if col does not exist.
short GetColType(const wxString& name)
The same as above, but uses the column name as the identifier.
See ODBC SQL data types for a list of possible data types.
bool GetColumns(const wxString& table = NULL)
Returns the columns of the table with the specified name. If no name is given the class member tablename will be used. If both names are NULL nothing will happen. The data will be presented as a normal result set, organized as follows:
0 (VARCHAR) | TABLE_QUALIFIER |
1 (VARCHAR) | TABLE_OWNER |
2 (VARCHAR) | TABLE_NAME |
3 (VARCHAR) | COLUMN_NAME |
4 (SMALLINT) | DATA_TYPE |
5 (VARCHAR) | TYPE_NAME |
6 (INTEGER) | PRECISION |
7 (INTEGER) | LENGTH |
8 (SMALLINT) | SCALE |
9 (SMALLINT) | RADIX |
10 (SMALLINT) | NULLABLE |
11 (VARCHAR) | REMARKS |
long GetCurrentRecord()
Not implemented.
wxDatabase * GetDatabase()
Returns the wxDatabase object bound to a wxRecordSet.
bool GetDataSources()
Gets the currently-defined data sources via the ODBC manager. The data will be presented as a normal result set. See the documentation for the ODBC function SQLDataSources for how the data is organized.
Example:
wxDatabase Database; wxRecordSet *Record = new wxRecordSet(&Database); if (!Record->GetDataSources()) { char buf[300]; sprintf(buf, "%s %s\n", Database.GetErrorClass(), Database.GetErrorMessage()); frame->output->SetValue(buf); } else { do { frame->DataSource->Append((char*)Record->GetFieldDataPtr(0, SQL_CHAR)); } while (Record->MoveNext()); }
wxString GetDefaultConnect()
Not implemented.
wxString GetDefaultSQL()
Not implemented.
wxRETCODE GetErrorCode()
Returns the error code of the last ODBC action. 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. |
bool GetFieldData(int col, int dataType, void *dataPtr)
Copies the current data of the column at position col into the buffer dataPtr. To be sure to get the right type of data, the user has to pass the correct data type. The function returns FALSE if col does not exist or the wrong data type was given.
bool GetFieldData(const wxString& name, int dataType, void *dataPtr)
The same as above, but uses the column name as the identifier.
See ODBC SQL data types for a list of possible data types.
void * GetFieldDataPtr(int col, int dataType)
Returns the current data pointer of the column at position col. To be sure to get the right type of data, the user has to pass the data type. Returns NULL if col does not exist or if dataType is incorrect.
void * GetFieldDataPtr(const wxString& name, int dataType)
The same as above, but uses the column name as the identifier.
See ODBC SQL data types for a list of possible data types.
wxString GetFilter()
Returns the current filter.
bool GetPrimaryKeys(const wxString& ptable = NULL, const wxString& ftable = NULL)
Returns a list of foreign keys in the specified table (columns in the specified table that refer to primary keys in other tables), or a list of foreign keys in other tables that refer to the primary key in the specified table.
If ptable contains a table name, this function returns a result set containing the primary key of the specified table.
If ftable contains a table name, this functions returns a result set of containing all of the foreign keys in the specified table and the primary keys (in other tables) to which they refer.
If both ptable and ftable contain table names, this function returns the foreign keys in the table specified in ftable that refer to the primary key of the table specified in ptable. This should be one key at most.
GetForeignKeys returns results as a standard result set. If the foreign keys associated with a primary key are requested, the result set is ordered by FKTABLE_QUALIFIER, FKTABLE_OWNER, FKTABLE_NAME, and KEY_SEQ. If the primary keys associated with a foreign key are requested, the result set is ordered by PKTABLE_QUALIFIER, PKTABLE_OWNER, PKTABLE_NAME, and KEY_SEQ. The following table lists the columns in the result set.
0 (VARCHAR) | PKTABLE_QUALIFIER |
1 (VARCHAR) | PKTABLE_OWNER |
2 (VARCHAR) | PKTABLE_NAME |
3 (VARCHAR) | PKCOLUMN_NAME |
4 (VARCHAR) | FKTABLE_QUALIFIER |
5 (VARCHAR) | FKTABLE_OWNER |
6 (VARCHAR) | FKTABLE_NAME |
7 (VARCHAR) | FKCOLUMN_NAME |
8 (SMALLINT) | KEY_SEQ |
9 (SMALLINT) | UPDATE_RULE |
10 (SMALLINT) | DELETE_RULE |
11 (VARCHAR) | FK_NAME |
12 (VARCHAR) | PK_NAME |
long GetNumberCols()
Returns the number of columns in the result set.
int GetNumberFields()
Not implemented.
int GetNumberParams()
Not implemented.
long GetNumberRecords()
Returns the number of records in the result set.
bool GetPrimaryKeys(const wxString& table = NULL)
Returns the column names that comprise the primary key of the table with the specified name. If no name is given the class member tablename will be used. If both names are NULL nothing will happen. The data will be presented as a normal result set, organized as follows:
0 (VARCHAR) | TABLE_QUALIFIER |
1 (VARCHAR) | TABLE_OWNER |
2 (VARCHAR) | TABLE_NAME |
3 (VARCHAR) | COLUMN_NAME |
4 (SMALLINT) | KEY_SEQ |
5 (VARCHAR) | PK_NAME |
int GetOptions()
Returns the options of the wxRecordSet. Options are not supported yet.
bool GetResultSet()
Copies the data presented by ODBC into wxRecordSet. Depending on the wxRecordSet type all or only one record(s) will be copied. Usually this function will be called automatically after each successful database operation.
wxString GetSortString()
Not implemented.
wxString GetSQL()
Not implemented.
wxString GetTableName()
Returns the name of the current table.
bool GetTables()
Gets the tables of a database. The data will be presented as a normal result set, organized as follows:
0 (VARCHAR) | TABLE_QUALIFIER |
1 (VARCHAR) | TABLE_OWNER |
2 (VARCHAR) | TABLE_NAME |
3 (VARCHAR) | TABLE_TYPE (TABLE, VIEW, SYSTEM TABLE, GLOBAL TEMPORARY, LOCAL TEMPORARY, ALIAS, SYNONYM, or database-specific type) |
4 (VARCHAR) | REMARKS |
int GetType()
Returns the type of the wxRecordSet: wxOPEN_TYPE_DYNASET or wxOPEN_TYPE_SNAPSHOT. See the wxRecordSet description for details.
bool GoTo(long n)
Moves the cursor to the record with the number n, where the first record has the number 0.
bool IsBOF()
Returns TRUE if the user tried to move the cursor before the first record in the set.
bool IsFieldDirty(int field)
Returns TRUE if the given field has been changed but not saved yet.
bool IsFieldDirty(const wxString& name)
Same as above, but uses the column name as the identifier.
bool IsFieldNull(int field)
Returns TRUE if the given field has no data.
bool IsFieldNull(const wxString& name)
Same as above, but uses the column name as the identifier.
bool IsColNullable(int col)
Returns TRUE if the given column may contain no data.
bool IsColNullable(const wxString& name)
Same as above, but uses the column name as the identifier.
bool IsEOF()
Returns TRUE if the user tried to move the cursor behind the last record in the set.
bool IsDeleted()
Not implemented.
bool IsOpen()
Returns TRUE if the parent database is open.
bool Move(long rows)
Moves the cursor a given number of rows. Negative values are allowed.
bool MoveFirst()
Moves the cursor to the first record.
bool MoveLast()
Moves the cursor to the last record.
bool MoveNext()
Moves the cursor to the next record.
bool MovePrev()
Moves the cursor to the previous record.
bool Query(const wxString& columns, const wxString& table, const wxString& filter = NULL)
Start a query. An SQL string of the following type will automatically be generated and executed: "SELECT columns FROM table WHERE filter".
bool RecordCountFinal()
Not implemented.
bool Requery()
Re-executes the last query. Not implemented.
void SetFieldDirty(int field, bool dirty = TRUE)
Sets the dirty tag of the field field. Not implemented.
void SetFieldDirty(const wxString& name, bool dirty = TRUE)
Same as above, but uses the column name as the identifier.
void SetDefaultSQL(const wxString& s)
Not implemented.
void SetFieldNull(void *p, bool isNull = TRUE)
Not implemented.
void SetOptions(int opt)
Sets the options of the wxRecordSet. Not implemented.
void SetTableName(const wxString& tablename)
Specify the name of the table you want to use.
void SetType(int type)
Sets the type of the wxRecordSet. See the wxRecordSet class description for details.
bool Update()
Writes back the current record. Not implemented.