0

[anydac][DApt]-400.Fetch command fetched[0] instead of [1] record, Possible reasons:update table does not have PK or row identifier,record has been changed/deleted by another user,

when executing

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();

on

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)

as you can see, the table does have a PK. Also, the program is single-threaded and only one copy is running, so no one else is updating.

I set SingleTestRunADQuery.MasterFields=run_id and IndexFieldNames=run_id as that is the PK of table which holds a summary of all test runs. The second table hold the measurements taken during tests, with run_id giving all the measurements for one test run (I only added PK on tiemstamp to get rid of this error, but it didn't work and can be removed, I guess).

In case it helps, here's the master data source:

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)

Any idea what's wrong?


[Update] @ mj2008 points out that some fields have different names. This is for historical reasons (I am still trying something out & don't want to change yet), hoever these are adapted by the query:

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
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551

4 Answers4

3

I'm not sure that is correct to have TIMESTAMP field as PRIMARY KEY. It will automatically change on every UPDATE.

DiGi
  • 2,528
  • 18
  • 26
  • agreed In fact the table didn't have a PK - doesn't in my opinion need one, but I added it when that error message seemed to call for it. I didn't have it before & go the same eror. Interestingly, AnyDac is creating some sort of Fetch when I just want to insert. On the first insertion there is nothing to fetch – Mawg says reinstate Monica Mar 11 '13 at 09:46
  • btw, I will never `UPDATE` the measurements (details table), only the test runs (master table). – Mawg says reinstate Monica Mar 13 '13 at 04:27
1

Check out to the TFields property of Query component, through "Fields Editor" option. check that "Key Fields" has a ProviderFlags.pfInKey property set to true.

This applies today to FireDac components.

GatoSoft
  • 106
  • 1
  • 3
0

You should change the connection properties as follows: Try setting UpdateOptions.RefreshMode to rmManual.

enter image description here

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 04 '21 at 01:07
0

check if timestamp that is on database doesnot hav seconds and miliseconds