Subject | Re: [ib-support] an example of udf |
---|---|
Author | R. Tulloch |
Post date | 2002-07-17T18:57:26Z |
Hi:
For IB but the same
CSTRING(80) CHARACTER SET NONE
RETURNS INTEGER BY VALUE
ENTRY_POINT 'fn_ClearIbLog' MODULE_NAME 'ltudf';
//---------------------------------------------------------------------------
void __fastcall TIBAdminControl::ClearLogBtnClick(TObject *Sender)
{
//If log, clear text and save back to source file
if (DisplayKind == DataBaseLog)
{
//Verify user want to clear the log
if (Application->MessageBox("This will clear the Interbase
History log. Are you "
"sure you want to clear the log?",
"Clear Interbase History Log",
MB_YESNO | MB_ICONWARNING) == IDNO)
return;
if (!IBControlDM->IBControlTransaction->Active)
IBControlDM->IBControlTransaction->StartTransaction();
IBControlDM->IBClearLogSQL->Prepare();
String IBLogPath = MainForm->InterBaseRootPath +
"interbase.log";
IBControlDM->IBClearLogSQL->Params->ByName("FilePath")->AsString
= IBLogPath;
try
{
IBControlDM->IBClearLogSQL->ExecQuery();
IBControlDM->IBControlTransaction->CommitRetaining();
}
catch(EIBError *E)
{
DisplayMsg(ERR_SERVER_LOGIN, E->Message);
IBControlDM->IBControlTransaction->RollbackRetaining();
IBControlDM->IBClearLogSQL->Close();
IBControlDM->IBControlTransaction->Active = false;
}
bool Result =
IBControlDM->IBClearLogSQL->FieldByName("RESULT")->AsInteger;
// if
(IBControlDM->IBClearLogSQL->FieldByName("RESULT")->AsInteger == 0
)//String != "True")
if (!Result)
{
Application->MessageBox("The attempt to clear the Interbase
Log failed. "
"It can be cleared manually by using
Notepad.exe.",
"Clear Interbase Log File",
MB_OK |MB_ICONWARNING);
IBControlDM->IBClearLogSQL->Close();
IBControlDM->IBControlTransaction->Active = false;
return;
}
else
{
IBControlDM->IBClearLogSQL->Close();
IBControlDM->IBControlTransaction->Active = false;
IBDisplayMemo->Clear();
LogBtnClick(this);
return;
}
}
IBDisplayMemo->Clear();
}
The IBClearLogSQL statement:
SELECT * FROM CLEARLOG(:FilePath)
For IB but the same
> Somebody pls send me an example of attaching a UDF toDECLARE EXTERNAL FUNCTION CLEARIBLOG
> a FB database and selecting it in a sql statment.
>
> I am using Firebird 1 on W2k.
CSTRING(80) CHARACTER SET NONE
RETURNS INTEGER BY VALUE
ENTRY_POINT 'fn_ClearIbLog' MODULE_NAME 'ltudf';
//---------------------------------------------------------------------------
void __fastcall TIBAdminControl::ClearLogBtnClick(TObject *Sender)
{
//If log, clear text and save back to source file
if (DisplayKind == DataBaseLog)
{
//Verify user want to clear the log
if (Application->MessageBox("This will clear the Interbase
History log. Are you "
"sure you want to clear the log?",
"Clear Interbase History Log",
MB_YESNO | MB_ICONWARNING) == IDNO)
return;
if (!IBControlDM->IBControlTransaction->Active)
IBControlDM->IBControlTransaction->StartTransaction();
IBControlDM->IBClearLogSQL->Prepare();
String IBLogPath = MainForm->InterBaseRootPath +
"interbase.log";
IBControlDM->IBClearLogSQL->Params->ByName("FilePath")->AsString
= IBLogPath;
try
{
IBControlDM->IBClearLogSQL->ExecQuery();
IBControlDM->IBControlTransaction->CommitRetaining();
}
catch(EIBError *E)
{
DisplayMsg(ERR_SERVER_LOGIN, E->Message);
IBControlDM->IBControlTransaction->RollbackRetaining();
IBControlDM->IBClearLogSQL->Close();
IBControlDM->IBControlTransaction->Active = false;
}
bool Result =
IBControlDM->IBClearLogSQL->FieldByName("RESULT")->AsInteger;
// if
(IBControlDM->IBClearLogSQL->FieldByName("RESULT")->AsInteger == 0
)//String != "True")
if (!Result)
{
Application->MessageBox("The attempt to clear the Interbase
Log failed. "
"It can be cleared manually by using
Notepad.exe.",
"Clear Interbase Log File",
MB_OK |MB_ICONWARNING);
IBControlDM->IBClearLogSQL->Close();
IBControlDM->IBControlTransaction->Active = false;
return;
}
else
{
IBControlDM->IBClearLogSQL->Close();
IBControlDM->IBControlTransaction->Active = false;
IBDisplayMemo->Clear();
LogBtnClick(this);
return;
}
}
IBDisplayMemo->Clear();
}
The IBClearLogSQL statement:
SELECT * FROM CLEARLOG(:FilePath)