1
0
forked from MTSR/mapserver

tiledb insert

This commit is contained in:
NatureFreshMilk 2019-01-17 08:01:48 +01:00
parent b3b55a27fc
commit b5d3e934b9
2 changed files with 33 additions and 8 deletions

View File

@ -53,6 +53,8 @@ func (db *Sqlite3Accessor) GetTile(layerId int, pos coords.TileCoords) (*Tile, e
return nil, err
}
defer rows.Close()
if rows.Next() {
var data []byte
var mtime int64
@ -80,13 +82,12 @@ func (db *Sqlite3Accessor) GetTile(layerId int, pos coords.TileCoords) (*Tile, e
}
const setTileQuery = `
insert into tiles(x,y,zoom,layerid,data,mtime)
insert or replace into tiles(x,y,zoom,layerid,data,mtime)
values(?, ?, ?, ?, ?, ?)
on conflict replace
`
func (db *Sqlite3Accessor) SetTile(tile *Tile) error {
_, err := db.db.Query(setTileQuery, tile.Pos.X, tile.Pos.Y, tile.Pos.Zoom, tile.LayerId, tile.Data, tile.Mtime)
_, err := db.db.Exec(setTileQuery, tile.Pos.X, tile.Pos.Y, tile.Pos.Zoom, tile.LayerId, tile.Data, tile.Mtime)
return err
}

View File

@ -8,7 +8,7 @@ import (
)
func TestMigrate(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrateEmpty.*.sqlite")
tmpfile, err := ioutil.TempFile("", "TileDBTest.*.sqlite")
if err != nil {
panic(err)
}
@ -25,14 +25,38 @@ func TestMigrate(t *testing.T) {
}
pos := coords.NewTileCoords(0, 0, 13)
_, err = db.GetTile(0, pos)
tile, err := db.GetTile(0, pos)
if err != nil {
panic(err)
}
data := []byte{}
tile := Tile{LayerId: 0, Pos: pos, Data: data}
err = db.SetTile(&tile)
if tile != nil {
t.Fatal("non-empty tile found")
}
data := []byte{0x01, 0x02}
tile2 := Tile{LayerId: 0, Pos: pos, Data: data}
err = db.SetTile(&tile2)
if err != nil {
panic(err)
}
tile3, err := db.GetTile(0, pos)
if err != nil {
panic(err)
}
if tile3 == nil {
t.Fatal("no data returned")
}
if len(tile2.Data) != len(tile3.Data) {
t.Fatal("inserted data does not match")
}
err = db.SetTile(&tile2)
if err != nil {
panic(err)