From 90fde5774f1e6ee1a3b649753fa7338e386a3c45 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Thu, 1 Mar 2012 20:43:34 +0100 Subject: SQLite: Fixed SqLiteDataProvider::processSql handling of multiple rows When a prepared SQL statement would have returned multiple rows, this function would try to set the column header names multiple times which throws the AlreadySetException. Currently it doesn't seem that any prepared statements are meant to return multiple rows. Reviewed-by: Yohann Ferreira --- src/dal/sqlitedataprovider.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/dal') diff --git a/src/dal/sqlitedataprovider.cpp b/src/dal/sqlitedataprovider.cpp index a47c9862..cc698f61 100644 --- a/src/dal/sqlitedataprovider.cpp +++ b/src/dal/sqlitedataprovider.cpp @@ -365,25 +365,27 @@ const RecordSet &SqLiteDataProvider::processSql() throw std::runtime_error("not connected to database"); int totalCols = sqlite3_column_count(mStmt); + + // ensure we set column headers before adding a row Row fieldNames; + for (int col = 0; col < totalCols; ++col) + { + fieldNames.push_back(sqlite3_column_name(mStmt, col)); + } + mRecordSet.setColumnHeaders(fieldNames); while (sqlite3_step(mStmt) == SQLITE_ROW) { Row r; for (int col = 0; col < totalCols; ++col) { - fieldNames.push_back(sqlite3_column_name(mStmt, col)); const unsigned char *txt = sqlite3_column_text(mStmt, col); r.push_back(txt ? (char*)txt : std::string()); } - // ensure we set column headers before adding a row - mRecordSet.setColumnHeaders(fieldNames); mRecordSet.add(r); } - - sqlite3_finalize(mStmt); return mRecordSet; -- cgit v1.2.3-70-g09d2