Recent

Author Topic: Edit a Record  (Read 471 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 547
Edit a Record
« on: November 06, 2024, 03:12:32 pm »
Hello,

i have a Record which needs to be Updated. When i first insert the Record everything works. As soon as i try to update, it it wont update (code executed but nothing changed in DB). when i changed update mode from "upWhereAll" to "upWhereChanged" it worked. it worked prior with "upWhereAll" but suddenly i doesn't.

this is the Code i use to Update/Edit the Record:

Code: Pascal  [Select][+][-]
  1.    //speichern
  2.    RsSave.Upda]"]>Blockedde:= upWhereChanged; //upWhereAll
  3.    RsSave.Clear;
  4.    RsSave.UsePrimaryKeyAsKey:= False;
  5.    RsSave.DataBase:= DB_WGR;
  6.    RsSave.SQL.Text:= 'SELECT * FROM GERAET WHERE ZEICHNUNG = '+fDevice.ID.ToString+' AND KOMP = 0 AND ART = 0';
  7.    RsSave.Open;
  8.    RsSave.Edit;
  9.    RsSave.FieldByName('ARahmenart').AsInteger:= Ord(fFrameTyp);
  10.    RsSave.FieldByName('AGNam').AsString:= fGSize;
  11.    RsSave.FieldByName('AgBreit').AsFloat:= fBreit;
  12.    RsSave.FieldByName('AgHoch').AsFloat:= fHoch;
  13.    RsSave.FieldByName('AlLumeng').AsFloat:= fLuftmenge;
  14.    RsSave.FieldByName('AlPaExt').AsFloat:= fPaExt;
  15.    RsSave.FieldByName('AlPa').AsFloat:= fPa;
  16.    RsSave.FieldByName('AlPaGes').AsFloat:= fPaGes;
  17.    RsSave.FieldByName('AlBed').AsInteger:= fBed;
  18.    RsSave.FieldByName('AlAn').AsInteger:= fAn;
  19.    RsSave.FieldByName('Para2').AsInteger:= fIsSwapped.ToInteger;
  20.    RsSave.FieldByName('APauss').AsString:= fPAussen.ToString +';'+ Float2Str(fBlechStarkAussen);
  21.    RsSave.FieldByName('APinn').AsString:= fPInnen.ToString +';'+ Float2Str(fBlechStarkInnen);
  22.    RsSave.FieldByName('APbod').AsString:= fPBoden.ToString +';'+ Float2Str(fBlechStarkBoden);
  23.    RsSave.FieldByName('AGausf').AsInteger:= fGAusf;
  24.    RsSave.FieldByName('Z2').AsFloat:= fRaisedByTF;
  25.    RsSave.FieldByName('Para4').AsInteger:= 0;
  26.    RsSave.Post;
  27.    RsSave.ApplyUpdates;
  28.    TransWGR.Commit;
  29.  

am i forced to replace my Transactions with Parameterized Transactions ?

Edit: found out there is a Blob Field in the Table that is causing the problem. if i have it then the Records wont update, and if i remove it then the records will update.
« Last Edit: November 06, 2024, 03:38:06 pm by Weitentaaal »

rvk

  • Hero Member
  • *****
  • Posts: 6591
Re: Edit a Record
« Reply #1 on: November 06, 2024, 04:34:23 pm »
Edit: found out there is a Blob Field in the Table that is causing the problem. if i have it then the Records wont update, and if i remove it then the records will update.
Which is kinda logical because you can't do WHERE BLOB = :OLD_BLOB.

BTW. I also wouldn't use upWhereChanged in normal production. It's better to have a normal proper database design and use an ID.

With upWhereChanged you could end up with duplicate records (same values in fields) and mess up your whole database.

jcmontherock

  • Sr. Member
  • ****
  • Posts: 272
Re: Edit a Record
« Reply #2 on: November 06, 2024, 04:48:50 pm »
There is also an sql update:

update set fieldname= fieldvalue where x=value...
Windows 11 UTF8-64 - Lazarus 4RC1-64 - FPC 3.2.2

Weitentaaal

  • Hero Member
  • *****
  • Posts: 547
Re: Edit a Record
« Reply #3 on: November 07, 2024, 01:16:14 pm »
thanks for the Help !

i did Update/edit the Databse this ways beacause i went with this tutorial: "https://wiki.freepascal.org/SqlDBHowto#How_to_change_data_in_a_table?". Since i always did it like this, i never considered using "SQL Update".

 

TinyPortal © 2005-2018