Fixed HKEYS command for SQLite3 backend.

This commit is contained in:
Sascha L. Teichmann 2014-08-16 17:41:54 +02:00
parent b6c041b896
commit 6efb976ba2
2 changed files with 11 additions and 3 deletions

View File

@ -4,9 +4,17 @@
package common package common
import "strconv" import (
"fmt"
"strconv"
)
// Constructs a database key out of byte slice. // Constructs a database key out of byte slice.
func DecodePosFromBytes(key []byte) (pos int64, err error) { func DecodePosFromBytes(key []byte) (pos int64, err error) {
return strconv.ParseInt(string(key), 10, 64) 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))
}

View File

@ -242,12 +242,12 @@ func (ss *SqliteSession) AllKeys(hash []byte) (keys chan []byte, n int, err erro
defer rows.Close() defer rows.Close()
defer close(keys) defer close(keys)
for rows.Next() { for rows.Next() {
var key []byte var key int64
if err := rows.Scan(&key); err != nil { if err := rows.Scan(&key); err != nil {
log.Printf("WARN: %s", err) log.Printf("WARN: %s", err)
break break
} }
keys <- key keys <- common.EncodePosToBytes(key)
} }
}() }()