Commit a3c1a047 authored by Steven Murray's avatar Steven Murray
Browse files

SqliteRset::next() now always updates col metadata

Before this commit, column metadata was only set on the first call
to SqliteRset::next().  This was a design bug.  Column metadata can
be different for different rows in a result set.  This is because a
NULL column value has a corresponding SQLITE_NULL datatype.
parent 476b977d
......@@ -125,9 +125,7 @@ private:
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
SqliteRset::SqliteRset(SqliteStmt &stmt):
m_stmt(stmt),
m_nextHasNotBeenCalled(true) {
SqliteRset::SqliteRset(SqliteStmt &stmt): m_stmt(stmt) {
}
//------------------------------------------------------------------------------
......@@ -155,12 +153,8 @@ bool SqliteRset::next() {
throw exception::Exception(Sqlite::rcToStr(stepRc));
}
if(m_nextHasNotBeenCalled) {
m_nextHasNotBeenCalled = false;
if(SQLITE_ROW == stepRc) {
populateColNameToIdxAndTypeMap();
}
if(SQLITE_ROW == stepRc) {
clearAndPopulateColNameToIdxAndTypeMap();
}
return SQLITE_ROW == stepRc;
......@@ -171,14 +165,16 @@ bool SqliteRset::next() {
}
//------------------------------------------------------------------------------
// populateColNameToIdxMap
// clearAndPopulateColNameToIdxMap
//------------------------------------------------------------------------------
void SqliteRset::populateColNameToIdxAndTypeMap() {
void SqliteRset::clearAndPopulateColNameToIdxAndTypeMap() {
try {
m_colNameToIdxAndType.clear();
const int nbCols = sqlite3_column_count(m_stmt.get());
for (int i = 0; i < nbCols; i++) {
// Get the name of the column
const char *colName = sqlite3_column_name(m_stmt.get(), i);
const char *const colName = sqlite3_column_name(m_stmt.get(), i);
if (nullptr == colName) {
std::ostringstream msg;
msg << "Failed to get column name for column index " << i;
......
......@@ -101,20 +101,15 @@ private:
*/
SqliteStmt &m_stmt;
/**
* True if the next() method has not yet been called.
*/
bool m_nextHasNotBeenCalled;
/**
* Map from column name to column index and type.
*/
ColumnNameToIdxAndType m_colNameToIdxAndType;
/**
* Populates the map from column name to column index and type.
* Clears and populates the map from column name to column index and type.
*/
void populateColNameToIdxAndTypeMap();
void clearAndPopulateColNameToIdxAndTypeMap();
}; // class SqlLiteRset
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment