fix querystring bit type

This commit is contained in:
Lunny Xiao 2017-09-09 14:21:47 +08:00
parent 3dad119dd6
commit 6a56f45255
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 27 additions and 0 deletions

View File

@ -39,6 +39,9 @@ func reflect2value(rawValue *reflect.Value) (str string, err error) {
case reflect.Uint8: case reflect.Uint8:
data := rawValue.Interface().([]byte) data := rawValue.Interface().([]byte)
str = string(data) str = string(data)
if str == "\x00" {
str = "0"
}
default: default:
err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name()) 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"]) 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.Equal(t, "0", records[0]["msg"])
}
func toString(i interface{}) string { func toString(i interface{}) string {
switch i.(type) { switch i.(type) {
case []byte: case []byte: