From 6efb976ba285d56311c7395e0849c3111f48d282 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sat, 16 Aug 2014 17:41:54 +0200 Subject: [PATCH] Fixed HKEYS command for SQLite3 backend. --- common/coords.go | 10 +++++++++- sqlite.go | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/common/coords.go b/common/coords.go index 8b33b33..dce9b46 100644 --- a/common/coords.go +++ b/common/coords.go @@ -4,9 +4,17 @@ package common -import "strconv" +import ( + "fmt" + "strconv" +) // Constructs a database key out of byte slice. func DecodePosFromBytes(key []byte) (pos int64, err error) { return strconv.ParseInt(string(key), 10, 64) } + +// Encode a block pos to byte slice. +func EncodePosToBytes(key int64) []byte { + return []byte(fmt.Sprintf("%d", key)) +} diff --git a/sqlite.go b/sqlite.go index 2984eb0..4f4cc6d 100644 --- a/sqlite.go +++ b/sqlite.go @@ -242,12 +242,12 @@ func (ss *SqliteSession) AllKeys(hash []byte) (keys chan []byte, n int, err erro defer rows.Close() defer close(keys) for rows.Next() { - var key []byte + var key int64 if err := rows.Scan(&key); err != nil { log.Printf("WARN: %s", err) break } - keys <- key + keys <- common.EncodePosToBytes(key) } }()