瀏覽代碼

Merge pull request #209 from phillipCouto/float64_error

float64 point fails to marhsal
Ben Hood 11 年之前
父節點
當前提交
6f558cc0d1
共有 3 個文件被更改,包括 15 次插入1 次删除
  1. 14 0
      cassandra_test.go
  2. 0 0
      integration.sh
  3. 1 1
      marshal.go

+ 14 - 0
cassandra_test.go

@@ -872,3 +872,17 @@ func TestPreparedCacheEviction(t *testing.T) {
 		t.Error("expected delete statement to be cached, but statement was purged or not prepared.")
 	}
 }
+
+//TestMarshalFloat64Ptr tests to see that a pointer to a float64 is marshalled correctly.
+func TestMarshalFloat64Ptr(t *testing.T) {
+	session := createSession(t)
+	defer session.Close()
+
+	if err := session.Query("CREATE TABLE float_test (id double, test double, primary key (id))").Exec(); err != nil {
+		t.Fatal("create table:", err)
+	}
+	testNum := float64(7500)
+	if err := session.Query(`INSERT INTO float_test (id,test) VALUES (?,?)`, float64(7500.00), &testNum).Exec(); err != nil {
+		t.Fatal("insert float64:", err)
+	}
+}

+ 0 - 0
integration.sh


+ 1 - 1
marshal.go

@@ -659,7 +659,7 @@ func marshalDouble(info *TypeInfo, value interface{}) ([]byte, error) {
 	case reflect.Float64:
 		return encBigInt(int64(math.Float64bits(rv.Float()))), nil
 	case reflect.Ptr:
-		return marshalFloat(info, rv.Elem().Interface())
+		return marshalDouble(info, rv.Elem().Interface())
 	}
 	return nil, marshalErrorf("can not marshal %T into %s", value, info)
 }