0

I use C++ Builder (Delphi 10.2 and C++Builder 10.2 Update 2) and I need a method that, in case there is no particular table, creates it using TADO objects (ADODB)? I mean TADOQuery, TADOTable, TADOConnection, etc.

How can I do this?

I tried looking at the methods of TADOConncection, of TADOTable, but none of them seem to be useful. I also tried this route (https://docwiki.embarcadero.com/Libraries/Alexandria/en/Bde.DBTables.TTable.Exists) but there are compatibility problems.

breakou7z
  • 3
  • 3
  • 1
    You can use TADOConnection.GetTableNames() to get the a list of existing table names. But I don't know, how to create if not exists. – malom Feb 10 '23 at 13:47
  • 2
    If you are asking how to create a table, on way is to use TADOQuery to execute the SQL statement that you would use if you were creating the table manually (using SQL). – Roger Cigol Feb 10 '23 at 16:56
  • @RogerCigol my problem is that I have no way to tell if a table is in the database or not. Then if it is not present, I have to create it and there yes, I use TADOQuery. I thank you anyway for trying to help me. – breakou7z Feb 13 '23 at 10:46
  • @malom I had been eyeing this method too, but I was having trouble finding a loop to read strings using C++ since I don't know delphi. I was looking for something else, but apparently I think that's the only way. Thanks for the suggestion. – breakou7z Feb 13 '23 at 10:49

1 Answers1

0

Does this help ?

TADOConnection *YOUR_TADOCONNECTION; // your connection defined earlier in your code


TStringList *TableList = new TStringList;
bool WithSystemTables = true; // or false according to your requirements
YOUR_TADOCONNECTION->GetTableNames(TableList, WithSystemTables);
for (int i = 0 i < TableList->Count(); i++) {
   String NextTableName = TableList->Strings[i];
   /*.... your check for the table name being the one you want goes here .... */
}
delete TableList;
Roger Cigol
  • 173
  • 1
  • 9
  • I had actually solved yesterday in a way similar to this, but yours is done better so I just modified my code with your solution. Thank you very much. – breakou7z Feb 14 '23 at 10:57