Forum > Databases

[SOLVED] Zeos + sqlite update issue

(1/3) > >>

kqha:
I have a SQLite table accessed using Zeos TZQuery with SQL:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SELECT rowid,* FROM mytablerowidid_ext1id_ext2txt1122123100200some text410002000lorem ipsum
Whenever I edit the first or second record in example table above, I always caught an exception says "2 record(s) updated. Only one record should have been updated", which shouldn't happen because I explicitly request rowid to be present in resulting rows in order to prevent such multiple updates to happen. Anyone know how to, says, force ZQuery to acknowledge rowid as primary key in order to prevent such error?

Zvoni:
What's that got to do with a Primary Key?
I'd need to see the Table-Structure/Create-Statement to give you a guess.

And you're talking about Update-Issue, but you're showing a SELECT

kqha:
Structure nothing special really
id_ext1integerid_ext2integertxtvarchar
Update done with simple code like

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);begin  ZQuery1.RecNo := 1;  ZQuery1.Edit;  ZQuery1.FieldByName('id_ext1').AsInteger := 2;  ZQuery1.Post;end;     

af0815:

--- Quote from: kqha on April 26, 2022, 12:49:12 pm ---id_ext1integerid_ext2integertxtvarchar
--- End quote ---
No primary Key ? So it korrekt that 2 records updated. id_ext have duplicate data. If you are on the first record and give them a new value, the second record with the same value will also updated. A rowid is a virtual number, that is not possible to be a primary key. The rowid is not stored in the DB.

All ok, ZEOS make what you want, not what you mean :(SCNR) You have to use a unique primary key.

kqha:

--- Quote from: af0815 on April 26, 2022, 01:02:36 pm ---No primary Key ? So it korrekt that 2 records updated. id_ext have duplicate data. If you are on the first record and give them a new value, the second record with the same value will also updated.

All ok, ZEOS make what you want, not what you mean :(SCNR) You have to use a unique primary key.

--- End quote ---

SQLite have an internal field called rowid, which autoincrement automatically, just like an integer autoinc primary key in any other DB. Yes I can easily solved this problem by adding a dummy autoinc primary key, but if there are other ways that can utilized SQLite rowid, I'd prefer to do that. Hence my original question :)

Navigation

[0] Message Index

[#] Next page

Go to full version