![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » DBISAM Technical Support » Product Manuals » DBISAM Version 4 Manual for RAD Studio XE7 (C++ Win32) » Using DBISAM » Customizing the Engine |
void __fastcall TMyForm::EngineBeforeDeleteTrigger(TObject *Sender, TDBISAMSession *TriggerSession, TDBISAMDatabase *TriggerDatabase, const AnsiString TableName, TDBISAMRecord *CurrentRecord) { TDBISAMQuery *OrdersQuery; if (AnsiCompareText(TableName,"customer")==0) { TDBISAMQuery *OrdersQuery=TDBISAMQuery->Create(nil); try { OrdersQuery->SessionName=TriggerDatabase->SessionName; OrdersQuery->DatabaseName=TriggerDatabase->DatabaseName; OrdersQuery->RequestLive=true; OrdersQuery->SQL->Text="SELECT * FROM Orders "+ "WHERE CustNo=:CustNo AND "+ "AmountPaid < ItemsTotal"; OrdersQuery->ParamByName("CustNo")->AsFloat= CurrentRecord->FieldByName("CustNo")->AsFloat; OrdersQuery->Open(); try if(RecordCount > 0) { throw Exception("Cannot delete this "+ "customer, there are still "+ IntToStr(RecordCount)+' active "+ "orders present for this "+ "customer"); } __finally { OrdersQuery->Close(); } } __finally { delete OrdersQuery; } } }
{ // We'll just use the default Engine global function // for this example TDBISAMFunction *NewFunction=Engine()->Functions-> CreateFunction(ftInteger,"DaysBetween"); NewFunction->CreateFunctionParam(ftDate); NewFunction->CreateFunctionParam(ftDate); }
void __fastcall TMyForm::CustomFunction(TObject *Sender, const AnsiString FunctionName, TDBISAMParams *FunctionParams, Variant &Result) { if (AnsiCompareText(FunctionName,"DaysBetween")==0) { // Notice that the function parameters are accessed // in a 0-based manner TTimeStamp Stamp1=DateTimeToTimeStamp( FunctionParams->Items[0]->AsDateTime); TTimeStamp Stamp2=DateTimeToTimeStamp( FunctionParams->Items[1]->AsDateTime); Result=Trunc((Stamp2.Date-Stamp1.Date)+ (((((Stamp2.Time-Stamp1.Time)/1000)/60)/60)/24)); } }
Extensions | Properties |
Event | Description |
OnServerStart | This event will be triggered whenever the server starts listening for incoming normal data connections. The server is started via the TDBISAMEngine StartMainServer method or remotely via the TDBISAMSession StartRemoteServer method. |
OnServerStop | This event will be triggered whenever the server stops listening for incoming noraml data connections. The server is stopped via the TDBISAMEngine StopMainServer method or remotely via the TDBISAMSession StopRemoteServer method. |
OnServerConnect | This event will be triggered whenever a normal data connection is established. |
OnServerReconnect | This event will be triggered whenever a normal data connection is re-established by an automatic reconnection by the remote session. |
OnServerLogin | This event will be triggered whenever a user logs in on a normal data connection. |
OnServerLogout | This event will be triggered whenever a user logs out on a normal data connection. |
OnServerDisconnect | This event will be triggered whenever a normal data connection is closed. |
Event | Description |
OnServerLogEvent | This event is triggered whenever the server needs to log an event. The log record that is passed to the event handler is defined as a TLogRecord type. |
OnServerLogCount | This event is triggered whenever the server needs to get a count of the number of log records in the current log. This event is triggered whenever the TDBISAMEngine GetServerLogCount method is called or the TDBISAMSession GetRemoteLogCount method is called by a remote session. |
OnServerLogRecord | This event is triggered whenever the server needs to get a specific log record from the current log. This event is triggered whenever the TDBISAMEngine GetServerLogRecord method is called or the TDBISAMSession GetRemoteLogRecord method is called by a remote session. |
void __fastcall TMyForm::ServerScheduledEvent(TObject *Sender, const AnsiString EventName, bool &Completed) { AnsiString TempDescription=""; AnsiString TempPath=""; if (AnsiCompareText(EventName,"DailyBackup")==0) { // Create a new session component, remembering // the multi-threading requirements of DBISAM // for session names TDBISAMSession *TempSession=new TDBISAMSession(this); try { TempSession->SessionName="DailyBackup"+ IntToStr(GetCurrentThreadID); TempSession->Active=true; // Create a new database component TDBISAMDatabase *TempDatabase=new TDBISAMDatabase(this); try { TempDatabase->SessionName=TempSession->SessionName; TempDatabase->DatabaseName="DailyBackup"; // Get the actual local path for the Main // database Engine()->GetServerDatabase("Main", TempDescription, TempPath); TempDatabase->Directory=TempPath; TempDatabase->Connected=true; TStringList *BackupFiles=new TStringList; try { TempSession->GetTableNames(DatabaseName,BackupFiles); Completed=TempDatabase->Backup( IncludeTrailingBackslash(TempPath)+"backup"+ StringReplace(DateToStr(Date),"/", "",[rfReplaceAll])+".bkp", "Daily Backup for "+DateToStr(Date),6,BackupFiles); } __finally { delete BackupFiles; } TempDatabase->Connected=false; } __finally { delete TempDatabase; } } __finally { delete TempSession; } } else { Completed=true; } }
void __fastcall TMyForm::ServerProcedure(TObject *Sender, TDBISAMSession *ServerSession, const AnsiString ProcedureName) { AnsiString TempFileName=""; if (AnsiCompareText(ProcedureName,"TextFile")==0) { TempFileName=ServerSession->RemoteParams-> ParamByName("FileName")->AsString; // Now clear the parameters for use in populating // the result parameters ServerSession->RemoteParams->Clear; if (FileExists(TempFileName)) { // If the file exists, use the TDBISAMParam // LoadFromFile method to load the file // data into the parameter ServerSession->RemoteParams-> CreateParam(ftMemo,"FileContents")-> LoadFromFile(TempFileName,ftMemo); } else { // If the file doesn't exist, just create a NULL // parameter with the correct result name ServerSession->RemoteParams-> CreateParam(ftMemo,"FileContents"); } } }
This web page was last updated on Thursday, November 16, 2023 at 10:39 AM | Privacy Policy![]() © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |