diff --git a/dialect_postgres.go b/dialect_postgres.go index 1d4daa27..3f5c526f 100644 --- a/dialect_postgres.go +++ b/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 diff --git a/session_query.go b/session_query.go index 989efdf8..8bd11a3e 100644 --- a/session_query.go +++ b/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()) } diff --git a/session_query_test.go b/session_query_test.go index bdb1e1b2..4bb4598b 100644 --- a/session_query_test.go +++ b/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: