gSAFE  1.3.8
Public Slots | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
HTable Class Reference

#include <datalib.h>

Inheritance diagram for HTable:
HTableBase HSqlHandler HSqlInterface HBase

Public Slots

int disableReadonlyMask (void)
 
int enableReadonlyMask (void)
 
QString getInsertedKey (void)
 
int insertRecord (bool insertkey=false, bool disable_tr=false, bool resetafterinsert=true)
 
int insertRecordAll (bool disable_tr=false)
 
void rereadNextInsertedKey (void)
 
int returnToDefault (bool all=true)
 
int saveRecord (bool all=false, bool tdisabled=false)
 
int saveRecordAll (bool tdisabled=false)
 
int setKey (QString key)
 
int updateWithKey (QString key="", bool all=false, bool update=true, bool tdisabled=false)
 
int updateWithKeyAll (QString key="", bool update=true, bool tdisabled=false)
 
- Public Slots inherited from HTableBase
void addDependTableName (QString n)
 
int errorPassSlot (QString err)
 

Public Member Functions

 HTable (QString t)
 
 HTable (HTable *t)
 
 ~HTable (void)
 
void blockReInitialize (QString hide_marker, QString ro_marker)
 
void clearDataChangeLogger (void)
 
void deepcopy_from_htable (HTable *x)
 
QString getKey (bool head_val, QString intable="")
 
QVariant getSqlFieldValue (QString sqln)
 
QVariant operator[] (int i)
 
bool readonlyMask (void)
 
int recordCount (void)
 
void setDataChangeLogger (HDataChangeLogger *dcl)
 
void setSqlFieldValue (QString sqln, QVariant v, bool sdisable=false)
 
QString sqlInsert (bool insertkey=false)
 
QString sqlInsertAll (void)
 
QString sqlUpdate (bool all=false)
 
QString sqlUpdateAll (void)
 
- Public Member Functions inherited from HTableBase
 HTableBase (QString t)
 
 HTableBase (HTableBase *t)
 
 ~HTableBase (void)
 
void addField (HDataField *i)
 
void blockReInitializeBase (QString hide_marker, QString ro_marker)
 
void clearAndFreeConnections (void)
 
void clearConnections (void)
 
void clearRoles (void)
 
void clearSqlSynced (void)
 
void connectTable (HTableBase *ct, int type=INNER_JOIN, QString connconstraint="")
 
void connectTable (HTableBase *ct, QString thiskey, QString thatkey, int type=INNER_JOIN, QString connconstraint="")
 
void dataUpdated (void)
 
void deepcopy_from_htablebase (HTableBase *x)
 
void delRole (QString name)
 
HDataFieldfieldByIndex (int i, bool all=false)
 
HDataFieldfieldBySqlName (QString sqln, bool all=false, QString containerSqlTable="")
 
int fieldCount (bool withconnect=false)
 
void firstField (void)
 
void freeTable (void)
 
QStringList getExplainHeads (void)
 
QStringList getHeads (int what)
 
QStringList getShortTitleHeads (void)
 
bool isChanged (bool all=false)
 
bool isReallyChanged (void)
 
HDataFieldnextField (void)
 
HDataFieldnextFieldAll (void)
 
QVariant operator[] (int i)
 
void removeSqlCooseButtons (void)
 
void resetLogging (void)
 
void returnToDefaultAllMarked (QString mark)
 
void setAllNOSet (void)
 
void setAllYESSet (void)
 
void setColor (int r, int g, int b)
 
void setColorAllMarked (QString mark, int r, int g, int b)
 
void setEditable (void)
 
void setEditableAllMarked (QString mark)
 
void setGuiDisabledAllMarked (QString mark)
 
void setGuiEnabledAllMarked (QString mark)
 
void setHide (void)
 
void setHideAllMarked (QString mark)
 
void setLogging (void)
 
void setLoggingAllMarked (QString mark)
 
void setReadolnyAllMarked (QString mark)
 
void setReadonly (void)
 
void setShow (void)
 
void setShowAllMarked (QString mark)
 
void setTableTitle (QString s)
 
QString sqlCreateString (QString switches="")
 
QString sqlSelect (QString tail="", bool all=false, bool keypart=false)
 
QString sqlSelectAll (QString tail="")
 
QString sqlSelectWk (QString tail="", bool all=false)
 
QString sqlSelectWkAll (QString tail="")
 
void sqlSynced (HDataChangeLogger *dclog=NULL, bool forcechange=false, bool forcelog=false)
 
QString sqlTableName (void)
 
HDataFieldstaticFieldByTitle (QString title="")
 
QString tableTitle (void)
 
void useRole (QString name)
 
QString validate (bool all=true)
 
- 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)
 

Protected Member Functions

QString getKeyValueAfterInsert (void)
 
QString specifyKey (QString tablename)
 

Protected Attributes

HDataChangeLoggerdclog
 
QString insertedKey
 
bool reread_key
 
bool ro_mask
 
- Protected Attributes inherited from HTableBase
QString conn_part
 
QStack< HTableBase * > * connectedTableBases
 
QStringList * depend
 
int field
 
QString imc_thatkey
 
HTableBaseimc_thattable
 
QString imc_thiskey
 
HDataField_List * run
 
QString sqlTable
 
HDataField_List * table
 
QString tabletitle
 
- Protected Attributes inherited from HSqlHandler
bool query_error_occured
 
- Protected Attributes inherited from HBase
QString whoami
 

Additional Inherited Members

- Signals inherited from HTableBase
void dataChanged (void)
 
void dataModifiedSignal (void)
 
void dataUpdatedSignal (void)
 
void doWorking (void)
 
void endWorking (void)
 
void startWorking (void)
 
- 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)
 
- Public Attributes inherited from HTableBase
QString errstr
 
bool extrafeatures
 
bool gui_showtabletitle
 
- Static Public Attributes inherited from HSqlHandler
static int trans = 0
 

Detailed Description

The HTable class is handle/store an sql record. Holds a meta-record of the meta table with values.
This is the base read-write sql related class which can be used to edit the sql data.
However this class usally hold only a record, its name is "HTable" because the usual appearance:

htable.png

This record can be a whole sql table record or a subset of a sql record or can contain more field. (by join, calculated data,static data etc...)
Here every field (of the HTableBase) can store a value. This is a record or a record of a joined table system. This record can be read/store/reload/edited with this class.

Here is an sql table:

CREATE TABLE excerc
(
id VARCHAR PRIMARY KEY,
excer VARCHAR,
finished BOOLEAN DEFAULT FALSE,
price NUMERIC DEFAULT 0,
deadline DATE
);

And the correspond HTable: (You can see the XML format in HFactory calss description)

HTable *table = new HTable("excerc");
table->addField(new HKey("id","Identifier","Id",""));
table->addField(new HLargeText("excer","Task to do","Task","")->asColored(200,100,100));
table->addField(new HCheck("finished","Finished","Finished","",
"false","Yes, It is done!","No, it is unfinished."));
table->addField(new HNumber("price","Cost","Cost","usd",""));
table->addField(new HDate("deadline","Deadline","Deadline","NOW",false,false));

The HTable is showed by HDispTable in gui, looks like this way:

hdisptable.png
See Also
HTableBase

Definition at line 1350 of file datalib.h.

Constructor & Destructor Documentation

HTable::HTable ( QString  t)

Creates an empty table. The created table don't contain any data field and don't have any connections.

Parameters
tthe sql name of the table.

Definition at line 3096 of file datalib.cpp.

HTable::~HTable ( void  )

Destructor

Definition at line 3106 of file datalib.cpp.

HTable::HTable ( HTable t)

Deepcopy constructor. It clones the parameter HTable to itself. It copies the full data structure and state and attributes and values of the parameter table. But connected tables is not copied neither the connection data. Only the base table is copied! If you would like to copy a whole connected table you have to copy the tables one by one, and connect them again.

Parameters
tthe source table

Definition at line 3113 of file datalib.cpp.

Member Function Documentation

void HTable::blockReInitialize ( QString  hide_marker,
QString  ro_marker 
)

Equivalent calling the following functions:

Which is equivalent to call:

Parameters
hide_markerthe text HIDE_MARKER_PARAMETER
ro_markerthe text RO_MARKER_PARAMETER
See Also
returnToDefault
blockReInitializeBase

Definition at line 3938 of file datalib.cpp.

void HTable::clearDataChangeLogger ( void  )
inline

Clears the data change logger object to the HTable. It's disables the logging data changes to an sql table. It does not delete the given object

See Also
HDataChangeLogger

Definition at line 1466 of file datalib.h.

void HTable::deepcopy_from_htable ( HTable x)

Deepcopy function. It clones the parameter HTable to itself. It copies the full data structure and state and attributes and values of the parameter table. But connected tables is not copied neither the connection data. Only the base table is copied! If you would like to copy a whole connected table you have to copy the tables one by one, and connect them again.

Parameters
xthe source table

Definition at line 3121 of file datalib.cpp.

int HTable::disableReadonlyMask ( void  )
inlineslot

Disables the read only mask of the table. You can set a read only mask to the table which is tell the gui to show the whole table in read only mode. If the read only mask is enable the whole table will be read only irrespectively of the status of the read_only value of the fields. The independent read only value of the fields are untouched. So this read only mask DOES NOT MODIFY THE READ ONLY STATUS OF THE FIELDS!
Useful to show a read only view from a memory instance of an editable table.

See Also
enableReadonlyMask
readonlyMask

Definition at line 1577 of file datalib.h.

int HTable::enableReadonlyMask ( void  )
inlineslot

Enables the read only mask of the table. You can set a read only mask to the table which is tell the gui to show the whole table in read only mode. If the read only mask is enable the whole table will be read only irrespectively of the status of the read_only value of the fields. The independent read only value of the fields are untouched. So this read only mask DOES NOT MODIFY THE READ ONLY STATUS OF THE FIELDS!
Useful to show a read only view from a memory instance of an editable table.

See Also
disableReadonlyMask
readonlyMask

Definition at line 1568 of file datalib.h.

QString HTable::getInsertedKey ( void  )
inlineslot

Gets the value of the HKey field immediatly after the insert command. The method is queries the value of the HKey field. It queries the key value according to the value of timestamp.
THE RECORD/TABLE HAVE TO CONTAINS A TIMESTAMP FIELD TO WORK THIS FUNCTION CORRECTLY.
The timestamp field have to enabled the check/controll option. This function need to be run in one sql transaction with the insert. You have to run the rereadNextInsertedKey() before the insert.

...
HTable *mytable=...
QString key;
...
mytable->transaction();
if(mytable->insertRecord(false,true) == 0) //success
{
key = mytable->getInsertedKey();
mytable->commit();
}
else //error
{
mytable->rollback();
...
}
...

It only works with insertRecord() , the insertRecordAll() is unsupported!

Definition at line 1550 of file datalib.h.

QString HTable::getKey ( bool  head_val,
QString  intable = "" 
)

Returns of the header string/value of the key field of the record.

Parameters
head_valIf true the function returns the sql name of the key field If false the functionr returns the value of the key field
intableAct as a filter. If a table name is specified the key field is searched only that table which named in this parameter

Definition at line 3249 of file datalib.cpp.

QVariant HTable::getSqlFieldValue ( QString  sqln)

Returns the value of the specified field of the record

Parameters
sqlnthe sql name of the field which is about to query
Returns
the requested value

Definition at line 3141 of file datalib.cpp.

int HTable::insertRecord ( bool  insertkey = false,
bool  disable_tr = false,
bool  resetafterinsert = true 
)
slot

Inserts the current (in memory) record to the sql database. Inserts the values of the HConnect fields too.

Parameters
insertkeyif true the function will inserts the value of the HKey field too, otherwise (false) the key field is does not appear in the insert command. Useful if the key field is autogenerated.
disable_trif this parameter false the insert runs in a separate transaction so the function starts a transaction and to a commit after its, otherwise (true) the function doesn't call any transaction related things.
resetafterinsertif this true (default) the HTable calls returnToDefault() after a successfully insert.
Returns
0 if success, 1 if error occured
See Also
insertRecordAll()

Definition at line 3548 of file datalib.cpp.

int HTable::insertRecordAll ( bool  disable_tr = false)
slot

Inserts the current (in memory) record to the sql database. This function inserts the connected tables too. The function drops the values of the HConnect fields because it's filled during the connections.

Parameters
disable_trif this parameter false the insert runs in a separate transaction so the function starts a transaction and to a commit after its, otherwise (true) the function doesn't call any transaction related things.
Returns
0 if success, 1 if error occured
See Also
insertRecord()

Definition at line 3614 of file datalib.cpp.

QVariant HTable::operator[] ( int  i)

Returns the (in memory) value of the specified field.

Parameters
ithe index of the requested field.

Definition at line 3231 of file datalib.cpp.

bool HTable::readonlyMask ( void  )
inline

Returns the current status of the read only mask of the table. You can set a read only mask to the table which is tell the gui to show the whole table in read only mode. If the read only mask is enable the whole table will be read only irrespectively of the status of the read_only value of the fields. The independent read only value of the fields are untouched.
So this read only mask! DOES NOT MODIFY THE READ ONLY STATUS OF THE FIELDS! Useful to show a read only view from a memory instance of an editable table.

See Also
enableReadonlyMask
disableReadonlyMask

Definition at line 1440 of file datalib.h.

int HTable::recordCount ( void  )
inline

Returns the number of records in this table (It's always 1 in HTable because the HTable only represent one record )

Definition at line 1470 of file datalib.h.

void HTable::rereadNextInsertedKey ( void  )
inlineslot

The inserted key value will be queryied after the insert

See Also
getInsertedKey()

Definition at line 1553 of file datalib.h.

int HTable::returnToDefault ( bool  all = true)
slot

Sets the values to the data fields to the default. Useful to run after the insert (before inserting a new element)

Parameters
allif true the function works on connected tables too

Definition at line 3378 of file datalib.cpp.

int HTable::saveRecord ( bool  all = false,
bool  tdisabled = false 
)
slot

Store the (in memory) record to the sql database according to the key value of the HKey field.

Parameters
allstore the connected tables too
tdisabledif this parameter false the save runs in a separate transaction so the function starts a transaction and to a commit after its, otherwise (true) the function doesn't call any transaction related things.
Returns
0 if success, 1 if error occured
See Also
saveRecordAll()

Definition at line 3403 of file datalib.cpp.

int HTable::saveRecordAll ( bool  tdisabled = false)
inlineslot

Store the record to the sql database with the saveRecord function but always works on connected tables too.

See Also
saveRecord()

Definition at line 1501 of file datalib.h.

void HTable::setDataChangeLogger ( HDataChangeLogger dcl)
inline

Adds a data change logger object to the HTable. It's enables the logging data changes to an sql table. It does not delete the given object

See Also
HDataChangeLogger

Definition at line 1462 of file datalib.h.

int HTable::setKey ( QString  key)
slot

Sets the value of the first HKey field. (Set the key field of the record)

Parameters
keythe value to set

Definition at line 3276 of file datalib.cpp.

void HTable::setSqlFieldValue ( QString  sqln,
QVariant  v,
bool  sdisable = false 
)

Sets the value of the specified field of the record

Parameters
sqlnthe sql name of the field which is about to set
vthe value to set
sdisableif this true the dataUpdated signal is disabled, otherwise (default) is emitted.

Definition at line 3129 of file datalib.cpp.

QString HTable::sqlInsert ( bool  insertkey = false)

Generates the sql insert command of the record. (But does not execute the any SQL command, just create a string) The insert contains the current values of the record. The insert sets the values of the HConnect fields too.

Parameters
insertkeyIf the inserkey is true the insert command will contain the key field and the current key value. Otherwise the key field is not appear in the insert. (In that case you can use an auto key generation algorithm)

Definition at line 3660 of file datalib.cpp.

QString HTable::sqlInsertAll ( void  )

Generates the sql insert command of the connected record group. (But does not execute the any SQL command, just create a string) The insert contains the current values of the record. The function generates the insert command of all table. Calculate the dependencies, and calculate the connection keys.

Example:
INSERT INTO peoples(name,age) VALUES('frank',20);
INSERT INTO telephonenum(peopleid,number) VALUES((SELECT id FROM peoples WHERE name='frank' AND age=20 ORDER BY timestamp DESC),'00-1-XXXX-YYYY-ZZZZ');

Definition at line 3694 of file datalib.cpp.

QString HTable::sqlUpdate ( bool  all = false)

Generates the sql update command of the table which refresh the values of the sql record. (But does not execute the any SQL command, just create a string)

Parameters
allif all is true the command will update the connected tables too. Otherwise only the record of the base table is updated.

Definition at line 3152 of file datalib.cpp.

QString HTable::sqlUpdateAll ( void  )
inline

Generates the sql update command of the table and the connected tables too.

See Also
sqlUpdate

Definition at line 1408 of file datalib.h.

int HTable::updateWithKey ( QString  key = "",
bool  all = false,
bool  update = true,
bool  tdisabled = false 
)
slot

Queries a record from the sql database. And the values are actualized in this table. After the query 1 rows result are expected, and the memory values are automatically updated.

Parameters
keyif the key contains a key value that key values record will be queried, otherwise the current value of the key field will be used to limit the query to one record.
allif the all parameter is true the connected tables are updated too.
updateif this parameter is true the dataUpdated signal is emitted
tdisabledif this parameter false the update runs in a separate transaction so the function starts a transaction and to a commit after its, otherwise (true) the function doesn't call any transaction related things.

Definition at line 3291 of file datalib.cpp.

int HTable::updateWithKeyAll ( QString  key = "",
bool  update = true,
bool  tdisabled = false 
)
inlineslot

Do an updateWithKey which run on the connected tabled too.

See Also
updateWithKey

Definition at line 1485 of file datalib.h.


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