2008-03-13 17:37:20 +01:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Adriano dos Santos Fernandes
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Adriano dos Santos Fernandes <adrianosf@uol.com.br>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../jrd/ResultSet.h"
|
|
|
|
#include "../jrd/PreparedStatement.h"
|
|
|
|
#include "../jrd/align.h"
|
|
|
|
#include "../jrd/jrd.h"
|
2010-01-03 21:56:39 +01:00
|
|
|
#include "../jrd/req.h"
|
2008-03-13 17:37:20 +01:00
|
|
|
#include "../dsql/dsql.h"
|
|
|
|
#include "../dsql/sqlda_pub.h"
|
|
|
|
#include "../dsql/dsql_proto.h"
|
2010-01-03 21:56:39 +01:00
|
|
|
#include "../jrd/mov_proto.h"
|
|
|
|
|
|
|
|
using namespace Firebird;
|
2008-03-13 17:37:20 +01:00
|
|
|
|
|
|
|
namespace Jrd {
|
|
|
|
|
|
|
|
|
|
|
|
ResultSet::ResultSet(thread_db* tdbb, PreparedStatement* aStmt, jrd_tra* aTransaction)
|
|
|
|
: stmt(aStmt),
|
|
|
|
transaction(aTransaction),
|
2008-06-27 15:31:04 +02:00
|
|
|
firstFetchDone(false)
|
2008-03-13 17:37:20 +01:00
|
|
|
{
|
2013-02-17 13:08:53 +01:00
|
|
|
stmt->open(tdbb, transaction);
|
2008-03-13 17:37:20 +01:00
|
|
|
stmt->resultSet = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ResultSet::~ResultSet()
|
|
|
|
{
|
|
|
|
if (!stmt)
|
|
|
|
return;
|
|
|
|
|
|
|
|
thread_db* tdbb = JRD_get_thread_data();
|
|
|
|
|
|
|
|
stmt->resultSet = NULL;
|
|
|
|
|
2009-12-23 01:57:08 +01:00
|
|
|
if (stmt->request->getStatement()->getType() != DsqlCompiledStatement::TYPE_EXEC_PROCEDURE)
|
2008-03-13 17:37:20 +01:00
|
|
|
DSQL_free_statement(tdbb, stmt->request, DSQL_close);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ResultSet::fetch(thread_db* tdbb)
|
|
|
|
{
|
2009-12-23 01:57:08 +01:00
|
|
|
if (stmt->request->getStatement()->getType() == DsqlCompiledStatement::TYPE_EXEC_PROCEDURE &&
|
|
|
|
firstFetchDone)
|
|
|
|
{
|
2008-03-13 17:37:20 +01:00
|
|
|
return false;
|
2009-12-23 01:57:08 +01:00
|
|
|
}
|
2008-03-13 17:37:20 +01:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
memset(stmt->outMessage.begin(), 0, stmt->outMessage.getCount());
|
2008-03-13 17:37:20 +01:00
|
|
|
|
2013-02-17 13:08:53 +01:00
|
|
|
if (!stmt->request->fetch(tdbb, stmt->outMessage.begin()))
|
2008-03-13 17:37:20 +01:00
|
|
|
return false;
|
|
|
|
|
2010-01-02 22:46:11 +01:00
|
|
|
if (stmt->builder)
|
|
|
|
stmt->builder->moveFromResultSet(tdbb, this);
|
|
|
|
|
2008-06-27 15:31:04 +02:00
|
|
|
firstFetchDone = true;
|
2008-03-13 17:37:20 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-19 16:00:18 +01:00
|
|
|
bool ResultSet::isNull(unsigned param) const
|
2008-03-13 17:37:20 +01:00
|
|
|
{
|
2009-12-19 16:00:18 +01:00
|
|
|
fb_assert(param > 0);
|
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
const dsc* desc = &stmt->outValues[(param - 1) * 2 + 1];
|
2008-03-13 17:37:20 +01:00
|
|
|
fb_assert(desc->dsc_dtype == dtype_short);
|
|
|
|
|
2008-03-15 11:25:30 +01:00
|
|
|
return *reinterpret_cast<SSHORT*>(desc->dsc_address) != 0;
|
2008-03-13 17:37:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-19 16:00:18 +01:00
|
|
|
dsc& ResultSet::getDesc(unsigned param)
|
2008-03-13 17:37:20 +01:00
|
|
|
{
|
2009-12-19 16:00:18 +01:00
|
|
|
fb_assert(param > 0);
|
2009-10-21 02:42:38 +02:00
|
|
|
return stmt->outValues[(param - 1) * 2];
|
2008-03-13 17:37:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-03 21:56:39 +01:00
|
|
|
Firebird::string ResultSet::getString(thread_db* tdbb, unsigned param)
|
|
|
|
{
|
|
|
|
fb_assert(param > 0);
|
|
|
|
|
2010-04-19 00:19:11 +02:00
|
|
|
jrd_req* jrdRequest = stmt->getRequest()->req_request;
|
|
|
|
|
2010-01-03 21:56:39 +01:00
|
|
|
// Setup tdbb info necessary for blobs.
|
|
|
|
AutoSetRestore2<jrd_req*, thread_db> autoRequest(
|
2010-04-19 00:19:11 +02:00
|
|
|
tdbb, &thread_db::getRequest, &thread_db::setRequest, jrdRequest);
|
|
|
|
AutoSetRestore<jrd_tra*> autoRequestTrans(&jrdRequest->req_transaction,
|
2010-01-03 21:56:39 +01:00
|
|
|
tdbb->getTransaction());
|
|
|
|
|
|
|
|
return MOV_make_string2(tdbb, &getDesc(param), CS_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Firebird::MetaName ResultSet::getMetaName(thread_db* tdbb, unsigned param)
|
|
|
|
{
|
|
|
|
fb_assert(param > 0);
|
|
|
|
|
2010-04-19 00:19:11 +02:00
|
|
|
jrd_req* jrdRequest = stmt->getRequest()->req_request;
|
|
|
|
|
2010-01-03 21:56:39 +01:00
|
|
|
// Setup tdbb info necessary for blobs.
|
|
|
|
AutoSetRestore2<jrd_req*, thread_db> autoRequest(
|
2010-04-19 00:19:11 +02:00
|
|
|
tdbb, &thread_db::getRequest, &thread_db::setRequest, jrdRequest);
|
|
|
|
AutoSetRestore<jrd_tra*> autoRequestTrans(&jrdRequest->req_transaction,
|
2010-01-03 21:56:39 +01:00
|
|
|
tdbb->getTransaction());
|
|
|
|
|
|
|
|
return MOV_make_string2(tdbb, &getDesc(param), CS_METADATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ResultSet::moveDesc(thread_db* tdbb, unsigned param, dsc& desc)
|
|
|
|
{
|
|
|
|
fb_assert(param > 0);
|
|
|
|
|
2010-04-19 00:19:11 +02:00
|
|
|
jrd_req* jrdRequest = stmt->getRequest()->req_request;
|
|
|
|
|
2010-01-03 21:56:39 +01:00
|
|
|
// Setup tdbb info necessary for blobs.
|
|
|
|
AutoSetRestore2<jrd_req*, thread_db> autoRequest(
|
2010-04-19 00:19:11 +02:00
|
|
|
tdbb, &thread_db::getRequest, &thread_db::setRequest, jrdRequest);
|
|
|
|
AutoSetRestore<jrd_tra*> autoRequestTrans(&jrdRequest->req_transaction,
|
2010-01-03 21:56:39 +01:00
|
|
|
tdbb->getTransaction());
|
|
|
|
|
|
|
|
MOV_move(tdbb, &getDesc(param), &desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-13 17:37:20 +01:00
|
|
|
} // namespace
|