SOCI Session Sql return Values

297 views Asked by At

In my office I m asked to write some test cases on basic areas where db connections check and test, so that is a technology we gona implement newly so nobody there to ask for helping hand well and what they asked it to do for me is write Gtest(google test) for C++ with soci,

so now I have testcase like this,

Whether table got dropped or not,

so I wrote some code like this,

TEST(CheckNull, DropTable) 
 {
    bool output = true;
    session sql(oracle, "service=LOCAL user=ROOT password=123");
    string query = "drop table GTestAutomation";
    sql<<query;
    EXPECT_EQ(true,output);
}

now I wanted to check whether my sql statement successfully executed or not can I do something like this?

if(sql<<query)
{
  output = true ;
}
else
{
  output = false;
}

so that I can check my condition EXPECT_EQ(true,output); like this.

Need help, If you dont know correct way of doing or answer plz dont put etc etc comments.

Thanks

1

There are 1 answers

0
Superlokkus On

If you're statement was not successfully executed, soci would throw a soci::soci_error exception, which you can catch. So you could write something like this:

TEST(CheckNull, DropTable) 
 {
    bool output = true;
    session sql(oracle, "service=LOCAL user=ROOT password=123");
    string query = "drop table GTestAutomation";
    try{
        sql<<query;
    } catch (soci::soci_error &e) {
        output = false;
    }

    EXPECT_EQ(true,output);
}