Dear all,
May I ask for some help or pointers on the following please ?
My application reads through an SQL statement and creates a DB Grid and its columns etc at runtime. This works well if there is just a single table in the FROM clause.
But there are times when I need to create an unknown quantity of TADOTables and TDataSource’s at runtime. The problem is, I have no idea whether I need to build a single instance of each, or multiples, it all depends on what the users SQL statement contains.
I don’t have a problem creating a single instance when the users SQL statement is …
… I free ATable and ADataSource objects when I’m done with them.
The problem I have is how do I create multiple instances of ATable and ADataSource if the SQL statement contains a join to a second table ? Obviously, I can’t use ATable or ADataSource again as it’s being used for the first Table in the SQL statement.
I know I could declare a second instance of each object, but this just shifts the problem if the SQL’s FROM clause includes a third table, or a fourth, or a fifth.
So imagine the following SQL statement (from Northwind.mdb) …
I can collect everything I need from the statement, ie get the table names and then read through their fields and get the primary and foreign keys. In this case there are 3 tables so I need 3 instances of TADOTable and TDataSources.
So my question is …
Is it possible to create multiple TADOTable and TDataSource objects at runtime (without knowing in advance how many I need) and if so how ?
Limiting the users SQL statement to, say, 3 tables isn’t a solution, as I would need to start rewriting the SQL if it contained more than 3 tables in the FROM clause ... I think this would bring a host of other problems.
I hope this post makes sense. Thanks for taking the time to read, I would be grateful for any help you could offer.
Amy.
PS - Using Delphi 7 Pro.
May I ask for some help or pointers on the following please ?
My application reads through an SQL statement and creates a DB Grid and its columns etc at runtime. This works well if there is just a single table in the FROM clause.
But there are times when I need to create an unknown quantity of TADOTables and TDataSource’s at runtime. The problem is, I have no idea whether I need to build a single instance of each, or multiples, it all depends on what the users SQL statement contains.
I don’t have a problem creating a single instance when the users SQL statement is …
Code:
SELECT * FROM Customers
Code:
Var
ADataSource: TDatasource;
ATable: TADOTable;
Begin
ATable := TADOTable.Create(Self);
ADataSource := TDataSource.Create(Self);
With ATable do
Begin
// Sort out the ATable properties;
End;
With ADataSource do
Begin
// Sort out the ADataSource properties;
End;
End;
… I free ATable and ADataSource objects when I’m done with them.
The problem I have is how do I create multiple instances of ATable and ADataSource if the SQL statement contains a join to a second table ? Obviously, I can’t use ATable or ADataSource again as it’s being used for the first Table in the SQL statement.
I know I could declare a second instance of each object, but this just shifts the problem if the SQL’s FROM clause includes a third table, or a fourth, or a fifth.
So imagine the following SQL statement (from Northwind.mdb) …
Code:
SELECT *
FROM (Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID) INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID;
I can collect everything I need from the statement, ie get the table names and then read through their fields and get the primary and foreign keys. In this case there are 3 tables so I need 3 instances of TADOTable and TDataSources.
So my question is …
Is it possible to create multiple TADOTable and TDataSource objects at runtime (without knowing in advance how many I need) and if so how ?
Limiting the users SQL statement to, say, 3 tables isn’t a solution, as I would need to start rewriting the SQL if it contained more than 3 tables in the FROM clause ... I think this would bring a host of other problems.
I hope this post makes sense. Thanks for taking the time to read, I would be grateful for any help you could offer.
Amy.
PS - Using Delphi 7 Pro.