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

Added dedicated method to close Batch interface with errors check

This commit is contained in:
AlexPeshkoff 2021-05-04 14:20:32 +03:00
parent 2967e353a6
commit d46b5182b2
10 changed files with 1167 additions and 1370 deletions

File diff suppressed because it is too large Load Diff

View File

@ -296,7 +296,7 @@ int main()
print_cs(status, cs, utl); print_cs(status, cs, utl);
// close batch // close batch
batch->release(); batch->close(&status);
batch = NULL; batch = NULL;
// //
@ -366,7 +366,7 @@ int main()
print_cs(status, cs, utl); print_cs(status, cs, utl);
// close batch // close batch
batch->release(); batch->close(&status);
batch = NULL; batch = NULL;
// //
@ -493,7 +493,7 @@ int main()
print_cs(status, cs, utl); print_cs(status, cs, utl);
// cleanup // cleanup
batch->release(); batch->close(&status);
batch = NULL; batch = NULL;
tra->commit(&status); tra->commit(&status);
tra = NULL; tra = NULL;

View File

@ -516,6 +516,9 @@ interface Batch : ReferenceCounted
uint getBlobAlignment(Status status); uint getBlobAlignment(Status status);
MessageMetadata getMetadata(Status status); MessageMetadata getMetadata(Status status);
void setDefaultBpb(Status status, uint parLength, const uchar* par); void setDefaultBpb(Status status, uint parLength, const uchar* par);
version: // added after FB4 RC1
void close(Status status);
} }
interface BatchCompletionState : Disposable interface BatchCompletionState : Disposable

View File

@ -1864,6 +1864,7 @@ namespace Firebird
unsigned (CLOOP_CARG *getBlobAlignment)(IBatch* self, IStatus* status) throw(); unsigned (CLOOP_CARG *getBlobAlignment)(IBatch* self, IStatus* status) throw();
IMessageMetadata* (CLOOP_CARG *getMetadata)(IBatch* self, IStatus* status) throw(); IMessageMetadata* (CLOOP_CARG *getMetadata)(IBatch* self, IStatus* status) throw();
void (CLOOP_CARG *setDefaultBpb)(IBatch* self, IStatus* status, unsigned parLength, const unsigned char* par) throw(); void (CLOOP_CARG *setDefaultBpb)(IBatch* self, IStatus* status, unsigned parLength, const unsigned char* par) throw();
void (CLOOP_CARG *close)(IBatch* self, IStatus* status) throw();
}; };
protected: protected:
@ -1877,7 +1878,7 @@ namespace Firebird
} }
public: public:
static const unsigned VERSION = 3; static const unsigned VERSION = 4;
static const unsigned char VERSION1 = 1; static const unsigned char VERSION1 = 1;
static const unsigned char TAG_MULTIERROR = 1; static const unsigned char TAG_MULTIERROR = 1;
@ -1963,6 +1964,19 @@ namespace Firebird
static_cast<VTable*>(this->cloopVTable)->setDefaultBpb(this, status, parLength, par); static_cast<VTable*>(this->cloopVTable)->setDefaultBpb(this, status, parLength, par);
StatusType::checkException(status); StatusType::checkException(status);
} }
template <typename StatusType> void close(StatusType* status)
{
if (cloopVTable->version < 4)
{
StatusType::setVersionError(status, "IBatch", cloopVTable->version, 4);
StatusType::checkException(status);
return;
}
StatusType::clearException(status);
static_cast<VTable*>(this->cloopVTable)->close(this, status);
StatusType::checkException(status);
}
}; };
class IBatchCompletionState : public IDisposable class IBatchCompletionState : public IDisposable
@ -9785,6 +9799,7 @@ namespace Firebird
this->getBlobAlignment = &Name::cloopgetBlobAlignmentDispatcher; this->getBlobAlignment = &Name::cloopgetBlobAlignmentDispatcher;
this->getMetadata = &Name::cloopgetMetadataDispatcher; this->getMetadata = &Name::cloopgetMetadataDispatcher;
this->setDefaultBpb = &Name::cloopsetDefaultBpbDispatcher; this->setDefaultBpb = &Name::cloopsetDefaultBpbDispatcher;
this->close = &Name::cloopcloseDispatcher;
} }
} vTable; } vTable;
@ -9934,6 +9949,20 @@ namespace Firebird
} }
} }
static void CLOOP_CARG cloopcloseDispatcher(IBatch* self, IStatus* status) throw()
{
StatusType status2(status);
try
{
static_cast<Name*>(self)->Name::close(&status2);
}
catch (...)
{
StatusType::catchException(&status2);
}
}
static void CLOOP_CARG cloopaddRefDispatcher(IReferenceCounted* self) throw() static void CLOOP_CARG cloopaddRefDispatcher(IReferenceCounted* self) throw()
{ {
try try
@ -9983,6 +10012,7 @@ namespace Firebird
virtual unsigned getBlobAlignment(StatusType* status) = 0; virtual unsigned getBlobAlignment(StatusType* status) = 0;
virtual IMessageMetadata* getMetadata(StatusType* status) = 0; virtual IMessageMetadata* getMetadata(StatusType* status) = 0;
virtual void setDefaultBpb(StatusType* status, unsigned parLength, const unsigned char* par) = 0; virtual void setDefaultBpb(StatusType* status, unsigned parLength, const unsigned char* par) = 0;
virtual void close(StatusType* status) = 0;
}; };
template <typename Name, typename StatusType, typename Base> template <typename Name, typename StatusType, typename Base>

View File

@ -355,6 +355,7 @@ type
IBatch_getBlobAlignmentPtr = function(this: IBatch; status: IStatus): Cardinal; cdecl; IBatch_getBlobAlignmentPtr = function(this: IBatch; status: IStatus): Cardinal; cdecl;
IBatch_getMetadataPtr = function(this: IBatch; status: IStatus): IMessageMetadata; cdecl; IBatch_getMetadataPtr = function(this: IBatch; status: IStatus): IMessageMetadata; cdecl;
IBatch_setDefaultBpbPtr = procedure(this: IBatch; status: IStatus; parLength: Cardinal; par: BytePtr); cdecl; IBatch_setDefaultBpbPtr = procedure(this: IBatch; status: IStatus; parLength: Cardinal; par: BytePtr); cdecl;
IBatch_closePtr = procedure(this: IBatch; status: IStatus); cdecl;
IBatchCompletionState_getSizePtr = function(this: IBatchCompletionState; status: IStatus): Cardinal; cdecl; IBatchCompletionState_getSizePtr = function(this: IBatchCompletionState; status: IStatus): Cardinal; cdecl;
IBatchCompletionState_getStatePtr = function(this: IBatchCompletionState; status: IStatus; pos: Cardinal): Integer; cdecl; IBatchCompletionState_getStatePtr = function(this: IBatchCompletionState; status: IStatus; pos: Cardinal): Integer; cdecl;
IBatchCompletionState_findErrorPtr = function(this: IBatchCompletionState; status: IStatus; pos: Cardinal): Cardinal; cdecl; IBatchCompletionState_findErrorPtr = function(this: IBatchCompletionState; status: IStatus; pos: Cardinal): Cardinal; cdecl;
@ -1508,10 +1509,11 @@ type
getBlobAlignment: IBatch_getBlobAlignmentPtr; getBlobAlignment: IBatch_getBlobAlignmentPtr;
getMetadata: IBatch_getMetadataPtr; getMetadata: IBatch_getMetadataPtr;
setDefaultBpb: IBatch_setDefaultBpbPtr; setDefaultBpb: IBatch_setDefaultBpbPtr;
close: IBatch_closePtr;
end; end;
IBatch = class(IReferenceCounted) IBatch = class(IReferenceCounted)
const VERSION = 3; const VERSION = 4;
const VERSION1 = Byte(1); const VERSION1 = Byte(1);
const TAG_MULTIERROR = Byte(1); const TAG_MULTIERROR = Byte(1);
const TAG_RECORD_COUNTS = Byte(2); const TAG_RECORD_COUNTS = Byte(2);
@ -1534,6 +1536,7 @@ type
function getBlobAlignment(status: IStatus): Cardinal; function getBlobAlignment(status: IStatus): Cardinal;
function getMetadata(status: IStatus): IMessageMetadata; function getMetadata(status: IStatus): IMessageMetadata;
procedure setDefaultBpb(status: IStatus; parLength: Cardinal; par: BytePtr); procedure setDefaultBpb(status: IStatus; parLength: Cardinal; par: BytePtr);
procedure close(status: IStatus);
end; end;
IBatchImpl = class(IBatch) IBatchImpl = class(IBatch)
@ -1551,6 +1554,7 @@ type
function getBlobAlignment(status: IStatus): Cardinal; virtual; abstract; function getBlobAlignment(status: IStatus): Cardinal; virtual; abstract;
function getMetadata(status: IStatus): IMessageMetadata; virtual; abstract; function getMetadata(status: IStatus): IMessageMetadata; virtual; abstract;
procedure setDefaultBpb(status: IStatus; parLength: Cardinal; par: BytePtr); virtual; abstract; procedure setDefaultBpb(status: IStatus; parLength: Cardinal; par: BytePtr); virtual; abstract;
procedure close(status: IStatus); virtual; abstract;
end; end;
BatchCompletionStateVTable = class(DisposableVTable) BatchCompletionStateVTable = class(DisposableVTable)
@ -6419,6 +6423,12 @@ begin
FbException.checkException(status); FbException.checkException(status);
end; end;
procedure IBatch.close(status: IStatus);
begin
BatchVTable(vTable).close(Self, status);
FbException.checkException(status);
end;
function IBatchCompletionState.getSize(status: IStatus): Cardinal; function IBatchCompletionState.getSize(status: IStatus): Cardinal;
begin begin
Result := BatchCompletionStateVTable(vTable).getSize(Self, status); Result := BatchCompletionStateVTable(vTable).getSize(Self, status);
@ -10106,6 +10116,15 @@ begin
end end
end; end;
procedure IBatchImpl_closeDispatcher(this: IBatch; status: IStatus); cdecl;
begin
try
IBatchImpl(this).close(status);
except
on e: Exception do FbException.catchException(status, e);
end
end;
var var
IBatchImpl_vTable: BatchVTable; IBatchImpl_vTable: BatchVTable;
@ -14942,7 +14961,7 @@ initialization
IStatementImpl_vTable.createBatch := @IStatementImpl_createBatchDispatcher; IStatementImpl_vTable.createBatch := @IStatementImpl_createBatchDispatcher;
IBatchImpl_vTable := BatchVTable.create; IBatchImpl_vTable := BatchVTable.create;
IBatchImpl_vTable.version := 3; IBatchImpl_vTable.version := 4;
IBatchImpl_vTable.addRef := @IBatchImpl_addRefDispatcher; IBatchImpl_vTable.addRef := @IBatchImpl_addRefDispatcher;
IBatchImpl_vTable.release := @IBatchImpl_releaseDispatcher; IBatchImpl_vTable.release := @IBatchImpl_releaseDispatcher;
IBatchImpl_vTable.add := @IBatchImpl_addDispatcher; IBatchImpl_vTable.add := @IBatchImpl_addDispatcher;
@ -14955,6 +14974,7 @@ initialization
IBatchImpl_vTable.getBlobAlignment := @IBatchImpl_getBlobAlignmentDispatcher; IBatchImpl_vTable.getBlobAlignment := @IBatchImpl_getBlobAlignmentDispatcher;
IBatchImpl_vTable.getMetadata := @IBatchImpl_getMetadataDispatcher; IBatchImpl_vTable.getMetadata := @IBatchImpl_getMetadataDispatcher;
IBatchImpl_vTable.setDefaultBpb := @IBatchImpl_setDefaultBpbDispatcher; IBatchImpl_vTable.setDefaultBpb := @IBatchImpl_setDefaultBpbDispatcher;
IBatchImpl_vTable.close := @IBatchImpl_closeDispatcher;
IBatchCompletionStateImpl_vTable := BatchCompletionStateVTable.create; IBatchCompletionStateImpl_vTable := BatchCompletionStateVTable.create;
IBatchCompletionStateImpl_vTable.version := 3; IBatchCompletionStateImpl_vTable.version := 3;

View File

@ -201,6 +201,7 @@ public:
unsigned getBlobAlignment(Firebird::CheckStatusWrapper* status) override; unsigned getBlobAlignment(Firebird::CheckStatusWrapper* status) override;
Firebird::IMessageMetadata* getMetadata(Firebird::CheckStatusWrapper* status) override; Firebird::IMessageMetadata* getMetadata(Firebird::CheckStatusWrapper* status) override;
void setDefaultBpb(Firebird::CheckStatusWrapper* status, unsigned parLength, const unsigned char* par) override; void setDefaultBpb(Firebird::CheckStatusWrapper* status, unsigned parLength, const unsigned char* par) override;
void close(Firebird::CheckStatusWrapper* status) override;
public: public:
JBatch(DsqlBatch* handle, JStatement* aStatement, Firebird::IMessageMetadata* aMetadata); JBatch(DsqlBatch* handle, JStatement* aStatement, Firebird::IMessageMetadata* aMetadata);

View File

@ -5877,6 +5877,13 @@ int JBatch::release()
return 0; return 0;
} }
void JBatch::close(CheckStatusWrapper* user_status)
{
freeEngineData(user_status);
}
void JBatch::freeEngineData(Firebird::CheckStatusWrapper* user_status) void JBatch::freeEngineData(Firebird::CheckStatusWrapper* user_status)
{ {
try try
@ -5890,6 +5897,7 @@ void JBatch::freeEngineData(Firebird::CheckStatusWrapper* user_status)
if (att) if (att)
att->deregisterBatch(this); att->deregisterBatch(this);
delete batch; delete batch;
batch = nullptr;
} }
catch (const Exception& ex) catch (const Exception& ex)
{ {

View File

@ -339,6 +339,7 @@ public:
unsigned getBlobAlignment(Firebird::CheckStatusWrapper* status) override; unsigned getBlobAlignment(Firebird::CheckStatusWrapper* status) override;
void setDefaultBpb(Firebird::CheckStatusWrapper* status, unsigned parLength, const unsigned char* par) override; void setDefaultBpb(Firebird::CheckStatusWrapper* status, unsigned parLength, const unsigned char* par) override;
Firebird::IMessageMetadata* getMetadata(Firebird::CheckStatusWrapper* status) override; Firebird::IMessageMetadata* getMetadata(Firebird::CheckStatusWrapper* status) override;
void close(Firebird::CheckStatusWrapper* status) override;
private: private:
void freeClientData(CheckStatusWrapper* status, bool force = false); void freeClientData(CheckStatusWrapper* status, bool force = false);
@ -2809,6 +2810,13 @@ void Batch::freeClientData(CheckStatusWrapper* status, bool force)
} }
void Batch::close(CheckStatusWrapper* status)
{
reset(status);
freeClientData(status);
}
void Batch::releaseStatement() void Batch::releaseStatement()
{ {
if (tmpStatement) if (tmpStatement)

View File

@ -383,6 +383,7 @@ public:
Firebird::IBatchCompletionState* execute(Firebird::CheckStatusWrapper* status, Firebird::ITransaction* transaction); Firebird::IBatchCompletionState* execute(Firebird::CheckStatusWrapper* status, Firebird::ITransaction* transaction);
void cancel(Firebird::CheckStatusWrapper* status); void cancel(Firebird::CheckStatusWrapper* status);
void setDefaultBpb(Firebird::CheckStatusWrapper* status, unsigned parLength, const unsigned char* par); void setDefaultBpb(Firebird::CheckStatusWrapper* status, unsigned parLength, const unsigned char* par);
void close(Firebird::CheckStatusWrapper* status);
public: public:
AtomicAttPtr attachment; AtomicAttPtr attachment;

View File

@ -5028,6 +5028,25 @@ void YBatch::cancel(CheckStatusWrapper* status)
} }
void YBatch::close(CheckStatusWrapper* status)
{
try
{
YEntry<YBatch> entry(status, this, CHECK_WARN_ZERO_HANDLE);
if (entry.next())
entry.next()->close(status);
if (!(status->getState() & IStatus::STATE_ERRORS))
destroy(DF_RELEASE);
}
catch (const Exception& e)
{
e.stuffException(status);
}
}
//------------------------------------- //-------------------------------------