This strange error occurred when I used ADO to connect MYSQL to update data through ODBC in DELPHI today: the row cannot be updated or located. Some 20540; may have been changed after the last read. I was puzzled, so I went online to check. Some say that there is no primary key, but this table does. today, when I use ADO in DELPHI to connect to MYSQL to update data through ODBC, this strange error occurs: unable to locate the row for update. Some values may have changed since the last read.
I was puzzled, so I went online to check. Some say that there is no primary key, but I have some in this table; some say that there are default values. I checked that all fields do not have default values; some say that they are caused by first INSERT and then EDIT, this is pure EDIT, POST, no INSERT, so it does not exist.
After searching for another half a day, I finally found a similar situation. some people say that if the data modified by EDIT is the same as the original data, this error will be reported during POST. I checked it. actually, the value assigned to the field by the EDIT operation is the same as that before the modification. if the field value is changed slightly, the POST operation can be submitted normally. The solution is to determine whether the values are the same before assigning values to the fields. this is enough for BT.
The problem is solved, but why? By enabling ODBC tracking logs for analysis, we can probably guess the cause. The following section shows the SQL trace log that assigns the same value to all fields:
BEXE 13f4-1118EXIT SQLExecDirectW with return code 0 (SQL _SUCCESS)
HSTMT 0x0362C568
WCHAR * 0x0B774FC8 [-3] "UPDATE 'test'. 'table1' SET 'table1id' = ?, 'Tid' = ?, 'Name' = ?,... 'Bkwfid' =? WHERE 'table1id' =? AND 'tid' =? AND... AND 'bkwfid' =? \ 0"
SDWORD-3
BEXE 13f4-1118 EXIT SQLRowCount with return code 0 (SQL _SUCCESS)
HSTMT 0x0362C568
SQLLEN * 0x0018E804 (0)
Note that SQLRowCount returns 0, indicating that 0 rows are updated.
The following is the SQL trace log with a value change:
BEXE 13f4-1118 EXIT SQLExecDirectW with return code 0 (SQL _SUCCESS)
HSTMT 0x0362C568
WCHAR * 0x0B76FEC8 [-3] "UPDATE 'test'. 'table1' SET 'table1id' = ?, 'Tid' = ?, 'Name' = ?,... 'Bkwfid' =? WHERE 'table1id' =? AND 'tid' =? AND... AND 'bkwfid' =? \ 0"
SDWORD-3
BEXE 13f4-1118 EXIT SQLRowCount with return code 0 (SQL _SUCCESS)
HSTMT 0x0362C568
SQLLEN * 0x0018E804 (1)
At this time, SQLRowCount returns 1, which indicates that one row is updated.
The two SQL statements are identical, except that the content of the record after the previous SQL statement is executed is not changed, and the other one is changed! Then MYSQL will tell you that you have not updated any records. In fact, you have updated a record, but the results are the same before and after UPDATE, which has the same effect as those without UPDATE, so MYSQL returned 0, so ADO thought that the data was not updated, so it was deemed that someone else had modified the data, so it reported the error "unable to UPDATE the location Line.