Let us consider this:
- Code: Select all Expand view
aRow := oCn:QueryResult('select * from '+cTable+' where '+cWhere )
oCn:Insert( cTable, nil, aRow )
I understand you are reading one or more rows from a source table and trying to insert into a destination table and also that both tables have the same structure with ID as autoinc primary key.
aRow contains ID values as recorded in the source table.
If the destination table does not contain these IDs the rows are inserted with the same ID in the destination table also.
Problem arises when the destination table already contains some rows with the same IDs.
In such cases of conflict, by default, the operation results in error and aborts from that point.
We can use the 4th logical parameter to decide what to do in case of conflict, i.e., if the ID already exists in the destination table.
Set the 4th optional parameter lUpdate to .T.:
In this case, if the ID already exists in the destination table, the same row is updated with the values from the source and otherwise the rows are inserted retaining the same ID as in the source.
Set the 4th parameter to .F.: ( ignore duplicates )
In this case rows with duplicate IDs are skipped without raising error and other rows are inserted retaining the same ID as in the source.
If you let me know what exactly you want to do, I can suggest how you can do that.