Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Product Manuals » DBISAM Version 4 Manual for Developer Studio 2006 (C++) » Advanced Topics » Multi-Threaded Applications |
int LastSessionValue; TRTLCriticalSection SessionNameSection; // Assume that the following code is being executed // within a thread bool __fastcall UpdateAccounts(); { bool TempResult=false; TDBISAMSession *LocalSession=GetNewSession; try { TDBISAMDatabase *LocalDatabase=new TDBISAMDatabase(NULL); try { // Be sure to assign the same session name // as the TDBISAMSession component LocalDatabase->SessionName=LocalSession->SessionName; LocalDatabase->DatabaseName="Accounts"; LocalDatabase->Directory="g:\\accountdb"; LocalDatabase->Connected=true; TDBISAMQuery *LocalQuery=new TDBISAMQuery(NULL); try { // Be sure to assign the same session and // database name as the TDBISAMDatabase // component LocalQuery->SessionName=LocalSession->SessionName; LocalQuery->DatabaseName=LocalDatabase->DatabaseName; LocalQuery->SQL->Clear(); LocalQuery->SQL->Add("UPDATE accounts SET PastDue=True"); LocalQuery->SQL->Add("WHERE DueDate < CURRENT_DATE")); LocalQuery->Prepare; try { // Start the transaction and execute the query LocalDatabase->StartTransaction(); try { LocalQuery->ExecSQL(); LocalDatabase->Commit(); TempResult=true; catch { LocalDatabase->Rollback(); } __finally { LocalQuery->UnPrepare(); } } __finally { delete LocalQuery; } } __finally { delete LocalDatabase; } } __finally { delete LocalSession; } return TempResult; end; TDBISAMSession* __fastcall GetNewSession(); { TDBISAMSession *TempResult=NULL; EnterCriticalSection(SessionNameSection); try { LastSessionValue=(LastSessionValue+1); TDBISAMSession *TempResult=new TDBISAMSession(NULL); TempResult->SessionName="AccountSession"+ IntToStr(LastSessionValue); } __finally { LeaveCriticalSection(SessionNameSection); } return TempResult; } { 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 |