Uniquery Error

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
isysoftware
Posts: 44
Joined: Wed 14 Nov 2012 17:33

Uniquery Error

Post by isysoftware » Tue 15 Apr 2014 16:55

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

isysoftware
Posts: 44
Joined: Wed 14 Nov 2012 17:33

Re: Uniquery Error

Post by isysoftware » Wed 16 Apr 2014 07:43

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.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Uniquery Error

Post by azyk » Wed 16 Apr 2014 14:16

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

isysoftware
Posts: 44
Joined: Wed 14 Nov 2012 17:33

Re: Uniquery Error

Post by isysoftware » Wed 16 Apr 2014 15:04

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

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Uniquery Error

Post by azyk » Thu 17 Apr 2014 13:15

Hello, Flavio

If any other questions come up, please contact us.

Best regards,
Andrey
Devart Team
www.devart.com

isysoftware
Posts: 44
Joined: Wed 14 Nov 2012 17:33

Re: Uniquery Error

Post by isysoftware » Fri 18 Apr 2014 16:59

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

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Uniquery Error

Post by AlexP » Tue 06 May 2014 11:04

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.

Post Reply