Get SQL before POST in a ZQuery

0

Well, does anyone know how to get the sql executed in the POST of a query in insert mode? For example, I have the student table with id and name:

begin
    tblAluno.Insert;
    tblAlunoID.asInteger := 1;
    tblAlunoNome.asString := 'Carlos';
    //aqui
    tblAluno.Post;
end;

Just in "here" I want to get the sql that runs underneath with the insert. Note that if I put: clipboard.asText: = tblAluno.Sql.Text it returns me the sql of the query and not the one actually executed in the post.

    
asked by anonymous 13.08.2014 / 19:47

2 answers

1

You can get sql from UpdateObject ex:

ZQuery.UpdateObject.InsertSQL;
ZQuery.UpdateObject.DeleteSQL;
ZQuery.UpdateObject.ModifySQL;

@jack, then you can try as follows:

var
   strLista: TStrings;
   idx: Integer;
begin
   strLista := nil;
   try
      strLista := TStringList.Create;
      strLista.Text := ZQuery.UpdateObject.InsertSQL.Text;
      strLista.Add('=======================================')
      for idx := 0 to ZQuery.Fields.Count - 1 do
      begin
         strLista.Add(ZQuery.Fields[idx].Name + ' = ' + ZQuery.Fields[idx].AsString);
      end;

      Clipboard.AsText := strLista.Text;
   finally
      if Assigned(strLista) then
         FreeAndNil(strLista);
   end;
end;

It will get the sql, and in the end it will add the parameters and their respective values, (it should be placed in the before post of zquery)

    
13.08.2014 / 19:52
0

Jack, I recommend that you do not use ZTable , only in very extreme cases. Play ZQuery in DataModule and assign to your connection. Then throw a ZUpdateSQL and assign it to ZQuery in the UpdateSQL property. At its ZQuery , modify the SQL.Text property to ' SELECT * FROM Tabela WHERE algumacoisa = algumacoisa; '. Then double-click the ZUpdateSQL and a window will open. Click on ' Generate SQL ' and it will do the 3 codes, for DELETE , UPDATE and INSERT . You can then edit and enhance them any way you like.

    
27.03.2016 / 13:50