HRecNum bug with query?

Startbeitrag von Arekusei Timakobu am 11.03.2015 07:40

Hi guys!
Does anyone met with this situation?
I have a TABLE control that display result of SQL query (non-embedded) where I need to delete a record. After reading documentation I do so:

RecordToDelete is int = HRecNum(QRY_Query)

In result RecordToDelete contains invalid record number - it is not match to the real record in the file and record with other record number is deleted.

HDelete(File,RecordToDelete) - incorrect record is deleted
HDelete(QRY_Query,RecordToDelete) - record is not deleted

Is it bug or "feature"?



HRecNum(QRY_Query) returns the number of records found (fetched) by the query not the id of the record.

You need to find the record id.

lnRow is int = TableSelect(MyTable)
RecordToDelete is int = QRY_Query[lnRow].idRecord
RecordToDelete is int = MyTable.idRecord

The query and table display are in memory so you will need to load the selected record from the DB.

von DerekT - am 11.03.2015 09:03

hRecNum on a query returns a sequential number, (counting from 1) that does not correspond to the physical recordnumber.
The physical recordnumber cannot be retrieved in a query.
So you cannot delete a record from the file directly, unless your query contains a unique key to look for the record.
You can delete the record directly from the query, but that will only work if your query is a single file query AND if the query has been executed using the hModifyFile parameter.


von Piet van Zanten - am 11.03.2015 11:28
Zur Information: hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.