Thread: Getting user created tables from SQL
hi guys,
i m trying to get the user created tables from SQL by using C++ Builder.Here is the code:
TQuery *TableQuery;
TableQuery= new TQuery (this);
TableQuery= new TQuery (this);
TQuery *TableCountQuery;
TableCountQuery= new TQuery (this);
TableCountQuery= new TQuery (this);
TableQuery->DatabaseName = "TEMP";
TableCountQuery->DatabaseName = "TEMP";
TableCountQuery->DatabaseName = "TEMP";
TableCountQuery->SQL->Add ("SELECT COUNT(TABLE_NAME) AS CTABLE FROM INFORMATION_SCHEMA.TABLES WHERE (TABLE_TYPE = 'BASE TABLE')");
TableCountQuery->Open ();
TableCountQuery->Open ();
int counttables = TableCountQuery->FieldByName ("CTABLE")->AsInteger;
TableCountQuery->Close ();
TableCountQuery->Free ();
TableQuery->SQL->Add ("SELECT TABLE_NAME AS TNAME FROM INFORMATION_SCHEMA.TABLES WHERE (TABLE_TYPE = 'BASE TABLE')");
TableQuery->Open ();
DynamicArray <AnsiString> CTableArr;
CTableArr.Length = counttables;
CTableArr.Length = counttables;
int f = 0;
while (!TableQuery->Eof)
{
CTableArr[f] = TableQuery->FieldByName ("TNAME")->AsString;
TableQuery->Next();
f++;
while (!TableQuery->Eof)
{
CTableArr[f] = TableQuery->FieldByName ("TNAME")->AsString;
TableQuery->Next();
f++;
}
TableQuery->Close ();
TableQuery->Free ();
TableQuery->Free ();
the first Select statement work correct, counttables variable gets the right value but unfortunately, after the second select statement, in C++ Builders SQL Explorer window, it brings the correct number of rows but without datas in them!!! In Enterprise Manager the second select statement also works correct but how come it aint work in C++ builder?
i would be grateful if you can help me
Thanks
CENK
THE PUBLICENEMY
http://www3.50megs.com/cenk1536/
CHAIRMAN Of Computer Information Systems Technology CLUB
Yahoo! for Good
Click here to donate to the Hurricane Katrina relief effort.
Cenk KIZILDAG wrote: > TableQuery->SQL->Add ("SELECT TABLE_NAME AS TNAME FROM > INFORMATION_SCHEMA.TABLES WHERE (TABLE_TYPE = 'BASE TABLE')"); > CTableArr[f] = TableQuery->FieldByName ("TNAME")->AsString; > the first Select statement work correct, counttables variable gets > the right value but unfortunately, after the second select statement, > in C++ Builders SQL Explorer window, it brings the correct number of > rows but without datas in them!!! In Enterprise Manager the second > select statement also works correct but how come it aint work in C++ > builder? I don't suppose this could be an identifer case issue? In the first query TNAME will be case-folded to 'tname' (because that's how PG does case-insensitive identifiers). Try looking up FieldByName("tname") and see if that comes up with anything. -- Richard Huxton Archonet Ltd