0

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?

4

2 回答 2

3

一定有另一个原因,这不起作用。
通常这应该可以工作;

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

相反,您可以尝试:

with SQLQuery1 do
   begin
      close;
      SQL.Clear;
      SQL.Add('SELECT table_name FROM INFORMATION_SCHEMA.TABLES'+
              ' WHERE table_schema = "'+schemaname+'"');
      Open;
   end;
于 2013-09-13T16:36:13.250 回答
0

原来问题是嵌套的with和我选择的参数名称的组合。

TSQLQuery 有一个名为的属性,我认为编译器与我的同名 参数schemaname混淆了。

调试器在检查器中正确报告参数的值并没有帮助捕捉到这一点......

于 2013-09-16T09:24:18.547 回答