Page 1 of 1

Problem using command at runtime : TUNIQUERY

Posted: Thu 16 Mar 2017 15:55
by gss200610
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

Re: Problem using command at runtime : TUNIQUERY

Posted: Fri 17 Mar 2017 09:00
by ViktorV
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.

Re: Problem using command at runtime : TUNIQUERY

Posted: Mon 20 Mar 2017 17:50
by gss200610
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

Re: Problem using command at runtime : TUNIQUERY

Posted: Wed 22 Mar 2017 10:39
by ViktorV
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.