Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread How to find TDBISAMDatabase by databasename
Wed, Mar 1 2006 5:11 PMPermanent Link

Danny Humphress
I need to specify the SessionName when opening a table (multi-threading with unique session names). The problem is that I have a lot of generalized
units that open tables using only a generic database name ("db1"). That database name refers to a TDBISAMDatabase component that has a session
attached to it. How can I find what session it is?

Here's what I have tried:

with TDBISAMTable.Create(nil) do begin
 DatabaseName := 'db1';
 SessionName := Database.SessionName; // <- Error here because Database is nil
end;

Is there an engine function or something that can give me the actual database reference based on the database name?

thanks,
Danny
Wed, Mar 1 2006 9:20 PMPermanent Link

Jeff Cook
Danny Humphress <danny@humphress.com> wrote on Wed, 1 Mar 2006 17:11:33 -0500

>I need to specify the SessionName when opening a table (multi-threading with unique session names). The problem is that I have a lot of generalized
>units that open tables using only a generic database name ("db1"). That database name refers to a TDBISAMDatabase component that has a session
>attached to it. How can I find what session it is?
>

Danny


You might be able to find the database like this:-

 for i := 0 to ComponentCount - 1 do
 begin
   if Components[i] is TDBISAMDatabase then
   begin
       SessionName := (Components[i] as TDBISAMDatabase).SessionName;
       break;
   end;
 end;

HTH

Cheers

Jeff

--
Jeff Cook
Aspect Systems Ltd
Phone: +64-9-424 5388
Skype: jeffcooknz
www.aspect.co.nz



Thu, Mar 2 2006 5:41 AMPermanent Link

Danny Humphress
Jeff,

Thanks. I ended up writing the following. It seems like a complicated way to get a reference to a database by its name. I thought there might be a
simplier solution:

function GetDatabaseByName( ADatabaseName: string ): TDBISAMDatabase;
var
 i, j: integer;
begin
 Result := nil;
 i := 0;
 while (i<Engine.SessionCount) and (Result=nil) do begin
   j := 0;
   while (j<Engine.Sessions[i].DatabaseCount) and (Result=nil) do begin
     if ANSICompareText(Engine.Sessions[i].Databases[j].DatabaseName,ADatabaseName)=0 then
       Result := Engine.Sessions[i].Databases[j];
     inc(j);
   end;
   inc(i);
 end;
end;
Thu, Mar 2 2006 9:37 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Danny,

<< I need to specify the SessionName when opening a table (multi-threading
with unique session names). The problem is that I have a lot of generalized
units that open tables using only a generic database name ("db1"). That
database name refers to a TDBISAMDatabase component that has a session
attached to it. How can I find what session it is? >>

Loop through the Engine.Sessions property and call this method for each
session:

http://www.elevatesoft.com/dbisam4d5_tdbisamsession_finddatabase.htm

http://www.elevatesoft.com/dbisam4d5_tdbisamengine_sessions.htm
http://www.elevatesoft.com/dbisam4d5_tdbisamengine_sessioncount.htm


--
Tim Young
Elevate Software
www.elevatesoft.com

Image