Skip to content

Commit

Permalink
Fix invalid SQL issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Apr 28, 2014
1 parent 6dc332e commit d6d83b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d6d83b0

Please sign in to comment.