forked from MTSR/mapserver
common sql accessor
This commit is contained in:
parent
2119b09f85
commit
f9d0b78013
@ -2,6 +2,8 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"mapserver/coords"
|
"mapserver/coords"
|
||||||
|
"mapserver/settings"
|
||||||
|
"mapserver/layer"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Block struct {
|
type Block struct {
|
||||||
@ -19,7 +21,7 @@ type DBAccessor interface {
|
|||||||
Migrate() error
|
Migrate() error
|
||||||
|
|
||||||
FindBlocksByMtime(gtmtime int64, limit int) ([]*Block, error)
|
FindBlocksByMtime(gtmtime int64, limit int) ([]*Block, error)
|
||||||
FindNextInitialBlocks(lastpos *coords.MapBlockCoords, limit int) (*InitialBlocksResult, error)
|
FindNextInitialBlocks(s settings.Settings, layers []layer.Layer, limit int) (*InitialBlocksResult, error)
|
||||||
|
|
||||||
CountBlocks(frommtime, tomtime int64) (int, error)
|
CountBlocks(frommtime, tomtime int64) (int, error)
|
||||||
GetBlock(pos *coords.MapBlockCoords) (*Block, error)
|
GetBlock(pos *coords.MapBlockCoords) (*Block, error)
|
||||||
|
@ -4,13 +4,29 @@ import (
|
|||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"mapserver/coords"
|
"mapserver/coords"
|
||||||
"mapserver/db"
|
"mapserver/db"
|
||||||
|
"mapserver/settings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (this *Sqlite3Accessor) FindNextInitialBlocks(lastpos *coords.MapBlockCoords, limit int) (*db.InitialBlocksResult, error) {
|
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) {
|
||||||
|
|
||||||
result := &db.InitialBlocksResult{}
|
result := &db.InitialBlocksResult{}
|
||||||
|
|
||||||
blocks := make([]*db.Block, 0)
|
blocks := make([]*db.Block, 0)
|
||||||
|
|
||||||
|
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)
|
||||||
pc := coords.CoordToPlain(lastpos)
|
pc := coords.CoordToPlain(lastpos)
|
||||||
|
|
||||||
rows, err := this.db.Query(getLastBlockQuery, pc, limit)
|
rows, err := this.db.Query(getLastBlockQuery, pc, limit)
|
||||||
@ -19,6 +35,7 @@ func (this *Sqlite3Accessor) FindNextInitialBlocks(lastpos *coords.MapBlockCoord
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
var newlastpos *coords.MapBlockCoords
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var pos int64
|
var pos int64
|
||||||
@ -31,10 +48,17 @@ func (this *Sqlite3Accessor) FindNextInitialBlocks(lastpos *coords.MapBlockCoord
|
|||||||
}
|
}
|
||||||
|
|
||||||
mb := convertRows(pos, data, mtime)
|
mb := convertRows(pos, data, mtime)
|
||||||
|
newlastpos = mb.Pos
|
||||||
|
|
||||||
blocks = append(blocks, mb)
|
blocks = append(blocks, mb)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.List = blocks
|
result.List = blocks
|
||||||
|
|
||||||
|
//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)
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,6 @@ order by b.mtime asc
|
|||||||
limit ?
|
limit ?
|
||||||
`
|
`
|
||||||
|
|
||||||
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 ?
|
|
||||||
`
|
|
||||||
|
|
||||||
const countBlocksQuery = `
|
const countBlocksQuery = `
|
||||||
select count(*) from blocks b where b.mtime >= ? and b.mtime <= ?
|
select count(*) from blocks b where b.mtime >= ? and b.mtime <= ?
|
||||||
`
|
`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user