diff options
Diffstat (limited to 'src/dal')
-rw-r--r-- | src/dal/pqdataprovider.cpp | 74 | ||||
-rw-r--r-- | src/dal/pqdataprovider.h | 26 | ||||
-rw-r--r-- | src/dal/sqlitedataprovider.cpp | 4 |
3 files changed, 52 insertions, 52 deletions
diff --git a/src/dal/pqdataprovider.cpp b/src/dal/pqdataprovider.cpp index b409151c..3fa8db45 100644 --- a/src/dal/pqdataprovider.cpp +++ b/src/dal/pqdataprovider.cpp @@ -59,24 +59,24 @@ PqDataProvider::getDbBackend(void) const */ void PqDataProvider::connect(const std::string& dbName, - const std::string& userName, - const std::string& password) + const std::string& userName, + const std::string& password) { // Create string to pass to PQconnectdb std::string connStr = "dbname = " + dbName + " "; // database name if (userName != "") - connStr += "user = " + userName + " "; // username + connStr += "user = " + userName + " "; // username if (password != "") - connStr += "password = " + password; // password + connStr += "password = " + password; // password // Connect to database mDb = PQconnectdb(connStr.c_str()); if (PQstatus(mDb) != CONNECTION_OK) { - std::string error = PQerrorMessage(mDb); - PQfinish(mDb); - throw DbConnectionFailure(error); + std::string error = PQerrorMessage(mDb); + PQfinish(mDb); + throw DbConnectionFailure(error); } mIsConnected = true; @@ -87,58 +87,58 @@ PqDataProvider::connect(const std::string& dbName, */ const RecordSet& PqDataProvider::execSql(const std::string& sql, - const bool refresh) + const bool refresh) { if (!mIsConnected) { - throw std::runtime_error("not connected to database"); + throw std::runtime_error("not connected to database"); } if (refresh || (sql != mSql)) { - mRecordSet.clear(); + mRecordSet.clear(); - // execute the query - PGresult *res; + // execute the query + PGresult *res; - res = PQexec(mDb, sql.c_str()); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - PQclear(res); - throw DbSqlQueryExecFailure(PQerrorMessage(mDb)); - } + res = PQexec(mDb, sql.c_str()); + if (PQresultStatus(res) != PGRES_COMMAND_OK) { + PQclear(res); + throw DbSqlQueryExecFailure(PQerrorMessage(mDb)); + } - // get field count - unsigned int nFields = PQnfields(res); + // get field count + unsigned int nFields = PQnfields(res); - // fill column names - Row fieldNames; - for (unsigned int i = 0; i < nFields; i++) { - fieldNames.push_back(PQfname(res, i)); - } - mRecordSet.setColumnHeaders(fieldNames); + // fill column names + Row fieldNames; + for (unsigned int i = 0; i < nFields; i++) { + fieldNames.push_back(PQfname(res, i)); + } + mRecordSet.setColumnHeaders(fieldNames); - // fill rows - for (unsigned int r = 0; r < PQntuples(res); r++) { - Row row; + // fill rows + for (unsigned int r = 0; r < PQntuples(res); r++) { + Row row; - for (unsigned int i = 0; i < nFields; i++) { - row.push_back(PQgetvalue(res, r, i)); - } + for (unsigned int i = 0; i < nFields; i++) { + row.push_back(PQgetvalue(res, r, i)); + } - mRecordSet.add(row); - } + mRecordSet.add(row); + } - // clear results - PQclear(res); + // clear results + PQclear(res); } } /** - * Close connection to databse. + * Close connection to database. */ void PqDataProvider::disconnect(void) { if (!mIsConnected) { - return; + return; } // finish up with Postgre diff --git a/src/dal/pqdataprovider.h b/src/dal/pqdataprovider.h index 1e8beedc..069228d5 100644 --- a/src/dal/pqdataprovider.h +++ b/src/dal/pqdataprovider.h @@ -39,14 +39,14 @@ class PqDataProvider : public DataProvider * Constructor */ PqDataProvider() - throw(); - + throw(); + /** * Destructor */ ~PqDataProvider() - throw(); - + throw(); + /** * Get name of the database backend * @@ -54,8 +54,8 @@ class PqDataProvider : public DataProvider */ DbBackends getDbBackend(void) const - throw(); - + throw(); + /** * Create a connection to the database. * @@ -67,10 +67,10 @@ class PqDataProvider : public DataProvider */ void connect(const std::string& dbName, - const std::string& userName, - const std::string& password); - - + const std::string& userName, + const std::string& password); + + /** * Execute a SQL query. * @@ -84,9 +84,9 @@ class PqDataProvider : public DataProvider */ const RecordSet& execSql(const std::string& sql, - const bool refresh = false); - - + const bool refresh = false); + + /** * Close the connection to the database. * diff --git a/src/dal/sqlitedataprovider.cpp b/src/dal/sqlitedataprovider.cpp index 30de91c5..38001acb 100644 --- a/src/dal/sqlitedataprovider.cpp +++ b/src/dal/sqlitedataprovider.cpp @@ -119,8 +119,8 @@ SqLiteDataProvider::execSql(const std::string& sql, mRecordSet.clear(); int errCode = sqlite3_get_table( - mDb, // an open database - sql.c_str(), // SQL to be executed + mDb, // an open database + sql.c_str(), // SQL to be executed &result, // result of the query &nRows, // number of result rows &nCols, // number of result columns |