added Poco::Data::Session::isGood()

This commit is contained in:
Günter Obiltschnig
2020-01-13 20:13:27 +01:00
parent c04a1f28d9
commit 43b79ffdbe
13 changed files with 200 additions and 44 deletions

View File

@@ -21,10 +21,10 @@ namespace MySQL {
MySQLStatementImpl::MySQLStatementImpl(SessionImpl& h) :
Poco::Data::StatementImpl(h),
_stmt(h.handle()),
Poco::Data::StatementImpl(h),
_stmt(h.handle()),
_pBinder(new Binder),
_pExtractor(new Extractor(_stmt, _metadata)),
_pExtractor(new Extractor(_stmt, _metadata)),
_hasNext(NEXT_DONTKNOW)
{
}
@@ -46,13 +46,13 @@ int MySQLStatementImpl::affectedRowCount() const
return _stmt.getAffectedRowCount();
}
const MetaColumn& MySQLStatementImpl::metaColumn(std::size_t pos) const
{
return _metadata.metaColumn(pos);
}
bool MySQLStatementImpl::hasNext()
{
if (_hasNext == NEXT_DONTKNOW)
@@ -79,11 +79,11 @@ bool MySQLStatementImpl::hasNext()
return false;
}
std::size_t MySQLStatementImpl::next()
{
if (!hasNext())
throw StatementException("No data received");
throw StatementException("No data received");
Poco::Data::AbstractExtractionVec::iterator it = extractions().begin();
Poco::Data::AbstractExtractionVec::iterator itEnd = extractions().end();
@@ -119,12 +119,21 @@ bool MySQLStatementImpl::canCompile() const
void MySQLStatementImpl::compileImpl()
{
_metadata.reset();
_stmt.prepare(toString());
_metadata.init(_stmt);
try
{
_metadata.reset();
_stmt.prepare(toString());
_metadata.init(_stmt);
if (_metadata.columnsReturned() > 0)
_stmt.bindResult(_metadata.row());
if (_metadata.columnsReturned() > 0)
_stmt.bindResult(_metadata.row());
}
catch (MySQLException& exc)
{
static_cast<SessionImpl&>(session()).setLastError(exc.code());
throw;
}
static_cast<SessionImpl&>(session()).setLastError(0);
}
@@ -141,8 +150,17 @@ void MySQLStatementImpl::bindImpl()
}
_stmt.bindParams(_pBinder->getBindArray(), _pBinder->size());
_stmt.execute();
try
{
_stmt.execute();
}
catch (MySQLException& exc)
{
static_cast<SessionImpl&>(session()).setLastError(exc.code());
throw;
}
_hasNext = NEXT_DONTKNOW;
static_cast<SessionImpl&>(session()).setLastError(0);
}