mysqldelphidbexpress

Delphi EDataBaseError - Operation Not Supported. How can I solve it?


I'm trying to query data from MySQL5 db, but when I use some other features from SQL code, I have the following error returned: [0x0005]: Operation Not Supported.

My SQL code query:

Select 
  s.nome, s.id_sistema, s.st_sis 
from 
  perm_usuar as p 
inner join 
  sistemas as s 
on 
  s.id_sistema = p.id_sistema 
where 
  p.id_usuario = "' + idusuario + '"'

When I don't use those features, it works just as well:

Select 
  sistemas.nome, sistemas.id_sistema, sistemas.st_sis 
from 
  perm_usuar 
inner join 
  sistemas 
on 
  sistemas.id_sistema = perm_usuar.id_sistema 
where 
  perm_usuar.id_usuario = "' + idusuario + '"'

Also, if I try to use WHERE of a joined table, I get the same error... I'm using DBExpress on Delphi XE8, with the following components: SQLConnection, SQLDataSet and SQLQuery.

When I use the code directly on MySQL, it works fine.

Why is it being returned and what's the solution?


Solution

  • I found the solution! The problem were on SQLQuery1.RecordCount. By what I read, the dbExpress is unidirectional, so the RecordCount bring it resource, however have its limitations (you can see here: http://edn.embarcadero.com/ru/article/28494)

    Before (returning error):

     SQL1.SQL.Clear;
     SQL1.SQL.Add(CodigoMYSQL);
     SQL1.Open;
     SQL1.First;
     cont := SQL1.RecordCount; //have limitations
     if cont > 0 then // check
      begin
       for i := 1 to cont do //loop in
        begin
         for ii := 0 to NValue do
          result[ii].Add(SQL1.Fields[ii].AsString);
         SQL1.Next;
        end;
      end;
     SQL1.Close;
    

    ** SQL1 = SQLQuery1

    After (solved):

     SQL1.SQL.Clear;
     SQL1.SQL.Add(CodigoMYSQL);
     SQL1.Open;
     SQL1.First;
     if not SQL1.IsEmpty then //check
      begin
        ii := 0;
        while not SQL1.Eof do //till the end
        begin
         for ii := 0 to NValue do
          result[ii].Add(SQL1.Fields[ii].AsString);
         SQL1.Next;
         inc(ii);
        end;
      end;
     SQL1.Close;
    

    Now I can use even more complex one SQL codes and functions.