gSAFE  1.3.8
Public Member Functions | Friends | List of all members
HDataChangeLogger Class Reference

#include <datalib.h>

Inheritance diagram for HDataChangeLogger:
HSqlHandler HSqlInterface HBase

Public Member Functions

 HDataChangeLogger (HTable *logtable, QString startpos=GSAFETEXT_UNKNOWN, QString startuser=GSAFETEXT_UNKNOWN)
 ~HDataChangeLogger (void)
void setPos (QString pos)
void setPosAndUser (QString pos, QString user)
void setUser (QString user)
- Public Member Functions inherited from HSqlHandler
 HSqlHandler (void)
 ~HSqlHandler (void)
QSqlQuery * allocateQSqlQuery (void)
void cloneSqlSettingsFrom (HSqlHandler *other)
void commit (void)
bool errorStatus (void)
void rollback (void)
bool submit0ResultQuery (QString q, QString err, bool tdisabled=false)
QVariant submit1ResultQuery (QString q, QString err, bool tdisabled=false)
HPlainDataMatrixsubmitNResultQuery (int N, QString q, QString err, bool tdisabled=false)
void transaction (void)
QSqlDatabase workDB (void)
- Public Member Functions inherited from HSqlInterface
 HSqlInterface ()
 ~HSqlInterface ()
void cloneSqlInterfaceSettingsFrom (HSqlInterface *other)
HSqlSingleInterfacemyInterface (void)
QString sqlConcatenateToLocal (QString string)
QString sqlConcatenateToLocal (QStringList fields)
- Public Member Functions inherited from HBase
 HBase (void)
 ~HBase (void)
QString getWhoami (void)


class HDataField
class HTable

Additional Inherited Members

- Signals inherited from HSqlHandler
void errorSignal (QString err)
- Static Public Member Functions inherited from HSqlHandler
static void setCustomSqlDatabase (QString databaseName, QString sqlinterfacename="")
static void setDefaultSqlDatabase (void)
- Static Public Member Functions inherited from HSqlInterface
static HSqlSingleInterfacecurrentDefaultSqlInterface (void)
static HSqlSingleInterfacegetSqlInterface (QString interfacename)
static void setSqlMode (QString modename)
static void setSqlModeBackToFirst (void)
- Static Public Attributes inherited from HSqlHandler
static int trans = 0
- Protected Attributes inherited from HSqlHandler
bool query_error_occured
- Protected Attributes inherited from HBase
QString whoami

Detailed Description

HDataChangeLogger is an object which can automatically log the data changes of a HTable into a separated sql table. Useful to store the history of a sql data table.
Every data field in a table has an attribute "logged". If this "logged" attribute is true and the HTable has a valid HDataChangeLogger object set, every real data modifications is automatically logged to an sql table.
(See HDataField::setLogging() and HDataField::resetLogging() to set the "logged" attribute.
And see HTable::setDataChangeLogger() and HTable::clearDataChangeLogger() to set this logger in a HTable)

You have to create a HTable instance which define the log sql table, and pass this HTable * to the HDataChangeLogger
The table has to have the following fields:

The table can contains any explain text, modifiers, comments or even more data fields.
An example log table (HFactory XML format):

<element name="datachange_log_table">
<table sqln="dclog">
<key sqln="dclkey">
<smalltext sqln="pos">
<explain>Position of changing</explain>
<smalltext sqln="cuser">
<smalltext sqln="sqltablename">
<explain>Sql table name which changed</explain>
<smalltext sqln="changedkey">
<explain>The changed records key</explain>
<smalltext sqln="sqlfieldname">
<explain>Sql field name which changed</explain>
<smalltext sqln="oldvalue">
<explain>The old value</explain>
<smalltext sqln="newvalue">
<explain>The new value</explain>
<timestamp sqln="changetime">
<explain>The changing time</explain>

Here is an example function of using this code in program. I have a mytable which is generated by the HFactory. I will edit this mytable ("t" variable) and I set up the logger to work on it. (Use the example XML above)
This function is edit (And optionally modify/log) a mytable record with "key"

int editMytableItem(QString key)
int result=0;
HTable *t = myfactory->genHTable("mytable"); //reads the mytable meta
HTable *logger_table = myfactory->genHTable("datachange_log_table"); //reads the logger meta
// You can create the table struct with logger_table->sqlCreateString() function
//We set the logger
HDataChangeLogger *logger = new HDataChangeLogger(logger_table,"editMytableItem","user");
//We create an edit dialog
HDialog *dialog = new HDialog(this,tr("Edit my table..."),t,NULL,
tr("Modify the item"),tr("Modify"),tr("Cancel"),NULL);
//Reads the current state of the record
//Executes the previously created dialog
//If the dialog accepted, store the new values. (If some changed, the logger
//automatically store the changes to the log table
if(t->saveRecord() != 0)
//error occured
delete logger;
delete logger_table;
delete dialog;
delete t;
return result;

Of course you can create and set this logger object outer of this function. You can set the changed position and the user name everytime with the setPos() and setUser() functions.

Definition at line 3639 of file datalib.h.

Constructor & Destructor Documentation

HDataChangeLogger::HDataChangeLogger ( HTable logtable,
QString  startpos = GSAFETEXT_UNKNOWN,
QString  startuser = GSAFETEXT_UNKNOWN 

Creates a HDataChangeLogger object.

logtablethe log table. See class details. It does not deleted on exit!
startposthe initial position (optional)
startuserthe currently active user (optional)

Definition at line 7553 of file datalib.cpp.

HDataChangeLogger::~HDataChangeLogger ( void  )

It deletes the HDataChangeLogger. You have to delete the HTable which reference this object before or call clearDataChangeLogger() before you delete it.

Definition at line 7630 of file datalib.cpp.

Member Function Documentation

void HDataChangeLogger::setPos ( QString  pos)

Sets the currently actual modification position

Definition at line 3659 of file datalib.h.

void HDataChangeLogger::setPosAndUser ( QString  pos,
QString  user 

Sets the currently actual modification position and user

Definition at line 3657 of file datalib.h.

void HDataChangeLogger::setUser ( QString  user)

Sets the currently actual user

Definition at line 3661 of file datalib.h.

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