Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Keao <[email protected]>
  • Loading branch information
YangKeao committed Dec 5, 2024
1 parent c9ab4fc commit 7ee734f
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 2,135 deletions.
14 changes: 14 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,20 @@ func checkColumnDefaultValue(ctx sessionctx.Context, col *table.Column, value in
}
}
}
if value != nil && col.GetType() == mysql.TypeBit {
v, ok := value.(string)
if !ok {
return hasDefaultValue, value, types.ErrInvalidDefault.GenWithStackByArgs(col.Name.O)
}

uintVal, err := types.BinaryLiteral(v).ToInt(ctx.GetSessionVars().StmtCtx)
if err != nil {
return hasDefaultValue, value, types.ErrInvalidDefault.GenWithStackByArgs(col.Name.O)
}
if col.GetFlen() < 64 && uintVal >= 1<<(uint64(col.GetFlen())) {
return hasDefaultValue, value, types.ErrInvalidDefault.GenWithStackByArgs(col.Name.O)
}
}
return hasDefaultValue, value, nil
}

Expand Down
17 changes: 17 additions & 0 deletions ddl/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,20 @@ func TestExchangePartitionAfterDropForeignKey(t *testing.T) {
tk.MustExec("alter table child drop key fk_1;")
tk.MustExec("alter table child_with_partition exchange partition p1 with table child;")
}

func TestTooLongDefaultValueForBit(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test;")

tk.MustGetErrCode("create table t(a bit(2) default b'111');", 1067)
tk.MustGetErrCode("create table t(a bit(65) default b'111');", 1439)
tk.MustExec("create table t(a bit(64) default b'1111111111111111111111111111111111111111111111111111111111111111');")
tk.MustExec("drop table t")
tk.MustExec("create table t(a bit(3) default b'111');")
tk.MustExec("drop table t")
tk.MustExec("create table t(a bit(3) default b'000111');")
tk.MustExec("drop table t;")
tk.MustExec("create table t(a bit(32) default b'1111111111111111111111111111111');")
}
6 changes: 3 additions & 3 deletions executor/writetest/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ func TestIssue18681(t *testing.T) {
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
createSQL := `drop table if exists load_data_test;
create table load_data_test (a bit(1),b bit(1),c bit(1),d bit(1));`
create table load_data_test (a bit(1),b bit(1),c bit(1),d bit(1),e bit(32),f bit(1));`
tk.MustExec(createSQL)
tk.MustExec("load data local infile '/tmp/nonexistence.csv' ignore into table load_data_test")
ctx := tk.Session().(sessionctx.Context)
Expand All @@ -1523,7 +1523,7 @@ func TestIssue18681(t *testing.T) {
require.NotNil(t, ld)

deleteSQL := "delete from load_data_test"
selectSQL := "select bin(a), bin(b), bin(c), bin(d) from load_data_test;"
selectSQL := "select bin(a), bin(b), bin(c), bin(d), bin(e), bin(f) from load_data_test;"
ctx.GetSessionVars().StmtCtx.DupKeyAsWarning = true
ctx.GetSessionVars().StmtCtx.BadNullAsWarning = true

Expand All @@ -1534,7 +1534,7 @@ func TestIssue18681(t *testing.T) {
}()
sc.IgnoreTruncate.Store(false)
tests := []testCase{
{[]byte("true\tfalse\t0\t1\n"), []string{"1|0|0|1"}, "Records: 1 Deleted: 0 Skipped: 0 Warnings: 0"},
{[]byte("true\tfalse\t0\t1\tb'1'\tb'1'\n"), []string{"1|1|1|1|1100010001001110011000100100111|1"}, "Records: 1 Deleted: 0 Skipped: 0 Warnings: 5"},
}
checkCases(tests, ld, t, tk, ctx, selectSQL, deleteSQL)
require.Equal(t, uint16(0), sc.WarningCount())
Expand Down
Loading

0 comments on commit 7ee734f

Please sign in to comment.