diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-11-10 00:12:18 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-11-10 00:12:18 +0100 |
commit | d0187a975857ba5cf35b688acd84666cee0ddbb8 (patch) | |
tree | a0de9e1154791cd2a21237704544e840d85938f5 /src/dal | |
parent | 8369416cdfd2782860032bc524b5c58c0f1c06a7 (diff) | |
download | manaserv-d0187a975857ba5cf35b688acd84666cee0ddbb8.tar.gz manaserv-d0187a975857ba5cf35b688acd84666cee0ddbb8.tar.bz2 manaserv-d0187a975857ba5cf35b688acd84666cee0ddbb8.tar.xz manaserv-d0187a975857ba5cf35b688acd84666cee0ddbb8.zip |
Fix code indentation in the sql related files.
Trivial fix.
Diffstat (limited to 'src/dal')
-rw-r--r-- | src/dal/dataprovider.cpp | 2 | ||||
-rw-r--r-- | src/dal/mysqldataprovider.cpp | 70 | ||||
-rw-r--r-- | src/dal/pqdataprovider.cpp | 24 | ||||
-rw-r--r-- | src/dal/sqlitedataprovider.cpp | 45 |
4 files changed, 70 insertions, 71 deletions
diff --git a/src/dal/dataprovider.cpp b/src/dal/dataprovider.cpp index 24fe8846..684c2556 100644 --- a/src/dal/dataprovider.cpp +++ b/src/dal/dataprovider.cpp @@ -89,9 +89,7 @@ bool DataProvider::isConnected() const std::string DataProvider::getDbName() const { if (!isConnected()) - { return ""; - } return mDbName; } diff --git a/src/dal/mysqldataprovider.cpp b/src/dal/mysqldataprovider.cpp index 4e5f286d..d0c488a8 100644 --- a/src/dal/mysqldataprovider.cpp +++ b/src/dal/mysqldataprovider.cpp @@ -59,9 +59,8 @@ MySqlDataProvider::~MySqlDataProvider() // make sure that the database is closed. // disconnect() calls mysql_close() which takes care of freeing // the memory allocated for the handle. - if (mIsConnected) { + if (mIsConnected) disconnect(); - } } @@ -80,9 +79,8 @@ DbBackends MySqlDataProvider::getDbBackend() const */ void MySqlDataProvider::connect() { - if (mIsConnected) { + if (mIsConnected) return; - } // retrieve configuration from config file const std::string hostname @@ -100,7 +98,8 @@ void MySqlDataProvider::connect() // for mysql_real_connect(). mDb = mysql_init(NULL); - if (!mDb) { + if (!mDb) + { throw DbConnectionFailure( "unable to initialize the MySQL library: no memory"); } @@ -142,48 +141,47 @@ const RecordSet& MySqlDataProvider::execSql(const std::string& sql, const bool refresh) { - if (!mIsConnected) { + if (!mIsConnected) throw std::runtime_error("not connected to database"); - } - LOG_DEBUG("MySqlDataProvider::execSql Performing SQL query: "<<sql); + LOG_DEBUG("MySqlDataProvider::execSql Performing SQL query: " << sql); // do something only if the query is different from the previous // or if the cache must be refreshed // otherwise just return the recordset from cache. - if (refresh || (sql != mSql)) { + if (refresh || (sql != mSql)) + { mRecordSet.clear(); // actually execute the query. - if (mysql_query(mDb, sql.c_str()) != 0) { + if (mysql_query(mDb, sql.c_str()) != 0) throw DbSqlQueryExecFailure(mysql_error(mDb)); - } - if (mysql_field_count(mDb) > 0) { + if (mysql_field_count(mDb) > 0) + { MYSQL_RES* res; // get the result of the query. - if (!(res = mysql_store_result(mDb))) { + if (!(res = mysql_store_result(mDb))) throw DbSqlQueryExecFailure(mysql_error(mDb)); - } // set the field names. unsigned int nFields = mysql_num_fields(res); MYSQL_FIELD* fields = mysql_fetch_fields(res); Row fieldNames; - for (unsigned int i = 0; i < nFields; ++i) { + for (unsigned int i = 0; i < nFields; ++i) fieldNames.push_back(fields[i].name); - } + mRecordSet.setColumnHeaders(fieldNames); // populate the RecordSet. MYSQL_ROW row; - while ((row = mysql_fetch_row(res))) { + while ((row = mysql_fetch_row(res))) + { Row r; - for (unsigned int i = 0; i < nFields; ++i) { + for (unsigned int i = 0; i < nFields; ++i) r.push_back(static_cast<char *>(row[i])); - } mRecordSet.add(r); } @@ -202,9 +200,8 @@ MySqlDataProvider::execSql(const std::string& sql, */ void MySqlDataProvider::disconnect() { - if (!mIsConnected) { + if (!mIsConnected) return; - } // mysql_close() closes the connection and deallocates the connection // handle allocated by mysql_init(). @@ -332,7 +329,8 @@ unsigned MySqlDataProvider::getModifiedRows() const const my_ulonglong affected = mysql_affected_rows(mDb); if (affected > INT_MAX) - throw std::runtime_error("MySqlDataProvider::getLastId exceeded INT_MAX"); + throw std::runtime_error( + "MySqlDataProvider::getLastId exceeded INT_MAX"); if (affected == (my_ulonglong)-1) { @@ -397,17 +395,20 @@ const RecordSet &MySqlDataProvider::processSql() if (mysql_stmt_bind_param(mStmt, paramsBind)) { - LOG_ERROR("MySqlDataProvider::processSql Bind params failed: " << mysql_stmt_error(mStmt)); + LOG_ERROR("MySqlDataProvider::processSql Bind params failed: " + << mysql_stmt_error(mStmt)); } - if (mysql_stmt_field_count(mStmt) > 0) { + if (mysql_stmt_field_count(mStmt) > 0) + { mRecordSet.clear(); MYSQL_BIND* resultBind; MYSQL_RES* res; if (mysql_stmt_execute(mStmt)) { - LOG_ERROR("MySqlDataProvider::processSql Execute failed: " << mysql_stmt_error(mStmt)); + LOG_ERROR("MySqlDataProvider::processSql Execute failed: " + << mysql_stmt_error(mStmt)); } res = mysql_stmt_result_metadata(mStmt); @@ -419,7 +420,8 @@ const RecordSet &MySqlDataProvider::processSql() resultBind = new MYSQL_BIND[mysql_num_fields(res)]; - for (i = 0; i < mysql_num_fields(res); ++i) { + for (i = 0; i < mysql_num_fields(res); ++i) + { resultBind[i].buffer_type = MYSQL_TYPE_STRING; resultBind[i].buffer = (void*) new char[255]; resultBind[i].buffer_length = 255; @@ -430,26 +432,26 @@ const RecordSet &MySqlDataProvider::processSql() if (mysql_stmt_bind_result(mStmt, resultBind)) { - LOG_ERROR("MySqlDataProvider::processSql Bind result failed: " << mysql_stmt_error(mStmt)); + LOG_ERROR("MySqlDataProvider::processSql Bind result failed: " + << mysql_stmt_error(mStmt)); } - for (i = 0; i < nFields; ++i) { + for (i = 0; i < nFields; ++i) fieldNames.push_back(fields[i].name); - } + mRecordSet.setColumnHeaders(fieldNames); // store the result of the query. - if (mysql_stmt_store_result(mStmt)) { + if (mysql_stmt_store_result(mStmt)) throw DbSqlQueryExecFailure(mysql_stmt_error(mStmt)); - } // populate the RecordSet. - while (!mysql_stmt_fetch(mStmt)) { + while (!mysql_stmt_fetch(mStmt)) + { Row r; - for (unsigned int i = 0; i < nFields; ++i) { + for (unsigned int i = 0; i < nFields; ++i) r.push_back(static_cast<char *>(resultBind[i].buffer)); - } mRecordSet.add(r); } diff --git a/src/dal/pqdataprovider.cpp b/src/dal/pqdataprovider.cpp index dfe5253c..5351b0ce 100644 --- a/src/dal/pqdataprovider.cpp +++ b/src/dal/pqdataprovider.cpp @@ -41,9 +41,8 @@ PqDataProvider::PqDataProvider() PqDataProvider::~PqDataProvider() throw() { - if (mIsConnected) { + if (mIsConnected) disconnect(); - } } @@ -94,18 +93,19 @@ void PqDataProvider::connect(const std::string& dbName, const RecordSet &PqDataProvider::execSql(const std::string& sql, const bool refresh) { - if (!mIsConnected) { + if (!mIsConnected) throw std::runtime_error("not connected to database"); - } - if (refresh || (sql != mSql)) { + if (refresh || (sql != mSql)) + { mRecordSet.clear(); // execute the query PGresult *res; res = PQexec(mDb, sql.c_str()); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { PQclear(res); throw DbSqlQueryExecFailure(PQerrorMessage(mDb)); } @@ -115,18 +115,19 @@ const RecordSet &PqDataProvider::execSql(const std::string& sql, // fill column names Row fieldNames; - for (unsigned int i = 0; i < nFields; i++) { + 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++) { + for (unsigned int r = 0; r < PQntuples(res); r++) + { Row row; - for (unsigned int i = 0; i < nFields; i++) { + for (unsigned int i = 0; i < nFields; i++) row.push_back(PQgetvalue(res, r, i)); - } mRecordSet.add(row); } @@ -143,9 +144,8 @@ const RecordSet &PqDataProvider::execSql(const std::string& sql, */ void PqDataProvider::disconnect() { - if (!mIsConnected) { + if (!mIsConnected) return; - } // finish up with Postgre. PQfinish(mDb); diff --git a/src/dal/sqlitedataprovider.cpp b/src/dal/sqlitedataprovider.cpp index 12ab2de5..ea394e0c 100644 --- a/src/dal/sqlitedataprovider.cpp +++ b/src/dal/sqlitedataprovider.cpp @@ -50,15 +50,16 @@ SqLiteDataProvider::SqLiteDataProvider() SqLiteDataProvider::~SqLiteDataProvider() throw() { - try { + try + { // make sure that the database is closed. // disconnect() calls sqlite3_close() which takes care of freeing // the memory allocated for the handle. - if (mIsConnected) { + if (mIsConnected) disconnect(); - } } - catch (...) { + catch (...) + { // ignore } } @@ -89,7 +90,8 @@ SqLiteDataProvider::connect() // sqlite3_open creates the database file if it does not exist // as a side-effect. - if (sqlite3_open(dbName.c_str(), &mDb) != SQLITE_OK) { + if (sqlite3_open(dbName.c_str(), &mDb) != SQLITE_OK) + { // save the error message thrown by sqlite3_open() // as we may lose it when sqlite3_close() runs. std::string msg(sqlite3_errmsg(mDb)); @@ -120,16 +122,16 @@ const RecordSet& SqLiteDataProvider::execSql(const std::string& sql, const bool refresh) { - if (!mIsConnected) { + if (!mIsConnected) throw std::runtime_error("not connected to database"); - } - LOG_DEBUG("Performing SQL query: "<<sql); + LOG_DEBUG("Performing SQL query: " << sql); // do something only if the query is different from the previous // or if the cache must be refreshed // otherwise just return the recordset from cache. - if (refresh || (sql != mSql)) { + if (refresh || (sql != mSql)) + { char** result; int nRows; int nCols; @@ -146,7 +148,8 @@ SqLiteDataProvider::execSql(const std::string& sql, &errMsg // error msg ); - if (errCode != SQLITE_OK) { + if (errCode != SQLITE_OK) + { std::string msg(sqlite3_errmsg(mDb)); LOG_ERROR("Error in SQL: " << sql << "\n" << msg); @@ -160,20 +163,19 @@ SqLiteDataProvider::execSql(const std::string& sql, // the first row of result[] contains the field names. Row fieldNames; - for (int col = 0; col < nCols; ++col) { + for (int col = 0; col < nCols; ++col) fieldNames.push_back(result[col]); - } + mRecordSet.setColumnHeaders(fieldNames); // populate the RecordSet - for (int row = 0; row < nRows; ++row) { + for (int row = 0; row < nRows; ++row) + { Row r; - for (int col = 0; col < nCols; ++col) { + for (int col = 0; col < nCols; ++col) r.push_back(result[nCols + (row * nCols) + col]); - } - mRecordSet.add(r); } @@ -196,9 +198,8 @@ void SqLiteDataProvider::disconnect() // sqlite3_close() closes the connection and deallocates the connection // handle. - if (sqlite3_close(mDb) != SQLITE_OK) { + if (sqlite3_close(mDb) != SQLITE_OK) throw DbDisconnectionFailure(sqlite3_errmsg(mDb)); - } mDb = 0; mIsConnected = false; @@ -362,19 +363,17 @@ bool SqLiteDataProvider::prepareSql(const std::string &sql) mRecordSet.clear(); - if (sqlite3_prepare_v2(mDb, sql.c_str(), sql.size(), &mStmt, NULL) != SQLITE_OK) - { + if (sqlite3_prepare_v2(mDb, sql.c_str(), sql.size(), + &mStmt, NULL) != SQLITE_OK) return false; - } return true; } const RecordSet &SqLiteDataProvider::processSql() { - if (!mIsConnected) { + if (!mIsConnected) throw std::runtime_error("not connected to database"); - } int totalCols = sqlite3_column_count(mStmt); Row fieldNames; |