![]() | Products |
| Home » Technical Support » ElevateDB Technical Support » Product Manuals » ElevateDB Version 2 Manual for RAD Studio XE6 (C++ Win64) » Getting Started » Multi-Threaded Applications |
int LastSessionValue;
TRTLCriticalSection SessionNameSection;
// Assume that the following code is being executed
// within a thread
bool __fastcall UpdateAccounts();
{
bool TempResult=false;
TEDBSession *LocalSession=GetNewSession;
try
{
TEDBDatabase *LocalDatabase=new TEDBDatabase(NULL);
try
{
// Be sure to assign the same session name
// as the TEDBSession component
LocalDatabase->SessionName=LocalSession->SessionName;
LocalDatabase->DatabaseName="AccountsDB";
LocalDatabase->Database="Accounting";
LocalDatabase->Connected=true;
TEDBQuery *LocalQuery=new TEDBQuery(NULL);
try
{
// Be sure to assign the same session and
// database name as the TEDBDatabase
// 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;
TEDBSession* __fastcall GetNewSession();
{
TEDBSession *TempResult=NULL;
EnterCriticalSection(SessionNameSection);
try
{
LastSessionValue=(LastSessionValue+1);
TEDBSession *TempResult=new TEDBSession(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 Tuesday, September 16, 2025 at 04:56 PM | Privacy Policy © 2026 Elevate Software, Inc. All Rights Reserved Questions or comments ? |

