Improved error handling of SQLite spatial queries a bit.

This commit is contained in:
Sascha L. Teichmann 2014-09-01 14:28:12 +02:00
parent f7a8c1fdec
commit f82216807e

View File

@ -333,21 +333,24 @@ func (ss *SqliteSession) interleavedSpatialQuery(first, second []byte, done chan
rows *sql.Rows rows *sql.Rows
) )
if rows, err = rangeStmt.Query(zmin, zmax); err != nil { if rows, err = rangeStmt.Query(zmin, zmax); err != nil {
log.Printf("Error in range query: %s", err)
return return
} }
for rows.Next() { for rows.Next() {
var zcode int64 var zcode int64
var data []byte var data []byte
if err = rows.Scan(&zcode, &data); err != nil { if err = rows.Scan(&zcode, &data); err != nil {
log.Printf("Error in range query: %s", err) log.Printf("Error in scanning row: %s", err)
break rows.Close()
return
} }
c := common.InterleavedToCoord(zcode) c := common.InterleavedToCoord(zcode)
if cub.Contains(c) { if cub.Contains(c) {
var encodedKey []byte var encodedKey []byte
if encodedKey, err = common.EncodeStringToBytes(common.CoordToPlain(c)); err != nil { if encodedKey, err = common.EncodeStringToBytes(common.CoordToPlain(c)); err != nil {
log.Printf("Key encoding failed: %s", err) log.Printf("Key encoding failed: %s", err)
break rows.Close()
return
} }
select { select {
case blocks <- Block{Key: encodedKey, Data: data}: case blocks <- Block{Key: encodedKey, Data: data}:
@ -409,13 +412,14 @@ func (ss *SqliteSession) plainSpatialQuery(first, second []byte, done chan struc
// Ordering should not be necessary. // Ordering should not be necessary.
from, to := order(common.CoordToPlain(a), common.CoordToPlain(b)) from, to := order(common.CoordToPlain(a), common.CoordToPlain(b))
if rows, err = rangeStmt.Query(from, to); err != nil { if rows, err = rangeStmt.Query(from, to); err != nil {
log.Printf("Error in range query: %s", err)
return return
} }
for rows.Next() { for rows.Next() {
var key int64 var key int64
var data []byte var data []byte
if err = rows.Scan(&key, &data); err != nil { if err = rows.Scan(&key, &data); err != nil {
log.Printf("Error in range query: %s", err) log.Printf("Error in scanning row: %s", err)
break break
} }
var encodedKey []byte var encodedKey []byte