Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Product Manuals » ElevateDB Version 2 Manual for RAD Studio 10 (Delphi Win32) » Getting Started » Multi-Threaded Applications |
var LastSessionValue: Integer; SessionNameSection: TRTLCriticalSection; { Assume that the following code is being executed within a thread } function UpdateAccounts: Boolean; var LocalSession: TEDBSession; LocalDatabase: TEDBDatabase; LocalQuery: TEDBQuery; begin Result:=False; LocalSession:=GetNewSession; try LocalDatabase:=TEDBDatabase.Create(nil); try with LocalDatabase do begin { Be sure to assign the same session name as the TEDBSession component } SessionName:=LocalSession.SessionName; DatabaseName:='AccountsDB'; Database:='Accounting'; Connected:=True; end; LocalQuery:=TEDBQuery.Create(nil); try with LocalQuery do begin { Be sure to assign the same session and database name as the TEDBDatabase 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: TEDBSession; begin EnterCriticalSection(SessionNameSection); try LastSessionValue:=LastSessionValue+1; Result:=TEDBSession.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 Thursday, November 16, 2023 at 10:39 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |