some compilation refactoring

This commit is contained in:
Aleksandar Fabijanic
2008-01-22 02:05:04 +00:00
parent 277101a054
commit bc8f7e8680
10 changed files with 69 additions and 59 deletions

View File

@@ -95,15 +95,16 @@ protected:
bool canBind() const;
/// Returns true if a valid statement is set and we can bind.
bool compileImpl();
bool canCompile() const;
/// Returns true if statement can compile.
void compileImpl();
/// Compiles the statement, doesn't bind yet.
/// Returns true if the statement was succesfully compiled.
/// The way SQLite handles batches of statmeents is by compiling
/// one at a time and returning a pointer to the next one.
/// The remainder of the statement is remebered in a string
/// buffer pointed to by _pLeftover member. Non-zero _pLeftover
/// pointing to an empty string means no more statements left
/// to compile.
/// The remainder of the statement is kept in a string
/// buffer pointed to by _pLeftover member.
void bindImpl();
/// Binds parameters
@@ -139,6 +140,7 @@ private:
BindIt _bindBegin;
bool _canBind;
bool _isExtracted;
bool _canCompile;
};
@@ -163,6 +165,12 @@ inline bool SQLiteStatementImpl::canBind() const
}
inline bool SQLiteStatementImpl::canCompile() const
{
return _canCompile;
}
} } } // namespace Poco::Data::SQLite

View File

@@ -56,7 +56,8 @@ SQLiteStatementImpl::SQLiteStatementImpl(Poco::Data::SessionImpl& rSession, sqli
_nextResponse(0),
_affectedRowCount(0),
_canBind(false),
_isExtracted(false)
_isExtracted(false),
_canCompile(true)
{
_columns.resize(1);
}
@@ -68,15 +69,9 @@ SQLiteStatementImpl::~SQLiteStatementImpl()
}
bool SQLiteStatementImpl::compileImpl()
void SQLiteStatementImpl::compileImpl()
{
if (_pLeftover && _pLeftover->empty())
{
_pLeftover = 0;
return false;
}
else if (!_pLeftover)
_bindBegin = bindings().begin();
if (!_pLeftover) _bindBegin = bindings().begin();
std::string statement(toString());
sqlite3_stmt* pStmt = 0;
@@ -119,10 +114,15 @@ bool SQLiteStatementImpl::compileImpl()
//For last statement in a batch (or a single statement), pLeftover == "", so the next call
// to compileImpl() shall return false immediately when there are no more statements left.
std::string leftOver(pLeftover);
trimInPlace(leftOver);
clear();
_pStmt = pStmt;
_pLeftover = new std::string(leftOver);
trimInPlace(*_pLeftover);
if (!leftOver.empty())
{
_pLeftover = new std::string(leftOver);
_canCompile = true;
}
else _canCompile = false;
_pBinder = new Binder(_pStmt);
_pExtractor = new Extractor(_pStmt);
@@ -150,8 +150,6 @@ bool SQLiteStatementImpl::compileImpl()
_columns[curDataSet].push_back(mc);
}
}
return true;
}
@@ -226,7 +224,6 @@ void SQLiteStatementImpl::clear()
_pStmt=0;
}
_pLeftover = 0;
_canBind = false;
}