mirror of https://github.com/go-gorm/gorm.git
Update sql validator for Count()
This commit is contained in:
parent
328e9401a0
commit
21713a5246
2
chain.go
2
chain.go
|
@ -273,7 +273,7 @@ func (s *Chain) Debug() *Chain {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Chain) validSql(str string) (result bool) {
|
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 {
|
if !result {
|
||||||
s.err(errors.New(fmt.Sprintf("SQL is not valid, %s", str)))
|
s.err(errors.New(fmt.Sprintf("SQL is not valid, %s", str)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -533,7 +533,11 @@ func TestOr(t *testing.T) {
|
||||||
func TestCount(t *testing.T) {
|
func TestCount(t *testing.T) {
|
||||||
var count, count1, count2 int64
|
var count, count1, count2 int64
|
||||||
var users []User
|
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)) {
|
if count != int64(len(users)) {
|
||||||
t.Errorf("Count() method should get same value of users count")
|
t.Errorf("Count() method should get same value of users count")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue