Вопрос

I trying to write a small database management app to compare our live and dev database schemas

At the moment I can use a single TSQLconnection to get the list of Schemas on the MySQL (5.0) server, the problem comes when I try and directly access the schemas.

I want to select a schema and show all the tables from that schema in a listbox.

The procedure below compiles, but fails with a "You have an error in your syntax" message when it hits the ExecSQL.

procedure TDM.GetTables(schemaname: string);
begin
   with SQLQuery1 do
   begin
      SQL.Clear;
      SQL.Add('SHOW TABLES FROM ' + schemaname);
      ExecSQL;
   end;
end;

Schemaname comes from a tcombobox seeded using GET SCHEMAS and looks to be being passed OK.

I've tried the above with Open rather than ExecSQL and get the same error. I've also tried to append a ; to the end of the statement.

Unless I'm being blind I'm wondering if the issue is with dbExpress

Does anyone know?

Это было полезно?

Решение 2

Turns out the problem was a combination of the nest of the with and my choice of parameter names.

TSQLQuery has a property called schemaname and I think that the compiler was getting confused with my parameter of the same name.

Catching this wasn't helped by the debugger correctly reporting the value of the parameter in the inspector...

Другие советы

There must be another reason that this don't work .
Normally this should work;

 SQL.Add('SHOW TABLES FROM ' + schemaname);

instead, you can try that :

with SQLQuery1 do
   begin
      close;
      SQL.Clear;
      SQL.Add('SELECT table_name FROM INFORMATION_SCHEMA.TABLES'+
              ' WHERE table_schema = "'+schemaname+'"');
      Open;
   end;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top