Don't hold sqlite locks across invocations.

This commit is contained in:
JoelKatz
2013-04-18 19:56:28 -07:00
parent e296a81c83
commit 3b90dfdcd1
3 changed files with 20 additions and 19 deletions

View File

@@ -80,6 +80,7 @@ bool SqliteDatabase::executeSQL(const char* sql, bool fail_ok)
#endif
}
return false;
endIterRows();
}
rc = sqlite3_step(mCurrentStmt);
if (rc == SQLITE_ROW)
@@ -88,6 +89,7 @@ bool SqliteDatabase::executeSQL(const char* sql, bool fail_ok)
}
else if (rc == SQLITE_DONE)
{
endIterRows();
mMoreRows = false;
}
else
@@ -107,6 +109,7 @@ bool SqliteDatabase::executeSQL(const char* sql, bool fail_ok)
cLog(lsWARNING) << "Error: " << sqlite3_errmsg(mConnection);
#endif
}
endIterRows();
return false;
}
@@ -126,7 +129,7 @@ int SqliteDatabase::getLastInsertID()
}
// returns false if there are no results
bool SqliteDatabase::startIterRows()
bool SqliteDatabase::startIterRows(bool finalize)
{
mColNameTable.clear();
mColNameTable.resize(sqlite3_column_count(mCurrentStmt));
@@ -135,6 +138,9 @@ bool SqliteDatabase::startIterRows()
mColNameTable[n]=sqlite3_column_name(mCurrentStmt,n);
}
if (!mMoreRows && finalize)
endIterRows();
return(mMoreRows);
}
@@ -146,25 +152,20 @@ void SqliteDatabase::endIterRows()
// call this after you executeSQL
// will return false if there are no more rows
bool SqliteDatabase::getNextRow()
bool SqliteDatabase::getNextRow(bool finalize)
{
if (!mMoreRows) return(false);
int rc=sqlite3_step(mCurrentStmt);
if (rc==SQLITE_ROW)
{
return(true);
}
else if (rc==SQLITE_DONE)
{
return(false);
}
else
if (mMoreRows)
{
int rc=sqlite3_step(mCurrentStmt);
if (rc==SQLITE_ROW)
return(true);
assert((rc != SQLITE_BUSY) && (rc != SQLITE_LOCKED));
cLog(lsWARNING) << "Rerror: " << mHost << ": " << rc;
return(false);
}
if (finalize)
endIterRows();
return false;
}
bool SqliteDatabase::getNull(int colIndex)

View File

@@ -34,12 +34,12 @@ public:
int getLastInsertID();
// returns false if there are no results
bool startIterRows();
bool startIterRows(bool finalize);
void endIterRows();
// call this after you executeSQL
// will return false if there are no more rows
bool getNextRow();
bool getNextRow(bool finalize);
bool getNull(int colIndex);
char* getStr(int colIndex,std::string& retStr);

View File

@@ -53,12 +53,12 @@ public:
virtual int getLastInsertID()=0;
// returns false if there are no results
virtual bool startIterRows()=0;
virtual bool startIterRows(bool finalize = true)=0;
virtual void endIterRows()=0;
// call this after you executeSQL
// will return false if there are no more rows
virtual bool getNextRow()=0;
virtual bool getNextRow(bool finalize = true)=0;
// get Data from the current row
bool getNull(const char* colName);