From 089ee96c19bbeccafe548aa405695c95c1e892e1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 15 Nov 2013 11:01:13 +0800 Subject: [PATCH] bug fixed --- mapper.go | 12 ++++-------- postgres_test.go | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/mapper.go b/mapper.go index 14b6ae0e..ff12e521 100644 --- a/mapper.go +++ b/mapper.go @@ -27,13 +27,9 @@ type SnakeMapper struct { func snakeCasedName(name string) string { newstr := make([]rune, 0) - firstTime := true - - for _, chr := range name { + for idx, chr := range name { if isUpper := 'A' <= chr && chr <= 'Z'; isUpper { - if firstTime == true { - firstTime = false - } else { + if idx > 0 { newstr = append(newstr, '_') } chr -= ('A' - 'a') @@ -44,7 +40,7 @@ func snakeCasedName(name string) string { return string(newstr) } -func pascal2Sql(s string) (d string) { +/*func pascal2Sql(s string) (d string) { d = "" lastIdx := 0 for i := 0; i < len(s); i++ { @@ -61,7 +57,7 @@ func pascal2Sql(s string) (d string) { } d += s[lastIdx+1:] return -} +}*/ func (mapper SnakeMapper) Obj2Table(name string) string { return snakeCasedName(name) diff --git a/postgres_test.go b/postgres_test.go index eddf6a3e..97c58133 100644 --- a/postgres_test.go +++ b/postgres_test.go @@ -1,7 +1,7 @@ package xorm import ( - "fmt" + //"fmt" //_ "github.com/bylevel/pq" _ "github.com/lib/pq" "testing" @@ -20,6 +20,7 @@ func TestPostgres(t *testing.T) { testAll2(engine, t) } +/* func TestPostgres2(t *testing.T) { engine, err := NewEngine("postgres", "dbname=xorm_test sslmode=disable") if err != nil { @@ -76,8 +77,6 @@ func TestPostgres2(t *testing.T) { joinSameMapper(engine, t) fmt.Println("-------------- havingSameMapper --------------") havingSameMapper(engine, t) - fmt.Println("-------------- transaction --------------") - transaction(engine, t) fmt.Println("-------------- combineTransactionSameMapper --------------") combineTransactionSameMapper(engine, t) fmt.Println("-------------- table --------------") @@ -106,7 +105,17 @@ func TestPostgres2(t *testing.T) { testMetaInfo(engine, t) fmt.Println("-------------- testIterate --------------") testIterate(engine, t) -} + fmt.Println("-------------- testStrangeName --------------") + testStrangeName(engine, t) + fmt.Println("-------------- testVersion --------------") + testVersion(engine, t) + fmt.Println("-------------- testDistinct --------------") + testDistinct(engine, t) + fmt.Println("-------------- testUseBool --------------") + testUseBool(engine, t) + fmt.Println("-------------- transaction --------------") + transaction(engine, t) +}*/ func BenchmarkPostgresNoCache(t *testing.B) { engine, err := NewEngine("postgres", "dbname=xorm_test sslmode=disable")