Ver código fonte

1.fix querystring bit type
2.fix bit type on postgres

xormplus 8 anos atrás
pai
commit
a077f1bafd
3 arquivos alterados com 30 adições e 0 exclusões
  1. 3 0
      dialect_postgres.go
  2. 3 0
      session_query.go
  3. 24 0
      session_query_test.go

+ 3 - 0
dialect_postgres.go

@@ -781,6 +781,9 @@ func (db *postgres) SqlType(c *core.Column) string {
 	case core.TinyInt:
 		res = core.SmallInt
 		return res
+	case core.Bit:
+		res = core.Boolean
+		return res
 	case core.MediumInt, core.Int, core.Integer:
 		if c.IsAutoIncrement {
 			return core.Serial

+ 3 - 0
session_query.go

@@ -39,6 +39,9 @@ func reflect2value(rawValue *reflect.Value) (str string, err error) {
 		case reflect.Uint8:
 			data := rawValue.Interface().([]byte)
 			str = string(data)
+			if str == "\x00" {
+				str = "0"
+			}
 		default:
 			err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
 		}

+ 24 - 0
session_query_test.go

@@ -44,6 +44,30 @@ func TestQueryString(t *testing.T) {
 	assert.Equal(t, "1.5", records[0]["money"])
 }
 
+func TestQueryString2(t *testing.T) {
+	assert.NoError(t, prepareEngine())
+
+	type GetVar3 struct {
+		Id  int64 `xorm:"autoincr pk"`
+		Msg bool  `xorm:"bit"`
+	}
+
+	assert.NoError(t, testEngine.Sync2(new(GetVar3)))
+
+	var data = GetVar3{
+		Msg: false,
+	}
+	_, err := testEngine.Insert(data)
+	assert.NoError(t, err)
+
+	records, err := testEngine.QueryString("select * from get_var3")
+	assert.NoError(t, err)
+	assert.Equal(t, 1, len(records))
+	assert.Equal(t, 2, len(records[0]))
+	assert.Equal(t, "1", records[0]["id"])
+	assert.True(t, "0" == records[0]["msg"] || "false" == records[0]["msg"])
+}
+
 func toString(i interface{}) string {
 	switch i.(type) {
 	case []byte: