Commit 54683936 authored by Mateusz Loskot's avatar Mateusz Loskot

Update to Sergei Nikulov's fix for issue #15

Clarify supported sequence of statement::execute(false|true) and
statement::get_affected_rows() calls across all backends:
1. execute(false) and empty destination does not execute statement, but
prepares for subsequent statement::fetch() requests.
2. execute(true)  and empty destination calls requests backend to
execute statement.
3. execute(false|true) causes bulk fetch to destination, with
withDataExchange=false|true ignored.
Moved relevant test to common tests, confirmed it passes for all but
Oracle (get_affected_rows not implemented) and Firebird (I have no means
to test).
Related discussion at
http://sourceforge.net/mailarchive/message.php?msg_id=30312517
Thanks to Sergei who first proposed this behaviour as reliable and
consistent option, yet not intrusive.
parent bc420495
......@@ -721,6 +721,15 @@ struct table_creator_three : public table_creator_base
}
};
struct table_creator_for_get_affected_rows : table_creator_base
{
table_creator_for_get_affected_rows(session & sql)
: table_creator_base(sql)
{
sql << "create table soci_test(val integer)";
}
};
//
// Support for SOCI Common Tests
//
......@@ -747,6 +756,11 @@ public:
return new table_creator_three(s);
}
table_creator_base* table_creator_4(session& s) const
{
return new table_creator_for_get_affected_rows(s);
}
std::string to_date_time(std::string const &datdt_string) const
{
return "\'" + datdt_string + "\'";
......
......@@ -1134,6 +1134,12 @@ public:
return new table_creator_three(s);
}
table_creator_base* table_creator_4(session& s) const
{
// get_affected_rows not implemented in Oracle backend
return 0;
}
std::string to_date_time(std::string const &datdt_string) const
{
return "to_date('" + datdt_string + "', 'YYYY-MM-DD HH24:MI:SS')";
......
......@@ -577,6 +577,15 @@ struct table_creator_three : public table_creator_base
}
};
struct table_creator_for_get_affected_rows : table_creator_base
{
table_creator_for_get_affected_rows(session & sql)
: table_creator_base(sql)
{
sql << "create table soci_test(val integer)";
}
};
//
// Support for soci Common Tests
//
......@@ -603,6 +612,11 @@ public:
return new table_creator_three(s);
}
table_creator_base* table_creator_4(session& s) const
{
return new table_creator_for_get_affected_rows(s);
}
std::string to_date_time(std::string const &datdt_string) const
{
return "timestamptz(\'" + datdt_string + "\')";
......
......@@ -258,55 +258,6 @@ void test5()
std::cout << "test 5 passed" << std::endl;
}
// Test commit b394d039530f124802d06c3b1a969c3117683152
// Author: Mika Fischer <mika.fischer@zoopnet.de>
// Date: Thu Nov 17 13:28:07 2011 +0100
// Implement get_affected_rows for SQLite3 backend
struct table_creator_for_test6 : table_creator_base
{
table_creator_for_test6(session & sql)
: table_creator_base(sql)
{
sql << "create table soci_test(val integer)";
}
};
void test6()
{
{
session sql(backEnd, connectString);
table_creator_for_test6 tableCreator(sql);
for (int i = 0; i != 10; i++)
{
sql << "insert into soci_test(val) values(:val)", use(i);
}
statement st1 = (sql.prepare <<
"update soci_test set val = val + 1");
st1.execute(true);
assert(st1.get_affected_rows() == 10);
statement st2 = (sql.prepare <<
"delete from soci_test where val <= 5");
st2.execute(true);
assert(st2.get_affected_rows() == 5);
statement st3 = (sql.prepare <<
"update soci_test set val = val + 1");
st3.execute(true);
assert(st3.get_affected_rows() == 5);
}
std::cout << "test 6 passed" << std::endl;
}
// DDL Creation objects for common tests
struct table_creator_one : public table_creator_base
{
......@@ -340,6 +291,20 @@ struct table_creator_three : public table_creator_base
}
};
// Originally, submitted to SQLite3 backend and later moved to common test.
// Test commit b394d039530f124802d06c3b1a969c3117683152
// Author: Mika Fischer <mika.fischer@zoopnet.de>
// Date: Thu Nov 17 13:28:07 2011 +0100
// Implement get_affected_rows for SQLite3 backend
struct table_creator_for_get_affected_rows : table_creator_base
{
table_creator_for_get_affected_rows(session & sql)
: table_creator_base(sql)
{
sql << "create table soci_test(val integer)";
}
};
//
// Support for SOCI Common Tests
//
......@@ -366,6 +331,11 @@ public:
return new table_creator_three(s);
}
table_creator_base* table_creator_4(session& s) const
{
return new table_creator_for_get_affected_rows(s);
}
std::string to_date_time(std::string const &datdt_string) const
{
return "datetime(\'" + datdt_string + "\')";
......@@ -407,7 +377,6 @@ int main(int argc, char** argv)
test3();
test4();
test5();
test6(); // FIXME: See issue #15
std::cout << "\nOK, all tests passed.\n\n";
......
......@@ -228,7 +228,7 @@ public:
: backEndFactory_(backEnd),
connectString_(connectString) {}
backend_factory const & getbackend_factory() const
backend_factory const & get_backend_factory() const
{
return backEndFactory_;
}
......@@ -243,6 +243,7 @@ public:
virtual table_creator_base* table_creator_1(session&) const = 0;
virtual table_creator_base* table_creator_2(session&) const = 0;
virtual table_creator_base* table_creator_3(session&) const = 0;
virtual table_creator_base* table_creator_4(session&) const = 0;
virtual ~test_context_base() {} // quiet the compiler
......@@ -256,7 +257,7 @@ class common_tests
public:
common_tests(test_context_base const &tc)
: tc_(tc),
backEndFactory_(tc.getbackend_factory()),
backEndFactory_(tc.get_backend_factory()),
connectString_(tc.get_connect_string())
{}
......@@ -303,6 +304,7 @@ public:
test28();
test29();
test30();
test_get_affected_rows();
}
private:
......@@ -3490,6 +3492,49 @@ void test30()
#endif // HAVE_BOOST
}
// Originally, submitted to SQLite3 backend and later moved to common test.
// Test commit b394d039530f124802d06c3b1a969c3117683152
// Author: Mika Fischer <mika.fischer@zoopnet.de>
// Date: Thu Nov 17 13:28:07 2011 +0100
// Implement get_affected_rows for SQLite3 backend
void test_get_affected_rows()
{
{
session sql(backEndFactory_, connectString_);
auto_table_creator tableCreator(tc_.table_creator_4(sql));
if (!tableCreator.get())
{
std::cout << "test get_affected_rows skipped (function not implemented)" << std::endl;
return;
}
for (int i = 0; i != 10; i++)
{
sql << "insert into soci_test(val) values(:val)", use(i);
}
statement st1 = (sql.prepare <<
"update soci_test set val = val + 1");
st1.execute(true);
assert(st1.get_affected_rows() == 10);
statement st2 = (sql.prepare <<
"delete from soci_test where val <= 5");
st2.execute(true);
assert(st2.get_affected_rows() == 5);
statement st3 = (sql.prepare <<
"update soci_test set val = val + 1");
st3.execute(true);
assert(st3.get_affected_rows() == 5);
}
std::cout << "test get_affected_rows passed" << std::endl;
}
}; // class common_tests
} // namespace tests
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment