|
|
@@ -1,12 +1,13 @@
|
|
|
+// Copyright 2017 The Xorm Authors. All rights reserved.
|
|
|
+// Use of this source code is governed by a BSD-style
|
|
|
+// license that can be found in the LICENSE file.
|
|
|
+
|
|
|
package xorm
|
|
|
|
|
|
import (
|
|
|
"reflect"
|
|
|
- "sync"
|
|
|
- "testing"
|
|
|
- "time"
|
|
|
-
|
|
|
"strings"
|
|
|
+ "testing"
|
|
|
|
|
|
"github.com/xormplus/core"
|
|
|
)
|
|
|
@@ -24,29 +25,19 @@ var colStrTests = []struct {
|
|
|
{"", 8, "`ID`, `IsDeleted`, `Caption`, `Code1`, `Code2`, `Code3`, `ParentID`, `Latitude`"},
|
|
|
}
|
|
|
|
|
|
-// !nemec784! Only for Statement object creation
|
|
|
-const driverName = "mysql"
|
|
|
-const dataSourceName = "Server=TestServer;Database=TestDB;Uid=testUser;Pwd=testPassword;"
|
|
|
-
|
|
|
-func init() {
|
|
|
- core.RegisterDriver(driverName, &mysqlDriver{})
|
|
|
-}
|
|
|
-
|
|
|
func TestColumnsStringGeneration(t *testing.T) {
|
|
|
-
|
|
|
var statement *Statement
|
|
|
|
|
|
for ndx, testCase := range colStrTests {
|
|
|
-
|
|
|
statement = createTestStatement()
|
|
|
|
|
|
if testCase.omitColumn != "" {
|
|
|
- statement.Omit(testCase.omitColumn) // !nemec784! Column must be skipped
|
|
|
+ statement.Omit(testCase.omitColumn)
|
|
|
}
|
|
|
|
|
|
+ columns := statement.RefTable.Columns()
|
|
|
if testCase.onlyToDBColumnNdx >= 0 {
|
|
|
- columns := statement.RefTable.Columns()
|
|
|
- columns[testCase.onlyToDBColumnNdx].MapType = core.ONLYTODB // !nemec784! Column must be skipped
|
|
|
+ columns[testCase.onlyToDBColumnNdx].MapType = core.ONLYTODB
|
|
|
}
|
|
|
|
|
|
actual := statement.genColumnStr()
|
|
|
@@ -54,11 +45,13 @@ func TestColumnsStringGeneration(t *testing.T) {
|
|
|
if actual != testCase.expected {
|
|
|
t.Errorf("[test #%d] Unexpected columns string:\nwant:\t%s\nhave:\t%s", ndx, testCase.expected, actual)
|
|
|
}
|
|
|
+ if testCase.onlyToDBColumnNdx >= 0 {
|
|
|
+ columns[testCase.onlyToDBColumnNdx].MapType = core.TWOSIDES
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func BenchmarkColumnsStringGeneration(b *testing.B) {
|
|
|
-
|
|
|
b.StopTimer()
|
|
|
|
|
|
statement := createTestStatement()
|
|
|
@@ -166,40 +159,10 @@ func (TestType) TableName() string {
|
|
|
}
|
|
|
|
|
|
func createTestStatement() *Statement {
|
|
|
-
|
|
|
- engine := createTestEngine()
|
|
|
-
|
|
|
statement := &Statement{}
|
|
|
statement.Init()
|
|
|
- statement.Engine = engine
|
|
|
+ statement.Engine = testEngine
|
|
|
statement.setRefValue(reflect.ValueOf(TestType{}))
|
|
|
|
|
|
return statement
|
|
|
}
|
|
|
-
|
|
|
-func createTestEngine() *Engine {
|
|
|
- driver := core.QueryDriver(driverName)
|
|
|
- uri, err := driver.Parse(driverName, dataSourceName)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
-
|
|
|
- dialect := &mysql{}
|
|
|
- err = dialect.Init(nil, uri, driverName, dataSourceName)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
-
|
|
|
- engine := &Engine{
|
|
|
- dialect: dialect,
|
|
|
- Tables: make(map[reflect.Type]*core.Table),
|
|
|
- mutex: &sync.RWMutex{},
|
|
|
- TagIdentifier: "xorm",
|
|
|
- TZLocation: time.Local,
|
|
|
- }
|
|
|
- engine.SetMapper(core.NewCacheMapper(new(core.SnakeMapper)))
|
|
|
-
|
|
|
- return engine
|
|
|
-}
|