Skip to content

Commit

Permalink
cherry pick pingcap#20924 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
Null not nil authored and ti-srebot committed Dec 10, 2020
1 parent a62d379 commit d2f4e1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,9 @@ func (cc *clientConn) handleLoadData(ctx context.Context, loadDataInfo *executor
if loadDataInfo == nil {
return errors.New("load data info is empty")
}

if !loadDataInfo.Table.Meta().IsBaseTable() {
return errors.New("can only load data into base tables")
}
err := cc.writeReq(ctx, loadDataInfo.Path)
if err != nil {
return err
Expand Down
11 changes: 11 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,17 @@ func (cli *testServerClient) runTestLoadData(c *C, server *Server) {
}, "LoadData", func(dbt *DBTest) {
dbt.mustExec("set @@tidb_dml_batch_size = 3")
dbt.mustExec("create table test (a varchar(255), b varchar(255) default 'default value', c int not null auto_increment, primary key(c))")
dbt.mustExec("create view v1 as select 1")
dbt.mustExec("create sequence s1")

// can't insert into views (in TiDB) or sequences. issue #20880
_, err = dbt.db.Exec("load data local infile '/tmp/load_data_test.csv' into table v1")
dbt.Assert(err, NotNil)
dbt.Assert(err.Error(), Equals, "Error 1105: can only load data into base tables")
_, err = dbt.db.Exec("load data local infile '/tmp/load_data_test.csv' into table s1")
dbt.Assert(err, NotNil)
dbt.Assert(err.Error(), Equals, "Error 1105: can only load data into base tables")

rs, err1 := dbt.db.Exec("load data local infile '/tmp/load_data_test.csv' into table test")
dbt.Assert(err1, IsNil)
lastID, err1 := rs.LastInsertId()
Expand Down

0 comments on commit d2f4e1b

Please sign in to comment.