8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:03:02 +01:00

Implemented CORE-6320: Replace Util methods to get interface pointer by legacy handle with plain functions

This commit is contained in:
Alex Peshkoff 2020-05-29 15:43:59 +03:00
parent 86c497dfbf
commit a9cef6d9ae
8 changed files with 1430 additions and 1181 deletions

View File

@ -347,7 +347,8 @@ fb_get_master_interface
fb_get_database_handle
fb_get_transaction_handle
#fb_get_statement_interface
fb_get_transaction_interface
fb_get_statement_interface
fb_database_crypt_callback
fb_dsql_set_timeout

File diff suppressed because it is too large Load Diff

View File

@ -173,7 +173,8 @@ int main()
raiseError(status, st);
// get transaction interface
tra = utl->getTransactionByHandle(&status, &tr);
if (fb_get_transaction_interface(st, &tra, &tr))
raiseError(status, st);
//
printf("\nPart 1. BLOB created using IBlob interface.\n");
@ -184,7 +185,8 @@ int main()
if (isc_dsql_prepare(st, &tr, &stmt, 0, sqlStmt1, 3, NULL))
raiseError(status, st);
// and get it's interface
statemt = utl->getStatementByHandle(&status, &stmt);
if (fb_get_statement_interface(st, &statemt, &stmt))
raiseError(status, st);
// Message to store in a table
FB_MESSAGE(Msg1, ThrowStatusWrapper,
@ -235,7 +237,8 @@ int main()
if (isc_dsql_prepare(st, &tr, &stmt, 0, sqlStmt2, 3, NULL))
raiseError(status, st);
// and get it's interface
statemt = utl->getStatementByHandle(&status, &stmt);
if (fb_get_statement_interface(st, &statemt, &stmt))
raiseError(status, st);
// Message to store in a table
FB_MESSAGE(Msg2, ThrowStatusWrapper,

View File

@ -1113,8 +1113,6 @@ interface Util : Versioned
version: // 3.0 => 4.0 Alpha1
DecFloat16 getDecFloat16(Status status);
DecFloat34 getDecFloat34(Status status);
Transaction getTransactionByHandle(Status status, isc_tr_handle* hndlPtr);
Statement getStatementByHandle(Status status, isc_stmt_handle* hndlPtr);
void decodeTimeTz(Status status, const ISC_TIME_TZ* timeTz, uint* hours, uint* minutes, uint* seconds,
uint* fractions, uint timeZoneBufferLength, string timeZoneBuffer);
void decodeTimeStampTz(Status status, const ISC_TIMESTAMP_TZ* timeStampTz, uint* year, uint* month, uint* day,

View File

@ -4143,8 +4143,6 @@ namespace Firebird
unsigned (CLOOP_CARG *setOffsets)(IUtil* self, IStatus* status, IMessageMetadata* metadata, IOffsetsCallback* callback) throw();
IDecFloat16* (CLOOP_CARG *getDecFloat16)(IUtil* self, IStatus* status) throw();
IDecFloat34* (CLOOP_CARG *getDecFloat34)(IUtil* self, IStatus* status) throw();
ITransaction* (CLOOP_CARG *getTransactionByHandle)(IUtil* self, IStatus* status, isc_tr_handle* hndlPtr) throw();
IStatement* (CLOOP_CARG *getStatementByHandle)(IUtil* self, IStatus* status, isc_stmt_handle* hndlPtr) throw();
void (CLOOP_CARG *decodeTimeTz)(IUtil* self, IStatus* status, const ISC_TIME_TZ* timeTz, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions, unsigned timeZoneBufferLength, char* timeZoneBuffer) throw();
void (CLOOP_CARG *decodeTimeStampTz)(IUtil* self, IStatus* status, const ISC_TIMESTAMP_TZ* timeStampTz, unsigned* year, unsigned* month, unsigned* day, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions, unsigned timeZoneBufferLength, char* timeZoneBuffer) throw();
void (CLOOP_CARG *encodeTimeTz)(IUtil* self, IStatus* status, ISC_TIME_TZ* timeTz, unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions, const char* timeZone) throw();
@ -4281,34 +4279,6 @@ namespace Firebird
return ret;
}
template <typename StatusType> ITransaction* getTransactionByHandle(StatusType* status, isc_tr_handle* hndlPtr)
{
if (cloopVTable->version < 3)
{
StatusType::setVersionError(status, "IUtil", cloopVTable->version, 3);
StatusType::checkException(status);
return 0;
}
StatusType::clearException(status);
ITransaction* ret = static_cast<VTable*>(this->cloopVTable)->getTransactionByHandle(this, status, hndlPtr);
StatusType::checkException(status);
return ret;
}
template <typename StatusType> IStatement* getStatementByHandle(StatusType* status, isc_stmt_handle* hndlPtr)
{
if (cloopVTable->version < 3)
{
StatusType::setVersionError(status, "IUtil", cloopVTable->version, 3);
StatusType::checkException(status);
return 0;
}
StatusType::clearException(status);
IStatement* ret = static_cast<VTable*>(this->cloopVTable)->getStatementByHandle(this, status, hndlPtr);
StatusType::checkException(status);
return ret;
}
template <typename StatusType> void decodeTimeTz(StatusType* status, const ISC_TIME_TZ* timeTz, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions, unsigned timeZoneBufferLength, char* timeZoneBuffer)
{
if (cloopVTable->version < 3)
@ -14650,8 +14620,6 @@ namespace Firebird
this->setOffsets = &Name::cloopsetOffsetsDispatcher;
this->getDecFloat16 = &Name::cloopgetDecFloat16Dispatcher;
this->getDecFloat34 = &Name::cloopgetDecFloat34Dispatcher;
this->getTransactionByHandle = &Name::cloopgetTransactionByHandleDispatcher;
this->getStatementByHandle = &Name::cloopgetStatementByHandleDispatcher;
this->decodeTimeTz = &Name::cloopdecodeTimeTzDispatcher;
this->decodeTimeStampTz = &Name::cloopdecodeTimeStampTzDispatcher;
this->encodeTimeTz = &Name::cloopencodeTimeTzDispatcher;
@ -14872,36 +14840,6 @@ namespace Firebird
}
}
static ITransaction* CLOOP_CARG cloopgetTransactionByHandleDispatcher(IUtil* self, IStatus* status, isc_tr_handle* hndlPtr) throw()
{
StatusType status2(status);
try
{
return static_cast<Name*>(self)->Name::getTransactionByHandle(&status2, hndlPtr);
}
catch (...)
{
StatusType::catchException(&status2);
return static_cast<ITransaction*>(0);
}
}
static IStatement* CLOOP_CARG cloopgetStatementByHandleDispatcher(IUtil* self, IStatus* status, isc_stmt_handle* hndlPtr) throw()
{
StatusType status2(status);
try
{
return static_cast<Name*>(self)->Name::getStatementByHandle(&status2, hndlPtr);
}
catch (...)
{
StatusType::catchException(&status2);
return static_cast<IStatement*>(0);
}
}
static void CLOOP_CARG cloopdecodeTimeTzDispatcher(IUtil* self, IStatus* status, const ISC_TIME_TZ* timeTz, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions, unsigned timeZoneBufferLength, char* timeZoneBuffer) throw()
{
StatusType status2(status);
@ -15030,8 +14968,6 @@ namespace Firebird
virtual unsigned setOffsets(StatusType* status, IMessageMetadata* metadata, IOffsetsCallback* callback) = 0;
virtual IDecFloat16* getDecFloat16(StatusType* status) = 0;
virtual IDecFloat34* getDecFloat34(StatusType* status) = 0;
virtual ITransaction* getTransactionByHandle(StatusType* status, isc_tr_handle* hndlPtr) = 0;
virtual IStatement* getStatementByHandle(StatusType* status, isc_stmt_handle* hndlPtr) = 0;
virtual void decodeTimeTz(StatusType* status, const ISC_TIME_TZ* timeTz, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions, unsigned timeZoneBufferLength, char* timeZoneBuffer) = 0;
virtual void decodeTimeStampTz(StatusType* status, const ISC_TIMESTAMP_TZ* timeStampTz, unsigned* year, unsigned* month, unsigned* day, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions, unsigned timeZoneBufferLength, char* timeZoneBuffer) = 0;
virtual void encodeTimeTz(StatusType* status, ISC_TIME_TZ* timeTz, unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions, const char* timeZone) = 0;

View File

@ -1136,6 +1136,8 @@ ISC_STATUS ISC_EXPORT fb_ping(ISC_STATUS*, isc_db_handle*);
ISC_STATUS ISC_EXPORT fb_get_database_handle(ISC_STATUS*, isc_db_handle*, void*);
ISC_STATUS ISC_EXPORT fb_get_transaction_handle(ISC_STATUS*, isc_tr_handle*, void*);
ISC_STATUS ISC_EXPORT fb_get_transaction_interface(ISC_STATUS*, void*, isc_tr_handle*);
ISC_STATUS ISC_EXPORT fb_get_statement_interface(ISC_STATUS*, void*, isc_stmt_handle*);
/********************************/
/* Client information functions */

View File

@ -673,8 +673,6 @@ public:
Firebird::IOffsetsCallback* callback);
Firebird::IDecFloat16* getDecFloat16(Firebird::CheckStatusWrapper* status);
Firebird::IDecFloat34* getDecFloat34(Firebird::CheckStatusWrapper* status);
Firebird::ITransaction* getTransactionByHandle(Firebird::CheckStatusWrapper* status, isc_tr_handle* hndlPtr);
Firebird::IStatement* getStatementByHandle(Firebird::CheckStatusWrapper* status, isc_stmt_handle* hndlPtr);
void decodeTimeTz(Firebird::CheckStatusWrapper* status, const ISC_TIME_TZ* timeTz,
unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions,
unsigned timeZoneBufferLength, char* timeZoneBuffer);

View File

@ -3810,6 +3810,60 @@ ISC_STATUS API_ROUTINE fb_get_transaction_handle(ISC_STATUS* userStatus, isc_tr_
}
// Get transaction interface by legacy handle
ISC_STATUS API_ROUTINE fb_get_transaction_interface(ISC_STATUS* userStatus, void* iPtr,
isc_tr_handle* hndlPtr)
{
StatusVector status(userStatus);
CheckStatusWrapper statusWrapper(&status);
try
{
ITransaction** tra = (ITransaction**) iPtr;
if (*tra)
(Arg::Gds(isc_random) << "Interface must be null").raise();
RefPtr<YTransaction> transaction(translateHandle(transactions, hndlPtr));
transaction->addRef();
*tra = transaction;
}
catch (const Exception& e)
{
e.stuffException(&statusWrapper);
}
return status[1];
}
// Get statement interface by legacy handle
ISC_STATUS API_ROUTINE fb_get_statement_interface(ISC_STATUS* userStatus, void* iPtr,
isc_stmt_handle* hndlPtr)
{
StatusVector status(userStatus);
CheckStatusWrapper statusWrapper(&status);
try
{
IStatement** stmt = (IStatement**) iPtr;
if (*stmt)
(Arg::Gds(isc_random) << "Interface must be null").raise();
RefPtr<IscStatement> statement(translateHandle(statements, hndlPtr));
statement->checkPrepared(isc_info_unprepared_stmt);
*stmt = statement->getInterface();
}
catch (const Exception& e)
{
e.stuffException(&statusWrapper);
}
return status[1];
}
//-------------------------------------
namespace Why {
@ -6535,39 +6589,4 @@ void Dispatcher::setDbCryptCallback(CheckStatusWrapper* status, ICryptKeyCallbac
cryptCallback = callback;
}
ITransaction* UtilInterface::getTransactionByHandle(CheckStatusWrapper* status, isc_tr_handle* hndlPtr)
{
try
{
RefPtr<YTransaction> transaction(translateHandle(transactions, hndlPtr));
transaction->addRef();
return transaction;
}
catch (const Exception& e)
{
e.stuffException(status);
}
return nullptr;
}
IStatement* UtilInterface::getStatementByHandle(Firebird::CheckStatusWrapper* status, isc_stmt_handle* hndlPtr)
{
try
{
RefPtr<IscStatement> statement(translateHandle(statements, hndlPtr));
statement->checkPrepared(isc_info_unprepared_stmt);
return statement->getInterface();
}
catch (const Exception& e)
{
e.stuffException(status);
}
return nullptr;
}
} // namespace Why