Update sql validator for Count()

This commit is contained in:
Jinzhu 2013-11-10 09:57:34 +08:00
parent 328e9401a0
commit 21713a5246
2 changed files with 6 additions and 2 deletions

View File

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

View File

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