Skip to content

Commit eaeef69

Browse files
committed
MYCPP-312: FIX FUNCTION .DEFINER() NOT SETTING VALUE IN VIEWCREATE()
1 parent 2744813 commit eaeef69

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

devapi/table_crud.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ class Op_ViewCreateAlter
594594
if (options)
595595
{
596596

597+
options->definer(m_user);
598+
597599
switch (m_algorythm)
598600
{
599601
case Algorithm::MERGE:

devapi/tests/session-t.cc

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ TEST_F(Sess, view)
467467

468468
sch.createView(view_name, false)
469469
.security(mysqlx::SQLSecurity::DEFINER)
470-
.definer("root")
470+
.definer("root@localhost")
471471
.definedAs(tbl.select("name as view_name", "2016-age as view_birth"))
472472
.withCheckOption(mysqlx::CheckOption::LOCAL)
473473
.execute();
@@ -515,7 +515,7 @@ TEST_F(Sess, view)
515515
sch.alterView(view_name)
516516
.columns(columns_list, "one")
517517
.security(mysqlx::SQLSecurity::DEFINER)
518-
.definer("root")
518+
.definer("root@localhost")
519519
.definedAs(tbl_select)
520520
.withCheckOption(mysqlx::CheckOption::LOCAL)
521521
.execute()
@@ -524,7 +524,7 @@ TEST_F(Sess, view)
524524
auto view_exec = sch.alterView(view_name)
525525
.columns(columns_list, "one", string("two"))
526526
.security(mysqlx::SQLSecurity::DEFINER)
527-
.definer("root")
527+
.definer("root@localhost")
528528
.definedAs(tbl_select)
529529
.withCheckOption(mysqlx::CheckOption::LOCAL);
530530

@@ -554,7 +554,7 @@ TEST_F(Sess, view)
554554
EXPECT_THROW( sch.alterView(view_name2)
555555
.columns("view_name", "fake")
556556
.security(mysqlx::SQLSecurity::DEFINER)
557-
.definer("root")
557+
.definer("root@localhost")
558558
.definedAs(tbl_select)
559559
.withCheckOption(mysqlx::CheckOption::LOCAL)
560560
.execute()
@@ -621,6 +621,35 @@ TEST_F(Sess, view)
621621

622622
EXPECT_EQ(30, row.get(1).get<int>());
623623

624+
}
625+
626+
{
627+
sch.dropView(view_name).execute();
628+
629+
sch.createView(view_name)
630+
.algorithm(Algorithm::MERGE)
631+
.security(SQLSecurity::INVOKER)
632+
.definer("unknownUser")
633+
.definedAs(tbl.select())
634+
.withCheckOption(mysqlx::CheckOption::CASCADED)
635+
.execute();
636+
637+
std::stringstream qry;
638+
639+
qry << "show create view " << schema_name << "." << view_name;
640+
641+
SqlResult result = sql(qry.str());
642+
643+
Row r = result.fetchOne();
644+
std::string data = (string)r[1];
645+
646+
cout << r[0] << ": " << data << endl;
647+
648+
EXPECT_TRUE(data.find("MERGE") != std::string::npos);
649+
EXPECT_TRUE(data.find("INVOKER") != std::string::npos);
650+
EXPECT_TRUE(data.find("unknownUser") != std::string::npos);
651+
EXPECT_TRUE(data.find("CASCADED") != std::string::npos);
652+
624653
}
625654

626655
std::cout << "Drop view" << std::endl;

0 commit comments

Comments
 (0)