forked from pingcap/tidb-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update pkg about database (pingcap#142)
- Loading branch information
1 parent
db3a058
commit e819b7f
Showing
8 changed files
with
437 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2018 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package dbutil | ||
|
||
import ( | ||
. "github.com/pingcap/check" | ||
) | ||
|
||
func (*testDBSuite) TestReplacePlaceholder(c *C) { | ||
testCases := []struct { | ||
originStr string | ||
args []string | ||
expectStr string | ||
}{ | ||
{ | ||
"a > ? AND a < ?", | ||
[]string{"1", "2"}, | ||
"a > '1' AND a < '2'", | ||
}, { | ||
"a = ? AND b = ?", | ||
[]string{"1", "2"}, | ||
"a = '1' AND b = '2'", | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
str := ReplacePlaceholder(testCase.originStr, testCase.args) | ||
c.Assert(str, Equals, testCase.expectStr) | ||
} | ||
|
||
} | ||
|
||
func (*testDBSuite) TestTableName(c *C) { | ||
testCases := []struct { | ||
schema string | ||
table string | ||
expectTableName string | ||
}{ | ||
{ | ||
"test", | ||
"testa", | ||
"`test`.`testa`", | ||
}, | ||
{ | ||
"test-1", | ||
"test-a", | ||
"`test-1`.`test-a`", | ||
}, | ||
{ | ||
"test", | ||
"t`esta", | ||
"`test`.`t``esta`", | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
tableName := TableName(testCase.schema, testCase.table) | ||
c.Assert(tableName, Equals, testCase.expectTableName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.