Selaa lähdekoodia

Handle bigint pointers correctly

Jonathan Rudenberg 13 vuotta sitten
vanhempi
commit
cd6a00cf5e
2 muutettua tiedostoa jossa 4 lisäystä ja 2 poistoa
  1. 3 1
      convert.go
  2. 1 1
      gocql_test.go

+ 3 - 1
convert.go

@@ -10,6 +10,7 @@ import (
 	"fmt"
 	"github.com/tux21b/gocql/uuid"
 	"math"
+	"reflect"
 	"strconv"
 	"time"
 )
@@ -124,8 +125,9 @@ func encInt(v interface{}) (driver.Value, error) {
 }
 
 func encBigInt(v interface{}) (driver.Value, error) {
+	x := reflect.Indirect(reflect.ValueOf(v)).Interface()
 	b := make([]byte, 8)
-	binary.BigEndian.PutUint64(b, uint64(v.(int64)))
+	binary.BigEndian.PutUint64(b, uint64(x.(int64)))
 	return b, nil
 }
 

+ 1 - 1
gocql_test.go

@@ -159,7 +159,7 @@ func TestTypes(t *testing.T) {
 
 	id := int64(-1 << 63)
 
-	if _, err := db.Exec(`INSERT INTO stuff (id, foo) VALUES (?, ?);`, id, "test"); err != nil {
+	if _, err := db.Exec(`INSERT INTO stuff (id, foo) VALUES (?, ?);`, &id, "test"); err != nil {
 		t.Fatal(err)
 	}