Update table at run-time lazarus / 16-Databases ---------------------------------------------------------------------- babycode · 2024-05-21 23:17 I'm trying to update a table at runtime using a temporary Query. In the end it does not show any errors or exceptions, but when I query the table the information has not been updated. Basically I'm updating just one field, I created the connection and the query at run time, I execute the sql, and I destroy the components, but the information is not updated in the database.  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure GravarMD5P(session_p: string; u_id: integer);var        qryTemp: TZQuery;        conTemp: TZConnection;begin        qryTemp := TZQuery.Create(Nil);        conTemp := CriarConexaoSec;         qryTemp.Connection := conTemp;        qryTemp.CachedUpdates := False;        ConTemp.Connect;         try                with qryTemp do              begin                        SQL.Clear;                       Connection.StartTransaction;                         SQL.Add('update usuarios set sessao_p = :sSession_p where usuario_id = :iUsuarioID;');                        ParamByName('sSession_p').AsString := 'ttaassttes';                      ParamByName('iUsuarioID').AsInteger := 1;                         try                                ExecSQL;                              ApplyUpdates;                                Connection.Commit;                      except                                on E: Exception do                                begin                                      ShowMessage('Erro ao gravar dados: ' + E.Message);                                      Connection.Rollback; // Desfaz a transação em caso de erro                                end;                      end;                end;        finally                conTemp.Free;                qryTemp.Free;        end;end;  I checked if SQL.Text is correct and if it is receiving the values ​​in the procedure parameters and they are. It simply doesn't show an error or exception, it doesn't record  . I'm using ZeosLib 8. Sorry for not including a minimal example, I'm using PostgreSQL. ---------------------------------------------------------------------- egsuh · 2024-05-22 03:28 1. Where is the qryTemp created? 2. Do not use ApplyUpdates if you are directly operating on a SQL DB with SQL statements. 3. Not sure these are supported in ZQuery, but basics are Transaction.StartTransaction and Transaction.Commit. You are using Connection.StartTransaction and Connection.Commit. ---------------------------------------------------------------------- babycode · 2024-05-22 12:57 Quote from: egsuh on May 22, 2024, 05:28:41 am1. Where is the qryTemp created? 2. Do not use ApplyUpdates if you are directly operating on a SQL DB with SQL statements. 3. Not sure these are supported in ZQuery, but basics are Transaction.StartTransaction and Transaction.Commit. You are using Connection.StartTransaction and Connection.Commit. The TZConnection component has the transaction option, but I did a test after your answer and also created a TZTransaction at run time and placed it for the TZConnection. I explicitly controlled the transaction using the transaction created and the information was saved in the bank correctly. Apparently I need the transaction even at run time. 1. The temporary query is created here: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure GravarMD5P(session_p: string; u_id: integer);var        qryTemp: TZQuery; // defines the type of TZQuery variable        conTemp: TZConnection; begin        qryTemp := TZQuery.Create(Nil); //creates an instance of the TZQuery class and assigns it to the variable. 2. I only used ApplyUpdates as a test, but in ZeosLib I generally use Query.CommitUpdates Transaction.Commit.