mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 04:17:55 +01:00
fix for Statement async execution and a diagnostics improvement in RecordSet
This commit is contained in:
@@ -279,6 +279,8 @@ private:
|
|||||||
{
|
{
|
||||||
typedef const InternalExtraction<T,C>* ExtractionVecPtr;
|
typedef const InternalExtraction<T,C>* ExtractionVecPtr;
|
||||||
|
|
||||||
|
bool typeFound = false;
|
||||||
|
|
||||||
const AbstractExtractionVec& rExtractions = extractions();
|
const AbstractExtractionVec& rExtractions = extractions();
|
||||||
AbstractExtractionVec::const_iterator it = rExtractions.begin();
|
AbstractExtractionVec::const_iterator it = rExtractions.begin();
|
||||||
AbstractExtractionVec::const_iterator end = rExtractions.end();
|
AbstractExtractionVec::const_iterator end = rExtractions.end();
|
||||||
@@ -289,13 +291,17 @@ private:
|
|||||||
|
|
||||||
if (pExtraction)
|
if (pExtraction)
|
||||||
{
|
{
|
||||||
|
typeFound = true;
|
||||||
const Column<T,C>& col = pExtraction->column();
|
const Column<T,C>& col = pExtraction->column();
|
||||||
if (0 == Poco::icompare(name, col.name()))
|
if (0 == Poco::icompare(name, col.name()))
|
||||||
return col.position();
|
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;
|
std::size_t _currentRow;
|
||||||
|
|||||||
@@ -114,10 +114,12 @@ class Data_API Statement
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef void (*Manipulator)(Statement&);
|
typedef void (*Manipulator)(Statement&);
|
||||||
typedef Poco::UInt32 ResultType;
|
|
||||||
typedef ActiveResult<ResultType> Result;
|
typedef Poco::UInt32 ResultType;
|
||||||
typedef SharedPtr<Result> ResultPtr;
|
typedef ActiveResult<ResultType> Result;
|
||||||
|
typedef SharedPtr<Result> ResultPtr;
|
||||||
typedef ActiveMethod<ResultType, void, StatementImpl> AsyncExecMethod;
|
typedef ActiveMethod<ResultType, void, StatementImpl> AsyncExecMethod;
|
||||||
|
typedef SharedPtr<AsyncExecMethod> AsyncExecMethodPtr;
|
||||||
|
|
||||||
enum Storage
|
enum Storage
|
||||||
{
|
{
|
||||||
@@ -203,7 +205,7 @@ public:
|
|||||||
/// Stops when either a limit is hit or the whole statement was executed.
|
/// 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
|
/// 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.
|
/// 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.
|
/// statement's synchronous nature.
|
||||||
|
|
||||||
void setAsync(bool async = true);
|
void setAsync(bool async = true);
|
||||||
@@ -271,13 +273,13 @@ private:
|
|||||||
const Result& doAsyncExec();
|
const Result& doAsyncExec();
|
||||||
/// Asynchronously executes the statement.
|
/// Asynchronously executes the statement.
|
||||||
|
|
||||||
StatementImplPtr _ptr;
|
StatementImplPtr _ptr;
|
||||||
|
|
||||||
// asynchronous execution related members
|
// asynchronous execution related members
|
||||||
bool _isAsync;
|
bool _async;
|
||||||
mutable ResultPtr _pResult;
|
mutable ResultPtr _pResult;
|
||||||
Mutex _mutex;
|
Mutex _mutex;
|
||||||
AsyncExecMethod _asyncExec;
|
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
|
inline bool Statement::isAsync() const
|
||||||
{
|
{
|
||||||
return _isAsync;
|
return _async;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -50,15 +50,14 @@ namespace Data {
|
|||||||
|
|
||||||
Statement::Statement(StatementImpl* pImpl):
|
Statement::Statement(StatementImpl* pImpl):
|
||||||
_ptr(pImpl),
|
_ptr(pImpl),
|
||||||
_isAsync(false),
|
_async(false)
|
||||||
_asyncExec(_ptr, &StatementImpl::execute)
|
|
||||||
{
|
{
|
||||||
poco_check_ptr (pImpl);
|
poco_check_ptr (pImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Statement::Statement(Session& session):
|
Statement::Statement(Session& session):
|
||||||
_asyncExec(_ptr, &StatementImpl::execute)
|
_async(false)
|
||||||
{
|
{
|
||||||
reset(session);
|
reset(session);
|
||||||
}
|
}
|
||||||
@@ -66,9 +65,9 @@ Statement::Statement(Session& session):
|
|||||||
|
|
||||||
Statement::Statement(const Statement& stmt):
|
Statement::Statement(const Statement& stmt):
|
||||||
_ptr(stmt._ptr),
|
_ptr(stmt._ptr),
|
||||||
_isAsync(stmt._isAsync),
|
_async(stmt._async),
|
||||||
_pResult(stmt._pResult),
|
_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)
|
void Statement::swap(Statement& other)
|
||||||
{
|
{
|
||||||
std::swap(_ptr, other._ptr);
|
std::swap(_ptr, other._ptr);
|
||||||
std::swap(_isAsync, other._isAsync);
|
std::swap(_async, other._async);
|
||||||
std::swap(_asyncExec, other._asyncExec);
|
std::swap(_pAsyncExec, other._pAsyncExec);
|
||||||
std::swap(_pResult, other._pResult);
|
std::swap(_pResult, other._pResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Statement& Statement::reset(Session& session)
|
||||||
|
{
|
||||||
|
Statement stmt(session.createStatementImpl());
|
||||||
|
swap(stmt);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Statement::ResultType Statement::execute()
|
Statement::ResultType Statement::execute()
|
||||||
{
|
{
|
||||||
Mutex::ScopedLock lock(_mutex);
|
Mutex::ScopedLock lock(_mutex);
|
||||||
@@ -129,12 +136,23 @@ const Statement::Result& Statement::executeAsync()
|
|||||||
const Statement::Result& Statement::doAsyncExec()
|
const Statement::Result& Statement::doAsyncExec()
|
||||||
{
|
{
|
||||||
if (done()) _ptr->reset();
|
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);
|
poco_check_ptr (_pResult);
|
||||||
return *_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)
|
Statement::ResultType Statement::wait(long milliseconds)
|
||||||
{
|
{
|
||||||
if (!_pResult) return 0;
|
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
|
const std::string& Statement::getStorage() const
|
||||||
{
|
{
|
||||||
switch (storage())
|
switch (storage())
|
||||||
|
|||||||
Reference in New Issue
Block a user