Fix invalid SQL issue

This commit is contained in:
Jinzhu 2014-04-28 16:52:01 +08:00
parent 6dc332e04d
commit d6d83b0cde
2 changed files with 7 additions and 1 deletions

View File

@ -1768,6 +1768,12 @@ func TestScan(t *testing.T) {
t.Errorf("Scan into struct should work")
}
var doubleAgeRes result
db.Table("users").Select("age + age as age").Where("name = ?", 3).Scan(&doubleAgeRes)
if doubleAgeRes.Age != res.Age*2 {
t.Errorf("Scan double age as age")
}
var ress []result
db.Table("users").Select("name, age").Where("name = ?", 3).Scan(&ress)
if len(ress) != 2 || ress[0].Name != "3" || ress[1].Name != "3" {

View File

@ -141,7 +141,7 @@ func (s *search) getInterfaceAsSql(value interface{}) (str string) {
s.db.err(InvalidSql)
}
if !regexp.MustCompile("^\\s*[\\w\\s,.*()]*\\s*$").MatchString(str) {
if !regexp.MustCompile("^\\s*[\\w\\s,.*\\+\\-()]*\\s*$").MatchString(str) {
s.db.err(InvalidSql)
}
return