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

server: check LOAD DATA is into a base table (#20924) #21638

Merged
merged 7 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
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().IsView() || loadDataInfo.Table.Meta().IsSequence() {
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