Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Jan 8, 2014
1 parent dd9c707 commit 78fb484
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
16 changes: 14 additions & 2 deletions base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3175,7 +3175,9 @@ func testPointerData(engine *Engine, t *testing.T) {
// using instance type should just work too
nullData2Get := NullData2{}

has, err = engine.Table("null_data").Id(nullData.Id).Get(&nullData2Get)
tableName := engine.tableMapper.Obj2Table("NullData")

has, err = engine.Table(tableName).Id(nullData.Id).Get(&nullData2Get)
if err != nil {
t.Error(err)
panic(err)
Expand Down Expand Up @@ -3540,7 +3542,9 @@ func testNullValue(engine *Engine, t *testing.T) {
// update to null values
nullDataUpdate = NullData{}

cnt, err = engine.Id(nullData.Id).Cols("string_ptr").Update(&nullDataUpdate)
string_ptr := engine.columnMapper.Obj2Table("StringPtr")

cnt, err = engine.Id(nullData.Id).Cols(string_ptr).Update(&nullDataUpdate)
if err != nil {
t.Error(err)
panic(err)
Expand Down Expand Up @@ -3896,3 +3900,11 @@ func testAll3(engine *Engine, t *testing.T) {
fmt.Println("-------------- testStringPK --------------")
testStringPK(engine, t)
}

func testAllSnakeMapper(engine *Engine, t *testing.T) {

}

func testAllSameMapper(engine *Engine, t *testing.T) {

}
24 changes: 24 additions & 0 deletions mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ func TestMysql(t *testing.T) {
testAll3(engine, t)
}

func TestMysqlSameMapper(t *testing.T) {
err := mysqlDdlImport()
if err != nil {
t.Error(err)
return
}

engine, err := NewEngine("mysql", "root:@/xorm_test3?charset=utf8")
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.ShowSQL = showTestSql
engine.ShowErr = showTestSql
engine.ShowWarn = showTestSql
engine.ShowDebug = showTestSql
engine.SetMapper(SameMapper{})

testAll(engine, t)
testAll2(engine, t)
testAll3(engine, t)
}

func TestMysqlWithCache(t *testing.T) {
err := mysqlDdlImport()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func (statement *Statement) Distinct(columns ...string) *Statement {
func (statement *Statement) Cols(columns ...string) *Statement {
newColumns := col2NewCols(columns...)
for _, nc := range newColumns {
statement.columnMap[nc] = true
statement.columnMap[strings.ToLower(nc)] = true
}
statement.ColumnStr = statement.Engine.Quote(strings.Join(newColumns, statement.Engine.Quote(", ")))
return statement
Expand All @@ -521,7 +521,7 @@ func (statement *Statement) UseBool(columns ...string) *Statement {
if len(columns) > 0 {
newColumns := col2NewCols(columns...)
for _, nc := range newColumns {
statement.boolColumnMap[nc] = true
statement.boolColumnMap[strings.ToLower(nc)] = true
}
} else {
statement.allUseBool = true
Expand All @@ -533,7 +533,7 @@ func (statement *Statement) UseBool(columns ...string) *Statement {
func (statement *Statement) Omit(columns ...string) {
newColumns := col2NewCols(columns...)
for _, nc := range newColumns {
statement.columnMap[nc] = false
statement.columnMap[strings.ToLower(nc)] = false
}
statement.OmitStr = statement.Engine.Quote(strings.Join(newColumns, statement.Engine.Quote(", ")))
}
Expand Down Expand Up @@ -586,7 +586,7 @@ func (statement *Statement) genColumnStr() string {
colNames := make([]string, 0)
for _, col := range table.Columns {
if statement.OmitStr != "" {
if _, ok := statement.columnMap[col.Name]; ok {
if _, ok := statement.columnMap[strings.ToLower(col.Name)]; ok {
continue
}
}
Expand Down
7 changes: 4 additions & 3 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,9 @@ func (table *Table) genCols(session *Session, bean interface{}, useCol bool, inc
args := make([]interface{}, 0)

for _, col := range table.Columns {
lColName := strings.ToLower(col.Name)
if useCol && !col.IsVersion && !col.IsCreated && !col.IsUpdated {
if _, ok := session.Statement.columnMap[col.Name]; !ok {
if _, ok := session.Statement.columnMap[lColName]; !ok {
continue
}
}
Expand All @@ -439,12 +440,12 @@ func (table *Table) genCols(session *Session, bean interface{}, useCol bool, inc
}

if session.Statement.ColumnStr != "" {
if _, ok := session.Statement.columnMap[col.Name]; !ok {
if _, ok := session.Statement.columnMap[lColName]; !ok {
continue
}
}
if session.Statement.OmitStr != "" {
if _, ok := session.Statement.columnMap[col.Name]; ok {
if _, ok := session.Statement.columnMap[lColName]; ok {
continue
}
}
Expand Down

0 comments on commit 78fb484

Please sign in to comment.