1
0
forked from MTSR/mapserver

CountBlocks impl

This commit is contained in:
Thomas Rudin 2019-01-09 10:16:22 +01:00
parent c3150e06a9
commit 869e7b28d6
2 changed files with 45 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
_ "github.com/mattn/go-sqlite3"
"github.com/sirupsen/logrus"
"time"
"errors"
)
var log *logrus.Entry
@ -73,7 +74,22 @@ func (db *Sqlite3Accessor) FindBlocks(posx int, posz int, posystart int, posyend
}
func (db *Sqlite3Accessor) CountBlocks(x1, x2, y1, y2, z1, z2 int) (int, error) {
return 0, nil
rows, err := db.db.Query("select count(*) from blocks")
if err != nil {
return 0, err
}
if !rows.Next() {
return 0, errors.New("No results")
}
var count int
err = rows.Scan(&count)
if err != nil {
return 0, err
}
return count, nil
}
func NewSqliteAccessor(filename string) (*Sqlite3Accessor, error) {

View File

@ -90,3 +90,31 @@ func TestMigrate(t *testing.T){
panic(err)
}
}
func TestMigrateAndQuery(t *testing.T){
tmpfile, err := ioutil.TempFile("", "example")
if err != nil {
panic(err)
}
createTestDatabase(tmpfile.Name())
a, err := NewSqliteAccessor(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
count, err := a.CountBlocks(-1000, 1000, -1000, 1000, -1000, 1000)
if err != nil {
panic(err)
}
if count <= 0 {
t.Fatal("wrong count!")
}
}