#include <sql.h>
Collaboration diagram for sql:
Public Member Functions | |
void | setCursor () |
Method to store the result of a query for later retrieval. | |
void | restoreCursor () |
Method to retrieve a previously stored query result. | |
void | initConn (const QString &uName, const QString &dbName="guest", const QString &password="", const QString &connName="guestConn", const QString &host="localhost", const QString &connType="QPSQL") |
int | prepare (const QString &functionName, int paramCnt, const QString &connName="") |
int | prepare (const QString &command, const QString &connName="") |
Method used to prepare a SQL command. | |
void | bind (int posn, QVariant value, int qID=-1) |
bool | query (int qID=-1) |
bool | first () |
Method to get the first result from the current query. | |
bool | next () |
Method to get the next result from the current query. | |
bool | last () |
Method to get the last result from the current query. | |
QVariant | get (int index) |
QVariant | getFirst (int index) |
QVariant | getNext (int index) |
void | dump () |
Method to dump out some details about the current result set. | |
QString * | useModuleConn () |
Static Public Member Functions | |
static sql * | Instance () |
Method to get the singleton instance. | |
Static Public Attributes | |
static QString * | DefaultConnectionName = new QString("guestConn") |
The name of the default connection. |
This is a singleton class that will manage the connections with the database. It will support any number of databases by using the QDatabase class.
All interactions with the database should be done with the instance of this class. If there is an error then an exception will be thrown, this can then be managed in the appropriate way.
If a cursor needs to be set within the scanning of a database then this is supported, however it is up to the developer to use these responsibly. That is they must be set and then restored in pairs.
Definition at line 39 of file sql.h.
|
|
Method to get the value indicated by index from the current record
Definition at line 158 of file sql.cpp. Referenced by getFirst(), and getNext(). 00159 { 00160 if (result == 0) 00161 throw sqlE(QSqlDatabase::database(lastDBConnName)); 00162 return result->value(index); 00163 }
|
|
Method to position the record on the first record and get the value indicated by index
Definition at line 165 of file sql.cpp. References first(), and get(). Referenced by DataClass::insert(), ModLecAlloc::ModLecAlloc(), TimeSlot::remove(), DataClass::remove(), DataClass::unique(), DataClass::update(), ModLecAlloc::updateClassSizeonDB(), ModLecAlloc::updateGroupsonDB(), ModLecAlloc::updateLabGroupsonDB(), and ModLecAlloc::updateLabHoursonDB().
|
|
Method to get the value from the current record and move to the next result
Definition at line 171 of file sql.cpp.
|
|
Method to create a connection to a database
Definition at line 44 of file sql.cpp. 00051 { 00052 QSqlDatabase dbConn = QSqlDatabase::addDatabase(connType,connName); 00053 00054 dbConn.setDatabaseName(dbName); 00055 dbConn.setUserName(uName); 00056 dbConn.setPassword(password); 00057 dbConn.setHostName(host); 00058 00059 if (!dbConn.open()) 00060 { 00061 throw sqlE(dbConn, "Failed to log on to the Database"); 00062 } 00063 lastDBConnName = connName; 00064 }
|
|
Method used to prepare a SQL function with the number of parameter given
Definition at line 66 of file sql.cpp. Referenced by TimeSlot::PrepareSQL(), Staff::PrepareSQL(), Room::PrepareSQL(), Programme::PrepareSQL(), Module::PrepareSQL(), ModLecAlloc::PrepareSQL(), Institute::PrepareSQL(), Faculty::PrepareSQL(), and Department::PrepareSQL(). 00069 { 00070 QString paramList = "?"; 00071 for (int cnt = 1; cnt < paramCnt; cnt++) 00072 { 00073 paramList += ", ?"; 00074 } 00075 QString command = "SELECT " + functionName + "(" + paramList + ")"; 00076 QString dbConn; 00077 if (connName=="") 00078 dbConn = lastDBConnName; 00079 else 00080 { 00081 dbConn = connName; 00082 lastDBConnName = dbConn; 00083 } 00084 QSqlQuery * preparedStmt = new QSqlQuery (QSqlDatabase::database(dbConn)); 00085 preparedStmt->prepare(command); 00086 queryList.append(preparedStmt); 00087 activeQuery = preparedStmt; 00088 return queryList.size()-1; 00089 }
|
|
Method to execute a query
Definition at line 121 of file sql.cpp. Referenced by DataClass::insert(), ModLecAlloc::ModLecAlloc(), TimeSlot::remove(), DataClass::remove(), DataClass::unique(), DataClass::update(), ModLecAlloc::updateClassSizeonDB(), ModLecAlloc::updateGroupsonDB(), ModLecAlloc::updateLabGroupsonDB(), and ModLecAlloc::updateLabHoursonDB(). 00122 { 00123 if (qID >= 0 && qID < queryList.size()) 00124 { 00125 activeQuery = queryList.at(qID); 00126 } 00127 result = new QSqlQuery(*activeQuery); 00128 bool success = result->exec(); 00129 if (success == false) 00130 throw sqlE(QSqlDatabase::database(lastDBConnName), "Query Error: \"" + result->lastQuery() +"\""); 00131 return success; 00132 }
|