Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util/types: ignore string truncate error. #2685

Merged
merged 2 commits into from
Feb 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,12 @@ func (s *testSuite) TestIndexScan(c *C) {
tk.MustExec("CREATE INDEX idx_tab1_1 on tab1 (b, a)")
result = tk.MustQuery("SELECT pk FROM tab1 WHERE b > 1")
result.Check(testkit.Rows("3", "4"))

tk.MustExec("drop table if exists t")
tk.MustExec("CREATE TABLE t (a varchar(3), index(a))")
Copy link
Member

@coocood coocood Feb 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert t values ("aaa"), ("aab");

tk.MustExec("insert t values('aaa'), ('aab')")
result = tk.MustQuery("select * from t where a >= 'aaaa' and a < 'aabb'")
result.Check(testkit.Rows("[97 97 98]"))
}

func (s *testSuite) TestIndexReverseOrder(c *C) {
Expand Down
4 changes: 2 additions & 2 deletions util/types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ func (d *Datum) convertToString(sc *variable.StatementContext, target *FieldType
}

var err error
if target.Flen >= 0 {
if target.Flen >= 0 && !sc.IgnoreTruncate {
// Flen is the rune length, not binary length, for UTF8 charset, we need to calculate the
// rune count and truncate to Flen runes if it is too long.
if target.Charset == charset.CharsetUTF8 || target.Charset == charset.CharsetUTF8MB4 {
Expand All @@ -777,7 +777,7 @@ func (d *Datum) convertToString(sc *variable.StatementContext, target *FieldType
for i := range s {
runeCount++
if runeCount == target.Flen+1 {
// We do break here because we need to iterate to the end to get runeCount.
// We don't break here because we need to iterate to the end to get runeCount.
truncateLen = i
}
}
Expand Down