mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-30 05:39:03 +01:00
fix for Statement async execution and a diagnostics improvement in RecordSet
This commit is contained in:
parent
1d774be07b
commit
5d4080e7f4
@ -279,6 +279,8 @@ private:
|
||||
{
|
||||
typedef const InternalExtraction<T,C>* ExtractionVecPtr;
|
||||
|
||||
bool typeFound = false;
|
||||
|
||||
const AbstractExtractionVec& rExtractions = extractions();
|
||||
AbstractExtractionVec::const_iterator it = rExtractions.begin();
|
||||
AbstractExtractionVec::const_iterator end = rExtractions.end();
|
||||
@ -289,13 +291,17 @@ private:
|
||||
|
||||
if (pExtraction)
|
||||
{
|
||||
typeFound = true;
|
||||
const Column<T,C>& col = pExtraction->column();
|
||||
if (0 == Poco::icompare(name, col.name()))
|
||||
return col.position();
|
||||
}
|
||||
}
|
||||
|
||||
throw NotFoundException(format("Unknown column name: %s", name));
|
||||
if (typeFound)
|
||||
throw NotFoundException(format("Column name: %s", name));
|
||||
else
|
||||
throw NotFoundException(format("Column type: %s, name: %s", typeid(C).name(), name));
|
||||
}
|
||||
|
||||
std::size_t _currentRow;
|
||||
|
@ -114,10 +114,12 @@ class Data_API Statement
|
||||
{
|
||||
public:
|
||||
typedef void (*Manipulator)(Statement&);
|
||||
typedef Poco::UInt32 ResultType;
|
||||
typedef ActiveResult<ResultType> Result;
|
||||
typedef SharedPtr<Result> ResultPtr;
|
||||
|
||||
typedef Poco::UInt32 ResultType;
|
||||
typedef ActiveResult<ResultType> Result;
|
||||
typedef SharedPtr<Result> ResultPtr;
|
||||
typedef ActiveMethod<ResultType, void, StatementImpl> AsyncExecMethod;
|
||||
typedef SharedPtr<AsyncExecMethod> AsyncExecMethodPtr;
|
||||
|
||||
enum Storage
|
||||
{
|
||||
@ -203,7 +205,7 @@ public:
|
||||
/// Stops when either a limit is hit or the whole statement was executed.
|
||||
/// Returns immediately. For statements returning data, the number of rows extracted is
|
||||
/// available by calling wait() method on either the returned value or the statement itself.
|
||||
/// When executed on otherwise synchronous statement, this method does not alter the
|
||||
/// When executed on a synchronous statement, this method does not alter the
|
||||
/// statement's synchronous nature.
|
||||
|
||||
void setAsync(bool async = true);
|
||||
@ -271,13 +273,13 @@ private:
|
||||
const Result& doAsyncExec();
|
||||
/// Asynchronously executes the statement.
|
||||
|
||||
StatementImplPtr _ptr;
|
||||
StatementImplPtr _ptr;
|
||||
|
||||
// asynchronous execution related members
|
||||
bool _isAsync;
|
||||
mutable ResultPtr _pResult;
|
||||
Mutex _mutex;
|
||||
AsyncExecMethod _asyncExec;
|
||||
bool _async;
|
||||
mutable ResultPtr _pResult;
|
||||
Mutex _mutex;
|
||||
AsyncExecMethodPtr _pAsyncExec;
|
||||
};
|
||||
|
||||
|
||||
@ -430,15 +432,9 @@ inline bool Statement::isNull(std::size_t col, std::size_t row) const
|
||||
}
|
||||
|
||||
|
||||
inline void Statement::setAsync(bool async)
|
||||
{
|
||||
_isAsync = async;
|
||||
}
|
||||
|
||||
|
||||
inline bool Statement::isAsync() const
|
||||
{
|
||||
return _isAsync;
|
||||
return _async;
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,15 +50,14 @@ namespace Data {
|
||||
|
||||
Statement::Statement(StatementImpl* pImpl):
|
||||
_ptr(pImpl),
|
||||
_isAsync(false),
|
||||
_asyncExec(_ptr, &StatementImpl::execute)
|
||||
_async(false)
|
||||
{
|
||||
poco_check_ptr (pImpl);
|
||||
}
|
||||
|
||||
|
||||
Statement::Statement(Session& session):
|
||||
_asyncExec(_ptr, &StatementImpl::execute)
|
||||
_async(false)
|
||||
{
|
||||
reset(session);
|
||||
}
|
||||
@ -66,9 +65,9 @@ Statement::Statement(Session& session):
|
||||
|
||||
Statement::Statement(const Statement& stmt):
|
||||
_ptr(stmt._ptr),
|
||||
_isAsync(stmt._isAsync),
|
||||
_async(stmt._async),
|
||||
_pResult(stmt._pResult),
|
||||
_asyncExec(_ptr, &StatementImpl::execute)
|
||||
_pAsyncExec(stmt._pAsyncExec)
|
||||
{
|
||||
}
|
||||
|
||||
@ -89,12 +88,20 @@ Statement& Statement::operator = (const Statement& stmt)
|
||||
void Statement::swap(Statement& other)
|
||||
{
|
||||
std::swap(_ptr, other._ptr);
|
||||
std::swap(_isAsync, other._isAsync);
|
||||
std::swap(_asyncExec, other._asyncExec);
|
||||
std::swap(_async, other._async);
|
||||
std::swap(_pAsyncExec, other._pAsyncExec);
|
||||
std::swap(_pResult, other._pResult);
|
||||
}
|
||||
|
||||
|
||||
Statement& Statement::reset(Session& session)
|
||||
{
|
||||
Statement stmt(session.createStatementImpl());
|
||||
swap(stmt);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Statement::ResultType Statement::execute()
|
||||
{
|
||||
Mutex::ScopedLock lock(_mutex);
|
||||
@ -129,12 +136,23 @@ const Statement::Result& Statement::executeAsync()
|
||||
const Statement::Result& Statement::doAsyncExec()
|
||||
{
|
||||
if (done()) _ptr->reset();
|
||||
_pResult = new Result(_asyncExec());
|
||||
if (!_pAsyncExec)
|
||||
_pAsyncExec = new AsyncExecMethod(_ptr, &StatementImpl::execute);
|
||||
poco_check_ptr (_pAsyncExec);
|
||||
_pResult = new Result((*_pAsyncExec)());
|
||||
poco_check_ptr (_pResult);
|
||||
return *_pResult;
|
||||
}
|
||||
|
||||
|
||||
void Statement::setAsync(bool async)
|
||||
{
|
||||
_async = async;
|
||||
if (_async && !_pAsyncExec)
|
||||
_pAsyncExec = new AsyncExecMethod(_ptr, &StatementImpl::execute);
|
||||
}
|
||||
|
||||
|
||||
Statement::ResultType Statement::wait(long milliseconds)
|
||||
{
|
||||
if (!_pResult) return 0;
|
||||
@ -151,14 +169,6 @@ Statement::ResultType Statement::wait(long milliseconds)
|
||||
}
|
||||
|
||||
|
||||
Statement& Statement::reset(Session& session)
|
||||
{
|
||||
Statement stmt(session.createStatementImpl());
|
||||
swap(stmt);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
const std::string& Statement::getStorage() const
|
||||
{
|
||||
switch (storage())
|
||||
|
Loading…
x
Reference in New Issue
Block a user