Problem using command at runtime : TUNIQUERY

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
gss200610
Posts: 35
Joined: Mon 23 May 2016 22:29

Problem using command at runtime : TUNIQUERY

Post by gss200610 » Thu 16 Mar 2017 15:55

I have the following function that worked normal, now I'm having problems in the parameters, the query on a datamodule always returns empty.
The last parameter is of type string:

Code: Select all

function TDM.RetornaStringTabela(CampoRetorno: string; tabela: string;
  Campochave: string; ValorChave: string): string;
begin
  Result := '';

  if ValorChave = EmptyStr then
    Exit;

  try
    try
      QBusca.Close;
      QBusca.SQL.Clear;
      QBusca.SQL.Text := 'SELECT ' + CampoRetorno + ' FROM ' + TABELA +
          ' WHERE ' + CampoChave + ' = :cod';
   [b]   QBusca.ParamByName('cod').AsString :=  ValorChave; [/b]
      QBusca.Prepare;
      QBusca.Open;
      if QBusca.RecordCount > 0 then
        result := QBusca.fieldbyname(CampoRetorno).AsString;


    except on E: Exception do
      begin
        QBusca.CancelarTransacao;
        raise Exception.CreateFmt('Erro ao buscar campo %s da tabela %s ' +
                    sLineBreak+ E.Message, [CampoRetorno, TABELA]);
      end;
    end;

  finally
    QBusca.Close;
  end;

end;
if I use :

Code: Select all

QBusca.SQL.Text := 'SELECT ' + CampoRetorno + ' FROM ' + TABELA +
          ' WHERE ' + CampoChave + ' =  ' +  quotedStr(valorchave);
Returns normal because the data exists in the database.

Remembering that I use this same statement in a separate unit, the more I create the query at execution time. And works normal. Now about the datamodule, my querys do not return any more data. USE OF DELPHI BERLIN 10.1 UP1 PROFESSIONAL

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Problem using command at runtime : TUNIQUERY

Post by ViktorV » Fri 17 Mar 2017 09:00

In order to get a detailed answer, please compose a full sample demonstrating the specified behavior and send it to us using the contact form https://www.devart.com/company/contactform.html, including scripts for creating and filling database objects.

gss200610
Posts: 35
Joined: Mon 23 May 2016 22:29

Re: Problem using command at runtime : TUNIQUERY

Post by gss200610 » Mon 20 Mar 2017 17:50

The odd one that some uniquery work and some not, select at runtime. Execsql does not commit even doing unicconection.commit.
Is there a way to know if it is something from the datamodule

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Problem using command at runtime : TUNIQUERY

Post by ViktorV » Wed 22 Mar 2017 10:39

Please describe the issue in more detail in order for us to give you a full answer. To receive a faster reply, please compose a full sample demonstrating the specified behavior and send it to us using the contact form https://www.devart.com/company/contactform.html, including scripts for creating and filling database objects.

Post Reply