Classes | |
struct | col_data |
Public Member Functions | |
Updatable_row (Database *db) | |
Constructor. | |
virtual | ~Updatable_row () |
Destructor. | |
void | database (Database *db) |
Set database connection. | |
Database * | database () |
Get database connection. | |
bool | loaded () const |
Are fields loaded. | |
virtual int | cols () |
Get number of columns in a row. | |
virtual const wxString | col_name (int idx) |
Get field name by column index. | |
virtual int | col_idx (const wxString &field) |
Get column index by name. | |
virtual int | type_simple (int idx) |
Returns type of column (for built in types only). | |
virtual bool | null (int idx) |
Check if field value is NULL. | |
virtual const wxString | get_str (int idx) |
Returns column value as wxString. | |
void | set_value (const wxString &field, int value) |
Set field value. | |
void | set_value (const wxString &field, double value) |
Set field value. | |
void | set_value (const wxString &field, const wxString &value) |
Set field value. | |
void | set_value (const wxString &field, const wxDateTime &value) |
Set field value. | |
void | set_date (const wxString &field, const wxDateTime &value) |
Set field value as date. | |
void | set_time (const wxString &field, const wxDateTime &value) |
Set field value as time. | |
void | set_bool (const wxString &field, bool value) |
Set field value. | |
void | set_null (const wxString &field) |
Set field to NULL. | |
void | set_type_simple (const wxString &field, int type) |
Set type for field. | |
virtual void | clear () |
Clear any defined fields. | |
void | table (const wxString &tab) |
Set table to work with. | |
const wxString & | table () const |
Get table. | |
virtual bool | load (const wxString &condition=wxEmptyString) |
Load data from database. | |
virtual void | unload () |
Remove any loaded information and data. | |
const wxString & | last_err () |
Get last error. | |
virtual bool | insert () |
Insert row to database. | |
virtual bool | update (const wxString &condition=wxEmptyString) |
Update row in database. | |
virtual bool | delete_record () |
Delete row from database. | |
Protected Attributes | |
wxString | last_err_ |
wxPg::Updatable_row::Updatable_row | ( | Database * | db | ) |
Constructor.
db | - database connection. |
virtual wxPg::Updatable_row::~Updatable_row | ( | ) | [inline, virtual] |
Destructor.
virtual void wxPg::Updatable_row::clear | ( | ) | [virtual] |
Clear any defined fields.
If fields are loaded, they are all set to NULL. Otherwise fields are removed from list.
virtual int wxPg::Updatable_row::col_idx | ( | const wxString & | field | ) | [virtual] |
Get column index by name.
field | - field name. |
Implements wxPg::Data_row_provider.
virtual const wxString wxPg::Updatable_row::col_name | ( | int | idx | ) | [virtual] |
Get field name by column index.
idx | - column index. |
Implements wxPg::Data_row_provider.
virtual int wxPg::Updatable_row::cols | ( | ) | [virtual] |
Get number of columns in a row.
Implements wxPg::Data_row_provider.
Database* wxPg::Updatable_row::database | ( | ) | [inline] |
Get database connection.
void wxPg::Updatable_row::database | ( | Database * | db | ) | [inline] |
Set database connection.
db | - database connection. |
virtual bool wxPg::Updatable_row::delete_record | ( | ) | [virtual] |
Delete row from database.
Deletes currenly loaded row from database. If an error occurs, call last_err() to get message for it.
virtual const wxString wxPg::Updatable_row::get_str | ( | int | idx | ) | [virtual] |
Returns column value as wxString.
If value is NULL and in case of error empty string is returned.
idx | - column index. |
Implements wxPg::Data_row_provider.
virtual bool wxPg::Updatable_row::insert | ( | ) | [virtual] |
Insert row to database.
Currently cached row is inserted to database. If an error occurs, call last_err() to get message for it.
const wxString& wxPg::Updatable_row::last_err | ( | ) | [inline] |
Get last error.
virtual bool wxPg::Updatable_row::load | ( | const wxString & | condition = wxEmptyString |
) | [virtual] |
Load data from database.
If condition is empty or there are no rows for it, only column definitions are loaded. Otherwise a first row for a condition is loaded.
If an error occurs, call last_err() to get message for it.
condition | - a condition for table. Should return only one row. |
bool wxPg::Updatable_row::loaded | ( | ) | const [inline] |
Are fields loaded.
virtual bool wxPg::Updatable_row::null | ( | int | idx | ) | [virtual] |
Check if field value is NULL.
idx | - column index. |
Implements wxPg::Data_row_provider.
void wxPg::Updatable_row::set_bool | ( | const wxString & | field, | |
bool | value | |||
) |
Set field value.
If fields are loaded, only an existing field can be set. Otherwise a field is added, if it does not exist.
Also sets field type to TYPE_BOOL.
field | - fiend name. | |
value | - value. |
void wxPg::Updatable_row::set_date | ( | const wxString & | field, | |
const wxDateTime & | value | |||
) |
Set field value as date.
If fields are loaded, only an existing field can be set. Otherwise a field is added, if it does not exist.
Also sets field type to TYPE_DATE.
field | - fiend name. | |
value | - value. |
void wxPg::Updatable_row::set_null | ( | const wxString & | field | ) |
Set field to NULL.
If fields are loaded, only an existing field can be set. Otherwise a field is added, if it does not exist.
If new field is added, its type is set to TYPE_UNKNOWN.
field | - fiend name. |
void wxPg::Updatable_row::set_time | ( | const wxString & | field, | |
const wxDateTime & | value | |||
) |
Set field value as time.
If fields are loaded, only an existing field can be set. Otherwise a field is added, if it does not exist.
Also sets field type to TYPE_TIME.
field | - fiend name. | |
value | - value. |
void wxPg::Updatable_row::set_type_simple | ( | const wxString & | field, | |
int | type | |||
) |
Set type for field.
If fields are loaded, only an existing field can be set. Otherwise a field is added, if it does not exist.
If new field is added, ist value is set to NULL.
Field value is set to NULL, if value is not acceptable for new type.
For fields with type TYPE_UNKNOWN, a string value is passed varbatim to database.
field | - field name. | |
type | - data type for field. |
void wxPg::Updatable_row::set_value | ( | const wxString & | field, | |
const wxDateTime & | value | |||
) |
Set field value.
If fields are loaded, only an existing field can be set. Otherwise a field is added, if it does not exist.
Note, that this sets field type to TYPE_TIMESTAMP. Use set_time or set_date for only date or time.
field | - fiend name. | |
value | - value. |
void wxPg::Updatable_row::set_value | ( | const wxString & | field, | |
const wxString & | value | |||
) |
Set field value.
If fields are loaded, only an existing field can be set. Otherwise a field is added, if it does not exist.
Also sets field type to TYPE_STRING.
field | - fiend name. | |
value | - value. |
void wxPg::Updatable_row::set_value | ( | const wxString & | field, | |
double | value | |||
) |
Set field value.
If fields are loaded, only an existing field can be set. Otherwise a field is added, if it does not exist.
Also sets field type to TYPE_FLOAT.
field | - fiend name. | |
value | - value. |
void wxPg::Updatable_row::set_value | ( | const wxString & | field, | |
int | value | |||
) |
Set field value.
If fields are loaded, only an existing field can be set. Otherwise a field is added, if it does not exist.
Also sets field type to TYPE_INT.
field | - fiend name. | |
value | - value. |
const wxString& wxPg::Updatable_row::table | ( | ) | const [inline] |
Get table.
void wxPg::Updatable_row::table | ( | const wxString & | tab | ) | [inline] |
Set table to work with.
tab | - table name. |
virtual int wxPg::Updatable_row::type_simple | ( | int | idx | ) | [virtual] |
Returns type of column (for built in types only).
If type of column is not built in or there is no column whith such index, wxPg::TYPE_UNKNOWN is returned. See type.h.
idx | - column index. |
Implements wxPg::Data_row_provider.
virtual void wxPg::Updatable_row::unload | ( | ) | [virtual] |
Remove any loaded information and data.
virtual bool wxPg::Updatable_row::update | ( | const wxString & | condition = wxEmptyString |
) | [virtual] |
Update row in database.
Currenly cached row is updated in database. Condition for update is eighter passed as argument, or is used the same, that was used when loading row. It is users responsibility to ensure, that only one row in table matches condition.
If an error occurs, call last_err() to get message for it.
condition | - a condition to be used instead of load condition. |