fix querystring bit type (#711)

* fix querystring bit type

* fix bit type on postgres
This commit is contained in:
Lunny Xiao 2017-09-09 17:10:15 +08:00 committed by GitHub
parent 3dad119dd6
commit 8439b76875
3 changed files with 30 additions and 0 deletions

View File

@ -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

View File

@ -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())
}

View File

@ -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: