diff --git a/chain.go b/chain.go index 18c24584..b6b14ab2 100644 --- a/chain.go +++ b/chain.go @@ -273,7 +273,7 @@ func (s *Chain) Debug() *Chain { } func (s *Chain) validSql(str string) (result bool) { - result = regexp.MustCompile("^\\s*[\\w][\\w\\s,.]*[\\w]\\s*$").MatchString(str) + result = regexp.MustCompile("^\\s*[\\w\\s,.*()]*\\s*$").MatchString(str) if !result { s.err(errors.New(fmt.Sprintf("SQL is not valid, %s", str))) } diff --git a/gorm_test.go b/gorm_test.go index d855f598..b165db15 100644 --- a/gorm_test.go +++ b/gorm_test.go @@ -533,7 +533,11 @@ func TestOr(t *testing.T) { func TestCount(t *testing.T) { var count, count1, count2 int64 var users []User - db.Where("name = ?", "1").Or("name = ?", "3").Find(&users).Count(&count) + + if err := db.Where("name = ?", "1").Or("name = ?", "3").Find(&users).Count(&count).Error; err != nil { + t.Errorf("Count should have no error", err) + } + if count != int64(len(users)) { t.Errorf("Count() method should get same value of users count") }