wxPg::Updatable_row Class Reference

Class for inserting, updating or deleting a single row in a table. More...

Inheritance diagram for wxPg::Updatable_row:

wxPg::Cached_row_provider wxPg::Data_row_provider

List of all members.

Classes

struct  col_data

Public Member Functions

 Updatable_row (Database *db)
 Constructor.
virtual ~Updatable_row ()
 Destructor.
void database (Database *db)
 Set database connection.
Databasedatabase ()
 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_


Detailed Description

Class for inserting, updating or deleting a single row in a table.


Constructor & Destructor Documentation

wxPg::Updatable_row::Updatable_row ( Database db  ) 

Constructor.

Parameters:
db - database connection.

virtual wxPg::Updatable_row::~Updatable_row (  )  [inline, virtual]

Destructor.


Member Function Documentation

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.

Parameters:
field - field name.
Returns:
0 - based column index, negative value for non existing field.

Implements wxPg::Data_row_provider.

virtual const wxString wxPg::Updatable_row::col_name ( int  idx  )  [virtual]

Get field name by column index.

Parameters:
idx - column index.
Returns:
field name for column idx.

Implements wxPg::Data_row_provider.

virtual int wxPg::Updatable_row::cols (  )  [virtual]

Get number of columns in a row.

Returns:
number of columns in a row.

Implements wxPg::Data_row_provider.

Database* wxPg::Updatable_row::database (  )  [inline]

Get database connection.

Returns:
database connection, used by this object.

void wxPg::Updatable_row::database ( Database db  )  [inline]

Set database connection.

Parameters:
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.

Returns:
true on success, false on error.

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.

Parameters:
idx - column index.
Returns:
string representation of column value.

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.

Returns:
true on success, false on error.

const wxString& wxPg::Updatable_row::last_err (  )  [inline]

Get last error.

Returns:
error message for 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.

Parameters:
condition - a condition for table. Should return only one row.
Returns:
true on success, false on error.

bool wxPg::Updatable_row::loaded (  )  const [inline]

Are fields loaded.

Returns:
true, if fields are loaded, false otherwise.

virtual bool wxPg::Updatable_row::null ( int  idx  )  [virtual]

Check if field value is NULL.

Parameters:
idx - column index.
Returns:
true if value is NULL or field not exists, false otherwise.

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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
field - fiend name.
value - value.

const wxString& wxPg::Updatable_row::table (  )  const [inline]

Get table.

Returns:
table name.

void wxPg::Updatable_row::table ( const wxString &  tab  )  [inline]

Set table to work with.

Parameters:
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.

Parameters:
idx - column index.
Returns:
one of types, defined in type.h.

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.

Parameters:
condition - a condition to be used instead of load condition.
Returns:
true on success, false on error.


Generated on Sat Sep 5 23:00:41 2009 for wxPostgres by  doxygen 1.5.8