1
0
forked from MTSR/mapserver
mapserver/server/db/sqlite/initialblocks.go

65 lines
1.4 KiB
Go
Raw Normal View History

2019-02-11 18:32:39 +03:00
package sqlite
import (
_ "github.com/mattn/go-sqlite3"
"mapserver/coords"
"mapserver/db"
2019-02-13 17:44:05 +03:00
"mapserver/settings"
2019-02-11 18:32:39 +03:00
)
2019-02-13 17:44:05 +03:00
const getLastBlockQuery = `
select pos,data,mtime
from blocks b
where b.mtime = 0
and b.pos > ?
order by b.pos asc, b.mtime asc
limit ?
`
func (this *Sqlite3Accessor) FindNextInitialBlocks(s settings.Settings, layers []layer.Layer, limit int) (*db.InitialBlocksResult, error) {
2019-02-11 18:32:39 +03:00
result := &db.InitialBlocksResult{}
blocks := make([]*db.Block, 0)
2019-02-13 17:44:05 +03:00
lastx := s.GetInt(settings.SETTING_LASTX, coords.MinCoord-1)
lasty := s.GetInt(settings.SETTING_LASTY, coords.MinCoord-1)
lastz := s.GetInt(settings.SETTING_LASTZ, coords.MinCoord-1)
lastcoords := coords.NewMapBlockCoords(lastx, lasty, lastz)
2019-02-11 18:32:39 +03:00
pc := coords.CoordToPlain(lastpos)
rows, err := this.db.Query(getLastBlockQuery, pc, limit)
if err != nil {
return nil, err
}
defer rows.Close()
2019-02-13 17:44:05 +03:00
var newlastpos *coords.MapBlockCoords
2019-02-11 18:32:39 +03:00
for rows.Next() {
var pos int64
var data []byte
var mtime int64
err = rows.Scan(&pos, &data, &mtime)
if err != nil {
return nil, err
}
mb := convertRows(pos, data, mtime)
2019-02-13 17:44:05 +03:00
newlastpos = mb.Pos
2019-02-11 18:32:39 +03:00
blocks = append(blocks, mb)
}
result.List = blocks
2019-02-13 17:44:05 +03:00
//Save current positions of initial run
s.SetInt(settings.SETTING_LASTX, newlastpos.X)
s.SetInt(settings.SETTING_LASTY, newlastpos.Y)
s.SetInt(settings.SETTING_LASTZ, newlastpos.Z)
2019-02-11 18:32:39 +03:00
return result, nil
}