Skip to content

Commit 563e1ae

Browse files
committed
Merge branch 'wl10787-drop-cleanup'
2 parents 4350f83 + 2f1ea3e commit 563e1ae

File tree

9 files changed

+172
-101
lines changed

9 files changed

+172
-101
lines changed

cdk/parser/expr_parser.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,18 @@ bool Expr_parser_base::parse_schema_ident(Token::Type (*types)[2])
468468

469469
void Expr_parser_base::parse_column_ident(Path_prc *prc)
470470
{
471-
parse_schema_ident();
471+
if (!parse_schema_ident())
472+
parse_error(L"Expected a column identifier");
472473
parse_column_ident1(prc);
473474
}
474475

475476

476477
void Expr_parser_base::parse_column_ident1(Path_prc *prc)
477478
{
479+
/*
480+
Note: at this point we assume that an (possibly schema qualified) identifier
481+
has been already seen and is stored in m_col_ref.table()
482+
*/
478483
if (consume_token(Token::DOT))
479484
{
480485
string name;
@@ -488,11 +493,13 @@ void Expr_parser_base::parse_column_ident1(Path_prc *prc)
488493
{
489494
// Re-interpret table name parsed by parse_schema_ident() as a
490495
// column name of the form [<table>.]<column>
496+
auto table = m_col_ref.table();
497+
assert(table);
491498

492-
if (m_col_ref.table()->schema())
493-
m_col_ref.set(m_col_ref.table()->name(), m_col_ref.table()->schema()->name());
499+
if (table->schema())
500+
m_col_ref.set(table->name(), table->schema()->name());
494501
else
495-
m_col_ref.set(m_col_ref.table()->name());
502+
m_col_ref.set(table->name());
496503
}
497504

498505
if (consume_token(Token::ARROW) || consume_token(Token::ARROW2))

devapi/session.cc

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,44 +1056,63 @@ void check_reply_skip_error_throw(cdk::Reply&& r, int skip_server_error)
10561056
void Session::dropSchema(const string &name)
10571057
{
10581058
try{
1059+
prepare_for_cmd();
10591060
std::stringstream qry;
10601061
qry << "Drop Schema `" << name << "`";
10611062
//skip server error 1008 = schema doesn't exist
1062-
check_reply_skip_error_throw(get_cdk_session().sql(qry.str()),
1063-
1008);
1063+
check_reply_skip_error_throw(get_cdk_session().sql(qry.str()), 1008);
10641064
}
10651065
CATCH_AND_WRAP
10661066
}
10671067

10681068

1069-
/*
1070-
TODO: better implementation: check if drop_collection can drop views also
1071-
*/
1069+
void Schema::dropTable(const string& table)
1070+
{
1071+
/*
1072+
Note: We simply forward to dropCollection() because xplugin does not
1073+
have a dedicated command for dropping tables and it does not distinguish
1074+
tables from collections.
1075+
*/
1076+
dropCollection(table);
1077+
}
10721078

1073-
void Session::dropTable(const mysqlx::string& schema, const string& table)
1079+
1080+
void Schema::dropCollection(const mysqlx::string& collection)
10741081
{
10751082
try{
1076-
Args args(schema, table);
1077-
// Doesn't throw if table doesn't exit (server error 1051)
1078-
check_reply_skip_error_throw(get_cdk_session().admin("drop_collection", args),
1079-
1051);
1083+
m_sess->prepare_for_cmd();
1084+
Args args(m_name, collection);
1085+
// Doesn't throw if collection doesn't exit (server error 1051)
1086+
check_reply_skip_error_throw(
1087+
m_sess->get_cdk_session().admin("drop_collection", args),
1088+
1051
1089+
);
10801090
}
10811091
CATCH_AND_WRAP
10821092
}
10831093

10841094

1085-
void Session::dropCollection(const mysqlx::string& schema,
1086-
const mysqlx::string& collection)
1095+
void Schema::dropView(const mysqlx::string& name)
10871096
{
1088-
try{
1089-
Args args(schema, collection);
1090-
// Doesn't throw if collection doesn't exit (server error 1051)
1091-
check_reply_skip_error_throw(get_cdk_session().admin("drop_collection", args),
1092-
1051);
1097+
Table_ref view(getName(),name);
1098+
1099+
try {
1100+
m_sess->prepare_for_cmd();
1101+
/*
1102+
Note: false argument to view_drop() means that we do not check for
1103+
the existence of the view being dropped.
1104+
We do not throw error 1347 (object is not a view) treating it the same
1105+
as the case when the view does not exist.
1106+
*/
1107+
check_reply_skip_error_throw(
1108+
m_sess->get_cdk_session().view_drop(view, false),
1109+
1347
1110+
);
10931111
}
10941112
CATCH_AND_WRAP
10951113
}
10961114

1115+
10971116
Schema Session::getDefaultSchema()
10981117
{
10991118
if (m_impl->m_default_db.empty())

devapi/table_crud.cc

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -676,53 +676,4 @@ ViewAlter::ViewAlter(Schema &sch, const string &name)
676676
} // namespace mysqlx
677677

678678

679-
/*
680-
ViewDrop
681-
========
682-
*/
683-
684-
namespace mysqlx {
685-
namespace internal{
686-
687-
class Op_ViewDrop
688-
: public Op_base<View_drop_impl>
689-
, public Table_ref
690-
{
691-
bool m_checkExistence = true;
692-
693-
public:
694-
695-
Op_ViewDrop(Schema &sch, const string &name)
696-
: Op_base<View_drop_impl>(sch.getSession())
697-
, Table_ref(sch.getName(), name)
698-
{}
699-
700-
void if_exists() override
701-
{
702-
m_checkExistence = false;
703-
}
704-
705-
Executable_impl* clone() const override
706-
{
707-
return new Op_ViewDrop(*this);
708-
}
709-
710-
cdk::Reply* send_command() override
711-
{
712-
return new cdk::Reply(get_cdk_session().view_drop(*this,m_checkExistence));
713-
}
714-
};
715-
716-
} // namespace internal
717-
718-
719-
ViewDrop::ViewDrop(Schema &sch, const string &name)
720-
{
721-
m_impl.reset(new internal::Op_ViewDrop(sch, name));
722-
}
723-
724-
} // namespace mysqlx
725-
726-
727-
728679
// ---------------------------------------------------------------------

devapi/tests/bugs-t.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,20 @@ TEST_F(Bugs, bug25505482)
9292

9393
cout << "Done!" << endl;
9494
}
95+
96+
TEST_F(Bugs, bug26130226_crash_update)
97+
{
98+
SKIP_IF_NO_XPLUGIN;
99+
100+
get_sess().dropSchema("crash_update");
101+
get_sess().createSchema("crash_update");
102+
Schema sch = get_sess().getSchema("crash_update");
103+
Collection coll = sch.createCollection("c1", true);
104+
105+
coll.add("{ \"name\": \"abc\", \"age\": 1 , \"misc\": 1.2}").execute();
106+
Table tabNew = sch.getCollectionAsTable("c1");
107+
108+
EXPECT_THROW(
109+
tabNew.update().set((char *)0, expr("")).execute(), // SegFault
110+
Error);
111+
}

devapi/tests/crud-t.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,9 +1330,9 @@ TEST_F(Crud, doc_path)
13301330
cout << "Creating session..." << endl;
13311331

13321332
Session sess(this);
1333-
sess.dropCollection("test", "coll");
13341333

13351334
Schema sch = sess.getSchema("test");
1335+
sch.dropCollection("coll");
13361336
Collection coll = sch.createCollection("coll",false);
13371337

13381338
coll.add( "{\"date\": {\"monthName\":\"December\", \"days\":[1,2,3]}}").execute();
@@ -1915,8 +1915,6 @@ TEST_F(Crud, group_by_having)
19151915
Session sess(this);
19161916

19171917
Schema test = sess.createSchema("test", true);
1918-
sess.dropCollection("test", "coll");
1919-
19201918
Collection coll = test.createCollection("coll", true);
19211919
Table tbl = test.getCollectionAsTable("coll", true);
19221920

@@ -2301,7 +2299,6 @@ TEST_F(Crud, single_document)
23012299
cout << "Session accepted, creating collection..." << endl;
23022300

23032301
Schema sch = sess.getSchema("test");
2304-
sess.dropCollection("test", "c1");
23052302
Collection coll = sch.createCollection("c1", true);
23062303

23072304
coll.add("{\"_id\":\"id1\", \"name\":\"foo\" }" )
@@ -2350,7 +2347,6 @@ TEST_F(Crud, add_or_replace)
23502347
cout << "Session accepted, creating collection..." << endl;
23512348

23522349
Schema sch = sess.getSchema("test");
2353-
sess.dropCollection("test", "c1");
23542350
Collection coll = sch.createCollection("c1", true);
23552351

23562352
coll.add("{\"_id\":\"id1\", \"name\":\"foo\" }")

devapi/tests/ddl-t.cc

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,31 @@ TEST_F(Ddl, create_drop)
101101

102102
//Drop Tables/Views
103103

104-
std::list<string> names_list = schema.getTableNames();
104+
/*
105+
Note: currently passing view to dropTable() does nothing. Changing this
106+
requires changes in xplugin. Similar with passing table to dropView().
107+
*/
108+
//EXPECT_THROW(schema.dropTable("view1"), mysqlx::Error);
109+
EXPECT_NO_THROW(schema.dropTable("view1"));
110+
EXPECT_NO_THROW(schema.getTable("view1", true));
105111

106-
for (auto name : names_list)
112+
EXPECT_NO_THROW(schema.dropView("tb1"));
113+
EXPECT_NO_THROW(schema.getTable("tb1", true));
114+
115+
std::list<Table> table_list = schema.getTables();
116+
117+
for (auto t : table_list)
107118
{
108119
//View is not dropped, but still no error thrown
109-
get_sess().dropTable(schema.getName(), name);
120+
if (t.isView())
121+
schema.dropView(t.getName());
122+
else
123+
schema.dropTable(t.getName());
110124
}
111125

112126
EXPECT_THROW(schema.getTable("tb1", true), mysqlx::Error);
113127
EXPECT_THROW(schema.getTable("tb2", true), mysqlx::Error);
128+
EXPECT_THROW(schema.getTable("view1", true), mysqlx::Error);
114129
}
115130

116131
//Collection tests
@@ -137,16 +152,24 @@ TEST_F(Ddl, create_drop)
137152

138153
// Drop Collections
139154

155+
/*
156+
Note: currently passing collection to dropView() does nothing. Changing this
157+
requires changes in xplugin.
158+
*/
159+
160+
EXPECT_NO_THROW(schema.dropView(collection_name_1));
161+
EXPECT_NO_THROW(schema.getCollection(collection_name_1, true));
162+
140163
std::list<string> list_coll_name = schema.getCollectionNames();
141164
for (auto name : list_coll_name)
142165
{
143-
get_sess().dropCollection(schema.getName(), name);
166+
schema.dropCollection(name);
144167
}
145168

146169
//Doesn't throw even if don't exist
147170
for (auto name : list_coll_name)
148171
{
149-
get_sess().dropCollection(schema.getName(), name);
172+
schema.dropCollection(name);
150173
}
151174

152175
//Test Drop Collection
@@ -183,3 +206,42 @@ TEST_F(Ddl, create_drop)
183206

184207
cout << "Done!" << endl;
185208
}
209+
210+
TEST_F(Ddl, bugs)
211+
{
212+
213+
SKIP_IF_NO_XPLUGIN;
214+
215+
{
216+
/*
217+
Having Result before dropView() triggered error, because cursor was closed
218+
without informing Result, so that Result coud cache and then close Cursor
219+
and Reply
220+
*/
221+
222+
get_sess().dropSchema("bugs");
223+
get_sess().createSchema("bugs", false);
224+
225+
Schema schema = get_sess().getSchema("bugs");
226+
sql(
227+
"CREATE TABLE bugs.bugs_table("
228+
"c0 JSON,"
229+
"c1 INT"
230+
")");
231+
232+
Table tbl = schema.getTable("bugs_table");
233+
234+
schema.createView("newView").algorithm(Algorithm::TEMPTABLE)
235+
.security(SQLSecurity ::INVOKER).definedAs(tbl.select()).execute();
236+
237+
RowResult result = get_sess().sql("show create view bugs.newView").execute();
238+
Row r = result.fetchOne();
239+
240+
schema.dropView("newView");
241+
242+
schema.createView("newView").algorithm(Algorithm::TEMPTABLE)
243+
.security(SQLSecurity ::INVOKER).definedAs(tbl.select()).execute();
244+
245+
r = result.fetchOne();
246+
}
247+
}

0 commit comments

Comments
 (0)