Page 1 of 1

Uniquery Error

Posted: Tue 15 Apr 2014 16:55
by isysoftware
Hi All,

I have this code:

Code: Select all

procedure TFrm_ArchivioClienti.My_Save_InfoOrdine;
var Myinfo:TInfoOrdine; MyQ:TUniQuery;
begin
     Myinfo:=TInfoOrdine.Create;
     with Myinfo do
        begin
             idordine:=MySelectedOrder;
             dataordine:=txtdataordine.Date;
             ordidcli:=MySelectedCliente;
             ordidagent:=-1;
             numordine:=txtnumeroordine.Text;
             if(Switchstatoordine.IsChecked) then
                begin
                stato:=0;
                statotxt:='Ordine da Evadere';

                end
             else
               begin
                stato:=1;
                 statotxt:='Ordine Evaso';
               end;
             totaleordine:=0;
        end;
     MyQ:=TUniQuery.Create(self);
     with MyQ do
        begin
            Connection:=mydm.SqlLiteConn;
            close;
            sql.Clear;
            sql.Add('select * from ordine where idordine=:anid');
            ParamByName('anid').Value:=Myinfo.idordine;
            open;
        end;
     if(Myq.RecordCount > 0) then
         begin
               with MyQ do
                   begin
                        edit;

                        FieldByName('dataordine').Value:=Myinfo.dataordine;
                        FieldByName('ordidcli').Value:=Myinfo.ordidcli;
                        FieldByName('ordidagent').Value:=Myinfo.ordidagent;
                        FieldByName('numordine').Value:=Myinfo.numordine;
                        FieldByName('stato').Value:=Myinfo.stato;
                        FieldByName('statotxt').Value:=Myinfo.statotxt;
                        try
                          begin
                              Connection.StartTransaction;
                              Post;
                              Connection.Commit;
                            //  result:=true;
                          end;
                        except on E: Exception do
                            begin
                                if(Connection.InTransaction) then
                                   Connection.Rollback;
                              //  result:=false;
                            end;
                        end;
                   end;
         end;
     Myq.Close;
     Myq.Free;
end;
On Post, I have thi error: Project raised exception class EDatabaseError whit message 'Update failed. Found 0 records'. And the update isn't executed.
I have this error in Step Over (F8) debug.

Can you help me?

Thanks,
Flavio

Re: Uniquery Error

Posted: Wed 16 Apr 2014 07:43
by isysoftware
Hi All,
It seems that the problem was that my table hasn't a PK. I have added a PK and now it works.

It's normal? With MySql I haven't had this kind of problem.

Thanks.

Re: Uniquery Error

Posted: Wed 16 Apr 2014 14:16
by azyk
Hello, Flavio.

The 'Update failed. Found 0 records' error occurs, because no record matched the WHERE condition.
Please analyze the SQL query, that is executed while calling Post. It can be seen using the dbMonitor tool. You can find out from the SQL query how many records match the WHERE condition.

Best regards,
Andrey
Devart Team
www.devart.com

Re: Uniquery Error

Posted: Wed 16 Apr 2014 15:04
by isysoftware
Hi Andrey, thanks for your reply.

I have checked my code and my DB: it seems all Ok.
I have solved setting primary key in my table.

I'll see if it'll happens again.

Thanks,
Flavio

Re: Uniquery Error

Posted: Thu 17 Apr 2014 13:15
by azyk
Hello, Flavio

If any other questions come up, please contact us.

Best regards,
Andrey
Devart Team
www.devart.com

Re: Uniquery Error

Posted: Fri 18 Apr 2014 16:59
by isysoftware
Hi Andrey,
the problem was here!!!

"....Founds 7 records..."

Here, you can daownlad the database: https://www.dropbox.com/s/9i5l7iprysoj2q7/isyorder.rar

and the code is this:

Code: Select all

function TFrm_ArchivioArticoli.SalvaArticolo: boolean;
var aQ:tuniquery;
begin
    if(MySelectedArticolo > 0) then
        begin
             if(MyDM.SqlLiteConn.Connected = true) then
                 begin
                      aQ:=TUniQuery.Create(self);
                      with aQ do
                         begin
                              Connection:=MyDM.SqlLiteConn;
                              close;
                              sql.Clear;
                              sql.Add('select * from articoli where idarticolo=:anid');
                              ParamByName('anid').Value:=MySelectedArticolo;
                              open;
                              edit;
                              FieldByName('codiceart').Value:=txtcodice.Text;
                              FieldByName('barcodeart').Value:=txtbarcode.Text;
                              FieldByName('descrizione').Value:=txtdescrizione.Text;
                              try
                                begin
                                     FieldByName('prezzoarticolo').Value:=strtofloat(txtprezzo.Text);
                                end;
                              except on E: Exception do
                                  FieldByName('prezzoarticolo').Value:=0;
                              end;

                              try
                                begin
                                     if(comboiva.ItemIndex >=0) then
                                         FieldByName('perceiva').Value:=strtofloat(comboiva.Items[comboiva.ItemIndex]);
                                end;
                              except on E: Exception do
                                  FieldByName('perceiva').Value:=0;
                              end;

                              if(comboiva.ItemIndex >=0) then
                                  FieldByName('perceivatxt').Value:=comboiva.Items[comboiva.ItemIndex];
                              if(SwitchIVA.IsChecked = false) then
                                 FieldByName('isivacompresa').Value:=0
                              else
                                  FieldByName('isivacompresa').Value:=1;

                              FieldByName('um').Value:=txtum.Text;

                              try
                                begin
                                    Connection.StartTransaction;
                                    posT;
                                    Connection.Commit;
                                    result:=true;
                                end;
                              except on E: Exception do
                                  begin
                                      if(Connection.InTransaction) then
                                         Connection.Rollback;
                                      result:=False;
                                  end;
                              end;

                         end;
                 end
             else
                result:=false;
        end
    else
        result:=false;
end;
Thanks,
Flavio

Re: Uniquery Error

Posted: Tue 06 May 2014 11:04
by AlexP
This is a correct behavior, since your table has no primary key. To solve the problem, you can use several options.
1) Modify the table by setting the idarticolo field as PrimaryKey.
2) Specify this field in the KeyFields property.
3) Set your own query in the UpdateSQL property.