gSAFE  1.3.8
Signals | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
HSqlHandler Class Reference

#include <datalib.h>

Inheritance diagram for HSqlHandler:
HSqlInterface HBase HDataChangeLogger HDataField HDynTableSqlConnector HFloatTables HTableBase HCharHash HCheck HConnect HDate HFloating HKey HLargeText HNumber HNumHash HSmallText HSqlChoose HStatic HTimestamp HList HTable

Signals

void errorSignal (QString err)
 

Public Member Functions

 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)
 

Static Public Member Functions

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

static int trans = 0
 

Protected Attributes

bool query_error_occured
 
- Protected Attributes inherited from HBase
QString whoami
 

Detailed Description

The base SQL data handler class. All class working with sql is inherited from this. Here are the base sql functions, to make the base operations, error handling, make transactions etc... This class can be used directly for making atomic sql operations too.
The higher level sql manipulator classes are inherited from here.

...
HSqlHandler sql;
if( sql.submit0ResultQuery("INSERT INTO table(id,name) VALUES(\'001\',\'Paul\')","Error occured") )
{
//error occured
...
}
...

Definition at line 769 of file datalib.h.

Constructor & Destructor Documentation

HSqlHandler::HSqlHandler ( void  )

Creates an HSqlHandler

Definition at line 1139 of file datalib.cpp.

HSqlHandler::~HSqlHandler ( void  )

Destructor

Definition at line 1148 of file datalib.cpp.

Member Function Documentation

QSqlQuery * HSqlHandler::allocateQSqlQuery ( void  )

Allocate the new QSqlQuery in the workDB() database. You have to delete after using!

Definition at line 1180 of file datalib.cpp.

void HSqlHandler::cloneSqlSettingsFrom ( HSqlHandler other)

Copy the SQL settings from the given parameter HSqlHandler. (It calls cloneSqlInterfaceSettingsFrom() function too.) Copies the custom database data and interface informations.

Definition at line 1156 of file datalib.cpp.

void HSqlHandler::commit ( void  )

Commits the current transaction

See Also
commit()
rollback()
transaction()

Definition at line 1195 of file datalib.cpp.

void HSqlHandler::errorSignal ( QString  err)
signal

If any error occured during the sql execution this signal is emitted. The "err" will be contains the error describe.

bool HSqlHandler::errorStatus ( void  )
inline

Queryes if the last SQL query is successfully executed or any error occured

Returns
TRUE:error occured, FALSE:no error occured

Definition at line 880 of file datalib.h.

void HSqlHandler::rollback ( void  )

Rollback the current transaction

See Also
commit()
rollback()
transaction()

Definition at line 1210 of file datalib.cpp.

void HSqlHandler::setCustomSqlDatabase ( QString  databaseName,
QString  sqlinterfacename = "" 
)
static

If the program has multiple database connections, you can specify the current global database for the new HSqlHandler instances.
Those (created) HSqlHandler instances keeps the database settings permanently after creation. It means this function is SET A DEFAULT database. So the objects (Even HTables,HList,etc) stays in that database which was the current during the creation.

...
//the program default database is A
...
HList *inAdb = myfactory->genHList("TableinA"); //create a HList in db A
HSqlHandler::setCustomSqlDatabase("b_database"); //change the current def database to B
HList *inBdb = myfactory->genHList("TableinB"); //create a HList in db B
HSqlHandler::setDefaultSqlDatabase(); //change the current def database back to A
inAdb->readList(); //it reads a table from A database
inBdb->readList(); //it reads a table from B database
Parameters
databaseNamethe database name is that name which is used when you create the connection Example: QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","this_is_the_name");
sqlinterfacenameyou can set different sql interface for this new database. Works same way than Sql databases. If you give empty string it means no change.

Definition at line 1124 of file datalib.cpp.

void HSqlHandler::setDefaultSqlDatabase ( void  )
static

Sets the current default database connection to active on this object. It restores the sqlinterface too.

See Also
setCustomSqlDatabase()

Definition at line 1132 of file datalib.cpp.

bool HSqlHandler::submit0ResultQuery ( QString  q,
QString  err,
bool  tdisabled = false 
)

Submit a simple SQL command which have no result (DDL/DML command)

Parameters
qThe text of the SQL command
errIn case of error the emitted error signal will be contains this message
tdisabledFALSE:It is submitted in a new separate transaction, TRUE:Don's start a new transaction
Returns
TRUE:error occured, this case it is emits an error signal with the specified err - string , FALSE: no error occured

Definition at line 1225 of file datalib.cpp.

QVariant HSqlHandler::submit1ResultQuery ( QString  q,
QString  err,
bool  tdisabled = false 
)

Submit a simple SQL command which returns one result (One row,one cell) For example: SELECT count(*) FROM mytable;

Parameters
qThe text of the SQL command
errIn case of error the emitted error signal will be contains this message
tdisabledFALSE:It is submitted in a new separate transaction, TRUE:Don's start a new transaction
Returns
NULL:if error occured, this case it is emits an error signal with the specified err - string otherwise it returns the result cell

Definition at line 1260 of file datalib.cpp.

HPlainDataMatrix * HSqlHandler::submitNResultQuery ( int  N,
QString  q,
QString  err,
bool  tdisabled = false 
)

Submits an SQL command which have a table result (Table with N row)

Parameters
Nthe column count of the result table. (Needed for allocate the HPlainDataMatrix)
qThe text of the SQL command
errIn case of error the emitted error signal will be contains this message
tdisabledFALSE:It is submitted in a new separate transaction, TRUE:Don's start a new transaction
See Also
HPlainDataMatrix
Returns
The result table in a HPlainDataMatrix instance

Definition at line 1302 of file datalib.cpp.

void HSqlHandler::transaction ( void  )

Begins an SQL transaction. Have to call this before calling a commit() or a rollback()

See Also
commit()
rollback()
transaction()

Definition at line 1185 of file datalib.cpp.

QSqlDatabase HSqlHandler::workDB ( void  )

Returns the QSqlDatabase object which sould be use. This function is used by the descendants. It controls that they use the correct database (In case of the program has multiple database connections

See Also
setCustomDatabase()
setDefaultDatabase()

Definition at line 1164 of file datalib.cpp.

Member Data Documentation

int HSqlHandler::trans = 0
static

Currently active transaction number

Definition at line 785 of file datalib.h.


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