Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Sanity check....
Mon, Jun 12 2023 3:24 PMPermanent Link

Ian Branch

Avatar

Hi Team,
Does anybody see any issue with this construct??
{code}
   try
     //
     while true do
     begin
       //
       if TEDBEngineSessionManager(dmDB.DBS1.Handle).TryLock(1) then
       begin
         //
         TEDBEngineSessionManager(dmDB.DBS1.Handle).Unlock;
         //
         { Session is not locked and is safe for you to use }
         try
            //
           tqServerSessions.Close;
           tqServerSessions.ExecSQL;
           //
           Break;
           //
         except
           // Delay for the specified amount of time
           Sleep(250);
           //
         end;
         //
       end
       else
         // Delay for the specified amount of time
         Sleep(250);
       //
     end;
     //
   except
     on E: Exception do ShowMessage('An unknown or unexpected error has occurred.');
   end;
{code}

I think the initali try-except-end is redundant.
Anything else?

Regards & TIA,
Ian
Tue, Jun 13 2023 2:29 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian


Personal view

If you mean

<<        if TEDBEngineSessionManager(dmDB.DBS1.Handle).TryLock(1) then
       begin
         //
         TEDBEngineSessionManager(dmDB.DBS1.Handle).Unlock;
         //
         { Session is not locked and is safe for you to use }>>

then yes - if it fails here it will also fail when you try and run the script

I'd also suggest

<<           tqServerSessions.Close;
           tqServerSessions.ExecSQL;
>>

becomes

<<
tqServerSessions.ExecSQL;
tqServerSessions.Close;
>>

or if you need an OUT parameter later on that you release it at some point elsewhere and I just hate

<<
     while true do
     begin
>>

use a variable and set as needed and allow the loop to terminate gracefully


Roy Lambert
Image