BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TClientDataSet: Method to know the table name?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (dbExpress)
View previous topic :: View next topic  
Author Message
Craig Stuntz [TeamB]
Guest





PostPosted: Fri Jan 16, 2004 8:21 pm    Post subject: Re: TClientDataSet: Method to know the table name? Reply with quote



Angelyy wrote:

Quote:
?There are some method or trick to know the table name with a
TClientDataSet?

Client datasets don't have a table name. If you want the table name
from the dataset which is linked via a TDatasetProvider, call (Dataset
as IProviderSupport).PSGetTableName. IIRC they added a GUID to
IProviderSupport in D7; prior to that you need to use a hard cast.

-Craig

--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://delphi.weblogs.com
How to ask questions the smart way:
http://www.catb.org/~esr/faqs/smart-questions.html

Back to top
Angelyy
Guest





PostPosted: Fri Jan 16, 2004 8:51 pm    Post subject: TClientDataSet: Method to know the table name? Reply with quote



¿There are some method or trick to know the table name with a
TClientDataSet?

I going to do a function that find all TClientDataSet in a DataModule, then
I want to create in run time a Sql statament for witch one, but I d'ont know
how can I get the table name for each TClientDataSet.

Thanksssssssss

Angelyy


Back to top
Angelyy
Guest





PostPosted: Mon Jan 19, 2004 11:59 am    Post subject: Re: TClientDataSet: Method to know the table name? Reply with quote



Craig, Thanks for your reply.

I try this code:

Cds.Close;
sTable := IProviderSupport(Cds).PSGetTableName;
sKey := IProviderSupport(Cds).PSGetKeyFields; //I'm sure
there are only a key in all my DbQuerys/Tables
Cds.CommandText := 'SELECT * FROM ' + sTable+ ' WHERE ' + sKey + '
= -1';
Cds.Open;

I can't understand why I get the key/s field/s name/s without problems
(PSGetTableName), but the TableName always comes empthy ('').

I try it whit differents Cds, I'm see tha'ts TsqlQuery.Sql property it's
correct with his table name, ...

Where it is the error?

TIA

Angelyy



"Craig Stuntz [TeamB]" <cstuntz (AT) nospam (DOT) please [a.k.a. vertexsoftware.com]>
escribió en el mensaje news:400855e1$1 (AT) newsgroups (DOT) borland.com...
Quote:
Angelyy wrote:

?There are some method or trick to know the table name with a
TClientDataSet?

Client datasets don't have a table name. If you want the table name
from the dataset which is linked via a TDatasetProvider, call (Dataset
as IProviderSupport).PSGetTableName. IIRC they added a GUID to
IProviderSupport in D7; prior to that you need to use a hard cast.

-Craig

--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://delphi.weblogs.com
How to ask questions the smart way:
http://www.catb.org/~esr/faqs/smart-questions.html



Back to top
Craig Stuntz [TeamB]
Guest





PostPosted: Mon Jan 19, 2004 12:29 pm    Post subject: Re: TClientDataSet: Method to know the table name? Reply with quote

Angelyy wrote:

Quote:
I can't understand why I get the key/s field/s name/s without problems
(PSGetTableName), but the TableName always comes empthy ('').

You have to call PSGetTableName on the dataset which is linked to the
CDS. So if you have:

MyDataset -> MyDatasetProvider -> MyClientDataset

...hooked up together, you need to call PSGetTableName on MyDataset,
not on MyClientDataset.

ClientDatasets don't *have* a table, so there's not much they can do
with PSGetTableName. On the other hand, they do have key fields, so
they can respond to that call.

-Craig

--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://delphi.weblogs.com
Useful articles about InterBase and Delphi development:
http://delphi.weblogs.com/articles

Back to top
Angelyy
Guest





PostPosted: Tue Jan 20, 2004 1:12 pm    Post subject: Re: TClientDataSet: Method to know the table name? Reply with quote

Thanks Craig, thats works !

I create a function that return the DataSet (TSqlQuey) I need, then I can
use IProviderSupport .

....
DataSet := StrProviderNameToSqlQuery(Cds.ProviderName);
sTabla := IProviderSupport(DataSet).PSGetTableName;
....



function StrProviderNameToSqlQuery(sProviderName): TSqlQuery;
var
i : Integer;
Begin
Result := Nil;
for i:=0 to Dm.ComponentCount-1 do begin
if (Dm.Components[i] is TDataSetProvider) and (Dm.Components[i].Name
= sProviderName) then
begin
Result := (TDataSetProvider(Dm.Components[i]).DataSet as
TSqlQuery);
Continue;
end;
end;
if not(Assigned(Result)) then
Abort;
end;


Angelyy


"Craig Stuntz [TeamB]" <cstuntz (AT) nospam (DOT) please [a.k.a. vertexsoftware.com]>
escribió en el mensaje news:400bdbb5 (AT) newsgroups (DOT) borland.com...
Quote:
Angelyy wrote:

I can't understand why I get the key/s field/s name/s without problems
(PSGetTableName), but the TableName always comes empthy ('').

You have to call PSGetTableName on the dataset which is linked to the
CDS. So if you have:

MyDataset -> MyDatasetProvider -> MyClientDataset

...hooked up together, you need to call PSGetTableName on MyDataset,
not on MyClientDataset.

ClientDatasets don't *have* a table, so there's not much they can do
with PSGetTableName. On the other hand, they do have key fields, so
they can respond to that call.

-Craig

--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://delphi.weblogs.com
Useful articles about InterBase and Delphi development:
http://delphi.weblogs.com/articles



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (dbExpress) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.