From d6d83b0cdededd98c1758b1c42eb857124dffc33 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 28 Apr 2014 16:52:01 +0800 Subject: [PATCH] Fix invalid SQL issue --- main_test.go | 6 ++++++ search.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 31e9d5f58..732ba55f6 100644 --- a/main_test.go +++ b/main_test.go @@ -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" { diff --git a/search.go b/search.go index 7f7e0da6f..833208ca9 100644 --- a/search.go +++ b/search.go @@ -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