diff --git a/internal/ogc/features/datasources/geopackage/geopackage.go b/internal/ogc/features/datasources/geopackage/geopackage.go index 5d9a5084..00a18e21 100644 --- a/internal/ogc/features/datasources/geopackage/geopackage.go +++ b/internal/ogc/features/datasources/geopackage/geopackage.go @@ -114,7 +114,7 @@ func NewGeoPackage(collections config.GeoSpatialCollections, gpkgConfig config.G log.Fatal("unknown GeoPackage config encountered") } - g.selectClauseFids = []string{g.fidColumn, "prevfid", "nextfid"} + g.selectClauseFids = []string{g.fidColumn, domain.PrevFid, domain.NextFid} metadata, err := readDriverMetadata(g.backend.getDB()) if err != nil { @@ -353,9 +353,9 @@ with next as (select * from "%[1]s" where "%[2]s" >= :fid %[3]s %[4]s order by %[2]s asc limit :limit + 1), prev as (select * from "%[1]s" where "%[2]s" < :fid %[3]s %[4]s order by %[2]s desc limit :limit), nextprev as (select * from next union all select * from prev), - nextprevfeat as (select *, lag("%[2]s", :limit) over (order by %[2]s) as prevfid, lead("%[2]s", :limit) over (order by "%[2]s") as nextfid from nextprev) + nextprevfeat as (select *, lag("%[2]s", :limit) over (order by %[2]s) as %[6]s, lead("%[2]s", :limit) over (order by "%[2]s") as %[7]s from nextprev) select %[5]s from nextprevfeat where "%[2]s" >= :fid %[3]s %[4]s limit :limit -`, table.TableName, g.fidColumn, temporalClause, pfClause, selectClause) // don't add user input here, use named params for user input! +`, table.TableName, g.fidColumn, temporalClause, pfClause, selectClause, domain.PrevFid, domain.NextFid) // don't add user input here, use named params for user input! namedParams := map[string]any{ "fid": criteria.Cursor.FID, @@ -415,10 +415,10 @@ with limit (select iif(bbox_size == 'big', :limit, 0) from bbox_size)), prev as (select * from prev_bbox_rtree union all select * from prev_bbox_btree), nextprev as (select * from next union all select * from prev), - nextprevfeat as (select *, lag("%[2]s", :limit) over (order by "%[2]s") as prevfid, lead("%[2]s", :limit) over (order by "%[2]s") as nextfid from nextprev) + nextprevfeat as (select *, lag("%[2]s", :limit) over (order by "%[2]s") as %[9]s, lead("%[2]s", :limit) over (order by "%[2]s") as %[10]s from nextprev) select %[5]s from nextprevfeat where "%[2]s" >= :fid %[6]s %[7]s limit :limit `, table.TableName, g.fidColumn, g.maxBBoxSizeToUseWithRTree, table.GeometryColumnName, - selectClause, temporalClause, pfClause, btreeIndexHint) // don't add user input here, use named params for user input! + selectClause, temporalClause, pfClause, btreeIndexHint, domain.PrevFid, domain.NextFid) // don't add user input here, use named params for user input! bboxAsWKT, err := wkt.EncodeString(criteria.Bbox) if err != nil { diff --git a/internal/ogc/features/domain/cursor.go b/internal/ogc/features/domain/cursor.go index 056bd12c..59305716 100644 --- a/internal/ogc/features/domain/cursor.go +++ b/internal/ogc/features/domain/cursor.go @@ -9,7 +9,12 @@ import ( "strings" ) -const separator = '|' +const ( + PrevFid = "prevfid" + NextFid = "nextfid" + + separator = '|' +) // Cursors holds next and previous cursor. Note that we use // 'cursor-based pagination' as opposed to 'offset-based pagination' diff --git a/internal/ogc/features/domain/mapper.go b/internal/ogc/features/domain/mapper.go index 9fcc16dc..8fe99e82 100644 --- a/internal/ogc/features/domain/mapper.go +++ b/internal/ogc/features/domain/mapper.go @@ -111,13 +111,13 @@ func mapColumnsToFeature(firstRow bool, feature *Feature, columns []string, valu // Skip these columns used for bounding box and zoom filtering continue - case "prevfid": + case PrevFid: // Only the first row in the result set contains the previous feature id if firstRow && columnValue != nil { prevNextID.Prev = columnValue.(int64) } - case "nextfid": + case NextFid: // Only the first row in the result set contains the next feature id if firstRow && columnValue != nil { prevNextID.Next = columnValue.(int64) diff --git a/internal/ogc/features/domain/mapper_test.go b/internal/ogc/features/domain/mapper_test.go index c6ab0ea1..b370c2ab 100644 --- a/internal/ogc/features/domain/mapper_test.go +++ b/internal/ogc/features/domain/mapper_test.go @@ -66,7 +66,7 @@ func TestMapColumnsToFeature(t *testing.T) { name: "Test prevfid and nextfid", firstRow: true, feature: &Feature{Properties: NewFeatureProperties(false)}, - columns: []string{"prevfid", "nextfid"}, + columns: []string{PrevFid, NextFid}, values: []any{int64(1), int64(2)}, expectedFeature: &Feature{Properties: NewFeatureProperties(false)}, expectedPrevNext: &PrevNextFID{Prev: int64(1), Next: int64(2)},