The query for retrieving fields that will uniquely identify a record is specified in the TIBCQuery.SmartFetch.SQLGetKeyValues.Text property. You should compose such a query yourself when the SQL query is complex, and the query to read the key and pre-selected fields cannot be generated automatically.
To solve the "Key fields not found" error in SmartFetch mode in your sample, you can use the following query for both TIBCQuery:
Code: Select all
IBCQuery1.SmartFetch.SQLGetKeyValues.Text: = 'select Mercadoria from CADASTRO_MERCADORIAS';
maybe this query will be not full, you should compose it yourself based on the architecture and logic of your application
and
Code: Select all
IBCQuery2.SmartFetch.SQLGetKeyValues.Text: = 'select Mercadoria from CADASTRO_MERCADORIAS';
Also, the "Key fields not found" error in SmartFetch mode when opening a dataset occurs when you cannot get key fields in your table. To solve the issue, you can set the TIBCQuery.KeyFields property (TIBCTable.KeyFields) to a valid value other than empty.