Merge branch 'master' into lunny/support_null_float

This commit is contained in:
Lunny Xiao 2019-10-05 14:42:38 +08:00 committed by GitHub
commit ac74909e9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 4 deletions

View File

@ -618,3 +618,28 @@ func TestCustomTypes(t *testing.T) {
assert.True(t, has)
assert.EqualValues(t, 32, age)
}
func TestGetViaMapCond(t *testing.T) {
type GetViaMapCond struct {
Id int64
Platform int
Index int
}
assert.NoError(t, prepareEngine())
assertSync(t, new(GetViaMapCond))
var (
r GetViaMapCond
platformStr = colMapper.Obj2Table("Platform")
indexStr = colMapper.Obj2Table("Index")
query = map[string]interface{}{
platformStr: 1,
indexStr: 1,
}
)
has, err := testEngine.Where(query).Get(&r)
assert.NoError(t, err)
assert.False(t, has)
}

View File

@ -344,9 +344,15 @@ func (session *Session) Sync2(beans ...interface{}) error {
}
}
}
if col.Default != oriCol.Default {
engine.logger.Warnf("Table %s Column %s db default is %s, struct default is %s",
tbName, col.Name, oriCol.Default, col.Default)
if (col.SQLType.Name == core.Bool || col.SQLType.Name == core.Boolean) &&
((strings.EqualFold(col.Default, "true") && oriCol.Default == "1") ||
(strings.EqualFold(col.Default, "false") && oriCol.Default == "0")) {
} else {
engine.logger.Warnf("Table %s Column %s db default is %s, struct default is %s",
tbName, col.Name, oriCol.Default, col.Default)
}
}
if col.Nullable != oriCol.Nullable {
engine.logger.Warnf("Table %s Column %s db nullable is %v, struct nullable is %v",

View File

@ -332,3 +332,16 @@ func TestSync2_2(t *testing.T) {
assert.True(t, tableNames[table.Name])
}
}
func TestSync2_Default(t *testing.T) {
type TestSync2Default struct {
Id int64
UserId int64 `xorm:"default(1)"`
IsMember bool `xorm:"default(true)"`
Name string `xorm:"default('my_name')"`
}
assert.NoError(t, prepareEngine())
assertSync(t, new(TestSync2Default))
assert.NoError(t, testEngine.Sync2(new(TestSync2Default)))
}

View File

@ -149,8 +149,12 @@ func (statement *Statement) And(query interface{}, args ...interface{}) *Stateme
cond := builder.Expr(query.(string), args...)
statement.cond = statement.cond.And(cond)
case map[string]interface{}:
cond := builder.Eq(query.(map[string]interface{}))
statement.cond = statement.cond.And(cond)
queryMap := query.(map[string]interface{})
newMap := make(map[string]interface{})
for k, v := range queryMap {
newMap[statement.Engine.Quote(k)] = v
}
statement.cond = statement.cond.And(builder.Eq(newMap))
case builder.Cond:
cond := query.(builder.Cond)
statement.cond = statement.cond.And(cond)