gpt4 book ai didi

mysql - "Row cannot be located for updating"错误 [另一个]

转载 作者:行者123 更新时间:2023-11-30 22:39:42 24 4
gpt4 key购买 nike

我正在使用 Delphi (XE3) 并需要连接到 MySQL 数据库。我遇到了一个看起来很常见的奇怪问题,但我仍然没有完全解决这个问题。

传统解决方案包括:

  • 将“更新条件”设置为 adCriteriaKey。
  • 确保您的表有主键(并将其告知 ADO 表)

问题 1:启动应用程序,执行代码:如果新值恰好与数据库中已有的值相匹配,我会在“B”位置收到错误。

问题 2:启动应用程序,执行代码:如果新值恰好与数据库中已有的值不同,则执行一次成功,然后在“A”位置报错。

由于记录主键未更改,因此随时定位记录应该没有任何问题。

object conMain: TADOConnection
Connected = True
ConnectionString =
'Provider=MSDASQL.1;Password=p;Persist Security Info=True;U' +
'ser ID=M;Extended Properties="Driver={MySQL ODBC 5.3 ANSI Dri' +
'ver};SERVER=yukon;DATABASE=db;UID=M;Pwd=p;PORT=3306;' +
'"'
LoginPrompt = False
Mode = cmShareDenyNone
Left = 48
Top = 24
end

object ADOTable1: TADOTable
Connection = conMain
IndexFieldNames = 'FacilityID'
TableName = 'facility'
Left = 152
Top = 24
end

procedure TForm1.Button1Click(Sender: TObject);
begin
conMain.Open;
ADOTable1.Open;
ADOTable1.Properties.Item['Update Criteria'].Value:=adCriteriaKey;
// **A**
if ADOTable1.Locate('facilityid', '{C0FADCC8-15C9-48C8-8003-3BBD4AB74586}', []) then
begin
ADOTable1.Edit;
ADOTable1.FieldByName('facilityaddress1').AsString:='mickey street';
ADOTable1.Properties.Item['Update Criteria'].Value:=adCriteriaKey;
// **B**
ADOTable1.Post;
end
else
showmessage('not found!');
ADOTable1.Close;
conMain.Close;
end;

就好像 Post 方法或连接使数据库处于某种中间状态...

这是我演示问题 1 时数据库日志的内容。

M@D3400 on db
SET NAMES latin1
SET character_set_results = NULL
SET SQL_AUTO_IS_NULL = 0
select database()
select database()
SHOW GLOBAL STATUS
SELECT @@tx_isolation
set @@sql_select_limit=DEFAULT
select * from facility
SHOW KEYS FROM `facility`
UPDATE `db`.`facility` SET `FacilityAddress1`=? WHERE `facilityid`=?
UPDATE `db`.`facility` SET `FacilityAddress1`='mickey street22' WHERE `facilityid`='{C0FADCC8-15C9-48C8-8003-3BBD4AB74586}'

这是我演示问题 2 时数据库日志的内容。

SHOW GLOBAL STATUS
M@D3400 on db
SET NAMES latin1
SET character_set_results = NULL
SET SQL_AUTO_IS_NULL = 0
select database()
select database()
SELECT @@tx_isolation
set @@sql_select_limit=DEFAULT
select * from facility
SHOW KEYS FROM `facility`
UPDATE `db`.`facility` SET `FacilityAddress1`=? WHERE `facilityid`=?
// SUCCESSFUL
UPDATE `db`.`facility` SET `FacilityAddress1`='mickey street22' WHERE `facilityid`='{C0FADCC8-15C9-48C8-8003-3BBD4AB74586}'
SHOW GLOBAL STATUS
SHOW GLOBAL STATUS
SHOW GLOBAL STATUS
db
select * from facility
UPDATE `db`.`facility` SET `FacilityAddress1`=? WHERE `facilityid`=?
// ERROR!
UPDATE `db`.`facility` SET `FacilityAddress1`='mickey street22' WHERE `facilityid`='{C0FADCC8-15C9-48C8-8003-3BBD4AB74586}'
SHOW GLOBAL STATUS

在各个地方设置“更新标准”没有帮助。

将表缩减为只有两个字段:facilityid varchar(38)、facilityaddress1 varchar(50)。同样的结果...

最佳答案

表格http://www.connectionstrings.com/mysql-connector-odbc-5-2/ ,我发现:

Provider=MSDASQL;Driver={MySQL ODBC 5.3 UNICODE Driver};Persist Security Info=True;Server=yukon;Database=ocean;User=M;Password=p;Option =2;

VB 建议使用“Option=2” http://dev.mysql.com/doc/connector-odbc/en/connector-odbc-configuration-connection-parameters.html#codbc-dsn-option-combos

有效!

感谢大家的贡献。

关于mysql - "Row cannot be located for updating"错误 [另一个],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31443766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com