Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 14 total
Thread Exists method
Fri, Apr 18 2008 3:45 PMPermanent Link

"Jose Eduardo Helminsky"
I have my own Table component that is inherited from TEDBTable

The code below could be an exist method ?

function THProTable.Exists: Boolean;
begin
    Result := Session.Execute('select name from information.tables where
name='+QuotedStr(Tablename)) > 0;
end;

Eduardo

Fri, Apr 18 2008 7:35 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eduardo,

<< The code below could be an exist method ? >>

Actually, this is what you need:

function THProTable.Exists: Boolean;
begin
    CheckActive;
    Result := Database.Execute('select name from information.tables where
name='+QuotedStr(Tablename)) > 0;
end;

You want to execute any such query from the context of the database defined
for the table, and you need the database open to do so.

--
Tim Young
Elevate Software
www.elevatesoft.com

Tue, Apr 22 2008 6:18 AMPermanent Link

"Jose Eduardo Helminsky"
Tim

<< Actually, this is what you need:

function THProTable.Exists: Boolean;
begin
   CheckActive;
   Result := Database.Execute('select name from information.tables where
name='+QuotedStr(Tablename)) > 0;
end;
>>

If I am understanding it correctly the Database is the EDBDatabase component
because there is no Database property at TEBTable level. In my case, the
Database is not available in this unit then since I am only using one
database per application, then I could use Session.Databases[0].Execute ?

Eduardo

Tue, Apr 22 2008 11:56 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eduardo,

<< If I am understanding it correctly the Database is the EDBDatabase
component because there is no Database property at TEBTable level. >>

No, there's a Database property at the TEDBTable level.  It's set to a
temporary TEDBDatabase component if you don't explicitly have one assigned
via the DatabaseName property.

<< In my case, the Database is not available in this unit then since I am
only using one database per application, then I could use
Session.Databases[0].Execute ? >>

Are you saying that the TEDBTable doesn't have its DatabaseName property
assigned yet in that unit ?  If so, then you'll have to figure out a way to
assign it a value prior to calling this method.  The TEDBTable must be open
for this method to work.

--
Tim Young
Elevate Software
www.elevatesoft.com

Wed, Apr 23 2008 6:02 AMPermanent Link

"Jose Eduardo Helminsky"
Tim

<< No, there's a Database property at the TEDBTable level.  It's set to a
temporary TEDBDatabase component if you don't explicitly have one assigned
via the DatabaseName property.
>>
Ok, got it.

<< Are you saying that the TEDBTable doesn't have its DatabaseName property
assigned yet in that unit ?  If so, then you'll have to figure out a way to
assign it a value prior to calling this method.  The TEDBTable must be open
for this method to work.
>>
No, at this time DatabaseName property should by assigned but why TEDBTable
must be opened ? I am trying to know if it exists.

Eduardo

Wed, Apr 23 2008 11:45 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eduardo,

<< No, at this time DatabaseName property should by assigned but why
TEDBTable must be opened ? I am trying to know if it exists. >>

Crap, I forgot about that.  What you need instead is this:

function THProTable.Exists: Boolean;
begin
  SetDatabaseFlag(dbfTable,True);
  try
    Result := Database.Execute('select name from information.tables where
name='+QuotedStr(Tablename)) > 0;
  finally
     SetDatabaseFlag(dbfTable,False);
  end;
end;

--
Tim Young
Elevate Software
www.elevatesoft.com

Wed, Apr 23 2008 1:19 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim

Can  you explain that function - it looks useful but what is SetDatabaseFlag(dbfTable,True);?


Roy Lambert
Wed, Apr 23 2008 3:20 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< Can you explain that function - it looks useful but what is
SetDatabaseFlag(dbfTable,True);? >>

It's an internal function for opening up the referenced database for
temporary purposes.

--
Tim Young
Elevate Software
www.elevatesoft.com

Wed, Apr 23 2008 4:11 PMPermanent Link

"Jose Eduardo Helminsky"
Tim

The big question:

Why this function is not available as a method of  TEBTable ?
I know ElevateDB is going to SQL based operations in a lot of areas but if
you don´t see any problems with the above code, then I think a lot of users
will be happy with this.

Eduardo

Wed, Apr 23 2008 4:36 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eduardo,

<< Why this function is not available as a method of  TEBTable ? I know
ElevateDB is going to SQL based operations in a lot of areas but if you
don´t see any problems with the above code, then I think a lot of users will
be happy with this. >>

The issue is that it starts us back down the slippery slope of wanting
meta-data methods in the TEDBTable component.  Today it's Exists, tomorrow
it's "CreateTable", and we simply cannot do those methods anymore due to the
complex nature of the table structures now with respect to constraints,
triggers, etc.

--
Tim Young
Elevate Software
www.elevatesoft.com

Page 1 of 2Next Page »
Jump to Page:  1 2
Image