![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » DBISAM Technical Support » Product Manuals » DBISAM Version 4 Manual for RAD Studio XE (Delphi) » Advanced Topics » Multi-Threaded Applications |
var LastSessionValue: Integer; SessionNameSection: TRTLCriticalSection; { Assume that the following code is being executed within a thread } function UpdateAccounts: Boolean; var LocalSession: TDBISAMSession; LocalDatabase: TDBISAMDatabase; LocalQuery: TDBISAMQuery; begin Result:=False; LocalSession:=GetNewSession; try LocalDatabase:=TDBISAMDatabase.Create(nil); try with LocalDatabase do begin { Be sure to assign the same session name as the TDBISAMSession component } SessionName:=LocalSession.SessionName; DatabaseName:='Accounts'; Directory:='g:\accountdb'; Connected:=True; end; LocalQuery:=TDBISAMQuery.Create(nil); try with LocalQuery do begin { Be sure to assign the same session and database name as the TDBISAMDatabase component } SessionName:=LocalSession.SessionName; DatabaseName:=LocalDatabase.DatabaseName; SQL.Clear; SQL.Add('UPDATE accounts SET PastDue=True'); SQL.Add('WHERE DueDate < CURRENT_DATE')); Prepare; try { Start the transaction and execute the query } LocalDatabase.StartTransaction; try ExecSQL; LocalDatabase.Commit; Result:=True; except LocalDatabase.Rollback; end; finally UnPrepare; end; end; finally LocalQuery.Free; end; finally LocalDatabase.Free; end; finally LocalSession.Free; end; end; function GetNewSession: TDBISAMSession; begin EnterCriticalSection(SessionNameSection); try LastSessionValue:=LastSessionValue+1; Result:=TDBISAMSession.Create(nil); with Result do SessionName:='AccountSession'+IntToStr(LastSessionValue); finally LeaveCriticalSection(SessionNameSection); end; end; { initialization in application } LastSessionValue:=0; InitializeCriticalSection(SessionNameSection); { finalization in application } DeleteCriticalSection(SessionNameSection);
This web page was last updated on Friday, January 20, 2023 at 07:13 AM | Privacy Policy![]() © 2023 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |