[anydac][DApt]-400.Fetch command fetched[0] 而不是 [1] 记录,可能的原因:更新表没有 PK 或行标识符,记录已被另一个用户更改/删除,
执行时
SingleTestRunADQuery.Append();
SingleTestRunADQuery.FieldByName('run_id').Value := StartRecordingButton.Tag;
SingleTestRunADQuery.FieldByName('ph_value').Value := FloatToStr(ph_reading);
SingleTestRunADQuery.FieldByName('conductivity_value').Value := conductivity_reading;
SingleTestRunADQuery.FieldByName('cod_value').Value := cod_reading;
SingleTestRunADQuery.Post();
在
mysql> describe measurements;
+------------------------+-----------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------+------+-----+-------------------+-------+
| run_id | int(11) | NO | MUL | NULL | |
| measurement_time_stamp | timestamp | NO | PRI | CURRENT_TIMESTAMP | |
| ph | float | NO | | NULL | |
| conductivity | float | NO | | NULL | |
| cod | float | NO | | NULL | |
+------------------------+-----------+------+-----+-------------------+-------+
5 rows in set (0.03 sec)
如您所见,该表确实有一个PK。此外,该程序是单线程的,只有一个副本在运行,所以没有其他人在更新。
我将其设置SingleTestRunADQuery.MasterFields=run_id and IndexFieldNames=run_id
为包含所有测试运行摘要的表的 PK。第二张表包含测试期间进行的测量,并run_id
给出了一次测试运行的所有测量值(我只在 tiemstamp 上添加了 PK 以消除此错误,但它不起作用并且可以删除,我猜)。
如果有帮助,这里是主数据源:
mysql> describe test_runs;
+------------------+-------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-------------+------+-----+-------------------+----------------+
| run_id | int(11) | NO | PRI | NULL | auto_increment |
| start_time_stamp | timestamp | NO | | CURRENT_TIMESTAMP | |
| end_time_stamp | timestamp | YES | | NULL | |
| description | varchar(64) | YES | | NULL | |
+------------------+-------------+------+-----+-------------------+----------------+
4 rows in set (0.05 sec)
知道有什么问题吗?
[更新]@mj2008 指出有些字段有不同的名称。这是出于历史原因(我仍在尝试一些东西并且还不想改变),但是这些是由查询调整的:
SELECT run_id,
measurement_time_stamp,
ph as ph_value,
conductivity as conductivity_value,
cod as cod_value
FROM photo_catalytic.measurements
ORDER BY measurement_time_stamp DESC