I load the layer from PostgreSQL completely into RAM.
var SelectSQL: string = 'SELECT * FROM MYTABLE WHERE ID > 1299 AND ID < 1321';
AxMap.AddLayerFromDatabase(ConnectionString, SelectSQL, true);
The table has an ID field with the primary key for this field. I have a question… Why are the ID field values overwritten in order starting from 1 when loading a layer in MapWinGIS? The field values should be 1300-1320, but in reality the values become 1-21. Is this how it should be? Is MapWinGIS working correctly? I have to create another unique field to link objects on the MapWinGIS map to a table in the Postgresql database. Or am I doing something wrong?
Something isn’t right. Your ID’s should maintain their values.
The ShapeIndex values are an internal reference that are always zero-based and created when you load the layer, but all of the field values of your table should be preserved, whether or not they are the primary key.
As a starting point, it would be interesting to know if PostgreSQL identifies your ID field as the so-called FID column (Feature ID column). Make a call to FIDColumnName and see what is returned.
Pseudo-code:
var SelectSQL: string = 'SELECT * FROM MYTABLE WHERE ID > 1299 AND ID < 1321';
var LayerHandle: integer = AxMap.AddLayerFromDatabase(ConnectionString, SelectSQL, true);
var MyTableLayer: OgrLayer = AxMap.OgrLayer(LayerHandle);
var FIDField: string = MyTableLayer.FIDColumnName();
Hopefully, PostgreSQL thinks that your ID field is the FID field, since it’s the primary key.
var SelectSQL: string = 'SELECT * FROM MYTABLE WHERE GID > 1299 AND GID < 1321';
var LayerHandle: integer = AxMap.AddLayerFromDatabase(ConnectionString, SelectSQL, true);
var MyTableLayer: OgrLayer = AxMap.OgrLayer(LayerHandle);
var FIDField: string = MyTableLayer.FIDColumnName();
FIDField = '';
I don’t know why. In fairness, it should be noted that my key field is named GID, not ID. Although… I don’t think it has anything to do with it. However, the GID field has a primary key!
Yes, ShapeIndex values are processed correctly. From 0 to the end in order…
Ups…
I figured out what was wrong. It’s my fault… I forgot to make again MyTableLayer.GetBuffer;
the Result was unpredictable.
After that, the ‘GID’ field began to show the correct values. All thanks… it worked as it should.
Although FIDColumnName still shows empty.