Updating OGR Layer

We are having an issue with records being overwritten when edits are being down in more than 1 session. When a feature is added in one session it saves as expected but if another session adds a feature it deletes the other session row in the table. Each row has a unique ID. I have tried the ExtendFromQuery and selecting only the added features but it seems to clear the updated shapes. Is there something I need to add to support edits from multiple sessions?

Hello @HollidayHT

You should be able to manage edits from multiple sessions, particularly in an OGR datasource, presuming that the database and GDAL driver are capable (make sure to review the driver capabilities on the GDAL site). There can also be differences between updating via the MWGIS library vs submitting SQL updates directly to the database (via ExecuteSQL). But in order to get a better idea of what’s happening, you would need to post some of the code involved in the edits.

Regards,
Jerry.

Thanks for the quick response. Here is what I have tried.
I setup a very simple project to test this. I am using MySQL 8.0 for the database.
Code to start the editing:
If AxMap1.get_OgrLayer(iLayer).SupportsEditing(tkOgrSaveType.ostSaveAll) = False Then
Debug.WriteLine("Cant edit the layer: " + AxMap1.get_OgrLayer(iLayer).ErrorMsg(AxMap1.get_OgrLayer(iLayer).LastErrorCode))
Else
Debug.WriteLine(“Layer supports editing”)
End If
sf = AxMap1.get_OgrLayer(iLayer).GetBuffer
sf.StartEditingShapes()
sf.InteractiveEditing = True
AxMap1.CursorMode = tkCursorMode.cmAddShape
If AxMap1.LastErrorCode > 0 Then
Debug.WriteLine(AxMap1.get_ErrorMsg(AxMap1.LastErrorCode))
End If

Code to save the edits:

Dim iSavedShapes As Integer
Dim Result As tkOgrSaveResult = AxMap1.get_OgrLayer(iLayer).SaveChanges(iSavedShapes, tkOgrSaveType.ostSaveAll, True)

sf.InteractiveEditing = False
AxMap1.CursorMode = tkCursorMode.cmSelection

Debug.WriteLine(Result.ToString)
MsgBox(iSavedShapes.ToString + " Features saved.")

This is the table before any edits are made.

2 Polygons are added in session 1, they appear correctly in the table and the message box displays 2 features were saved.

In another session a new polygon is added and saved. Oddly the message box displays 3 features saved, I am assuming it has deleted the features added in the other session because they were not in the layer when it was originally opened. The table then look like this.

I have tried to use both ExtendFromQuery and RunQuery to update the layer before saving but it seems to discard any changes made.
Thanks for your help on this.
ToddH

In an effort to work around this issue I added code to create a table of all of the features added since the current session was opened before saving the layer. My intent was to then add these features back after the save and update the layer using the ExtendFromQuery function. This works well except the updated features attributes are shifted down.

This is how they should appear:
0: OGR_FID 10709
1: parcelid 0000-01-020-01E-1-007-00
2: account NA0010709
3: taxarea 101
4: ownername SPILLMAN FAMILY TRUST
5: address1 14901 N PENNSYLVANIA
6: address2 APT 205

Instead, they look like this:
0: OGR_FID 10709
1: parcelid 10709
2: account 0000-01-020-01E-1-007-00
3: taxarea NA0010709
4: ownername 101
5: address1 SPILLMAN FAMILY TRUST
6: address2 14901 N PENNSYLVANIA

This is the code I am currently using:

Dim sCmd As String = "SELECT * FROM " + oLayer.Name + " WHERE " + sOGRFld + “>” + iLayerMaxID.ToString + “;”

oLayer.ExtendFromQuery(sCmd)

I have tried to exclude the FIDColumnName and the GeometryColumnName from the select statement which didn’t work at all. My question is how should the select statement be formed to keep the attributes correct.

Thanks for the any help you could provide.