Browse Source

Merge pull request #752 from esbie/master

Add reflection support for smallint
Chris Bannister 9 năm trước cách đây
mục cha
commit
63994ed6ce
3 tập tin đã thay đổi với 30 bổ sung0 xóa
  1. 1 0
      AUTHORS
  2. 27 0
      cassandra_test.go
  3. 2 0
      helpers.go

+ 1 - 0
AUTHORS

@@ -70,3 +70,4 @@ Rob McColl <rob@robmccoll.com>; <rmccoll@ionicsecurity.com>
 Viktor Tönköl <viktor.toenkoel@motionlogic.de>
 Ian Lozinski <ian.lozinski@gmail.com>
 Michael Highstead <highstead@gmail.com>
+Sarah Brown <esbie.is@gmail.com>

+ 27 - 0
cassandra_test.go

@@ -761,6 +761,33 @@ func matchSliceMap(t *testing.T, sliceMap []map[string]interface{}, testMap map[
 	}
 }
 
+func TestSmallInt(t *testing.T) {
+	if *flagProto < protoVersion4 {
+		t.Skip("smallint is only supported in cassandra 2.2+")
+	}
+	session := createSession(t)
+	defer session.Close()
+	if err := createTable(session, `CREATE TABLE gocql_test.smallint_table (
+			testsmallint  smallint PRIMARY KEY,
+		)`); err != nil {
+		t.Fatal("create table:", err)
+	}
+	m := make(map[string]interface{})
+	m["testsmallint"] = int16(2)
+	sliceMap := []map[string]interface{}{m}
+	if err := session.Query(`INSERT INTO smallint_table (testsmallint) VALUES (?)`,
+		m["testsmallint"]).Exec(); err != nil {
+		t.Fatal("insert:", err)
+	}
+	if returned, retErr := session.Query(`SELECT * FROM smallint_table`).Iter().SliceMap(); retErr != nil {
+		t.Fatal("select:", retErr)
+	} else {
+		if sliceMap[0]["testsmallint"] != returned[0]["testsmallint"] {
+			t.Fatal("returned testsmallint did not match")
+		}
+	}
+}
+
 func TestScanWithNilArguments(t *testing.T) {
 	session := createSession(t)
 	defer session.Close()

+ 2 - 0
helpers.go

@@ -37,6 +37,8 @@ func goType(t TypeInfo) reflect.Type {
 		return reflect.TypeOf(*new(float64))
 	case TypeInt:
 		return reflect.TypeOf(*new(int))
+	case TypeSmallInt:
+		return reflect.TypeOf(*new(int16))
 	case TypeDecimal:
 		return reflect.TypeOf(*new(*inf.Dec))
 	case TypeUUID, TypeTimeUUID: