Commit c6aef12b authored by Vadim Zeitlin's avatar Vadim Zeitlin

Add test checking string length when using bulk insert

This used to be broken, so add a test to check that it works after the
changes of the last commit and to avoid breaking it again.
parent 51c4c1e1
......@@ -352,6 +352,11 @@ public:
// whatever we do.
virtual bool enable_std_char_padding(session&) const { return true; }
// Return the name of the function for determining the length of a string,
// i.e. "char_length" in standard SQL but often "len" or "length" in
// practice.
virtual std::string get_length_function_name() const = 0;
virtual ~test_context_base()
{
the_test_context_ = NULL;
......@@ -4205,6 +4210,56 @@ TEST_CASE_METHOD(common_tests, "Select without table", "[core][select][dummy_fro
CHECK(plus17 == 17);
}
TEST_CASE_METHOD(common_tests, "String length", "[core][string][length]")
{
soci::session sql(backEndFactory_, connectString_);
auto_table_creator tableCreator(tc_.table_creator_1(sql));
std::string s("123");
sql << "insert into soci_test(str) values(:s)", use(s);
const std::string& len_func = tc_.get_length_function_name();
std::string sout;
size_t slen;
sql << "select str," + len_func + "(str)"
" from soci_test",
into(sout), into(slen);
CHECK(slen == 3);
CHECK(sout.length() == 3);
CHECK(sout == s);
sql << "delete from soci_test";
std::vector<std::string> v;
v.push_back("Hello");
v.push_back("");
v.push_back("whole of varchar(20)");
CHECK_NOTHROW( (sql << "insert into soci_test(str) values(:s)", use(v)) );
std::vector<std::string> vout(10);
std::vector<unsigned int> vlen(10);
sql << "select str," + len_func + "(str)"
" from soci_test"
" order by " + len_func + "(str)",
into(vout), into(vlen);
REQUIRE(vout.size() == 3);
REQUIRE(vlen.size() == 3);
CHECK(vlen[0] == 0);
CHECK(vout[0].length() == 0);
CHECK(vlen[1] == 5);
CHECK(vout[1].length() == 5);
CHECK(vlen[2] == 20);
CHECK(vout[2].length() == 20);
}
} // namespace test_cases
} // namespace tests
......
......@@ -95,6 +95,11 @@ public:
{
return "to_date('" + pi_datdt_string + "', 'YYYY-MM-DD HH24:MI:SS')";
}
virtual std::string get_length_function_name() const
{
return "length";
}
};
......
......@@ -1311,6 +1311,11 @@ class test_context : public tests::test_context_base
{
sql.commit();
}
virtual std::string get_length_function_name() const
{
return "char_length";
}
};
......
......@@ -127,6 +127,11 @@ public:
return false;
}
}
virtual std::string get_length_function_name() const
{
return "char_length";
}
};
#endif // SOCI_TESTS_MYSQL_H_INCLUDED
......@@ -107,6 +107,11 @@ test_context(backend_factory const &backEnd, std::string const &connectString)
{
return "#" + datdt_string + "#";
}
virtual std::string get_length_function_name() const
{
return "len";
}
};
int main(int argc, char** argv)
......
......@@ -93,6 +93,11 @@ public:
{
return "\'" + datdt_string + "\'";
}
virtual std::string get_length_function_name() const
{
return "length";
}
};
struct table_creator_bigint : table_creator_base
......
......@@ -160,6 +160,11 @@ public:
// on the side of caution and suppose that it's not supported.
return true;
}
virtual std::string get_length_function_name() const
{
return "len";
}
};
int main(int argc, char** argv)
......
......@@ -179,6 +179,11 @@ public:
return !m_verDriver.is_initialized() || m_verDriver < odbc_version(9, 3, 400);
}
virtual std::string get_length_function_name() const
{
return "char_length";
}
private:
odbc_version get_driver_version() const
{
......
......@@ -1555,6 +1555,11 @@ public:
{
return "to_date('" + datdt_string + "', 'YYYY-MM-DD HH24:MI:SS')";
}
virtual std::string get_length_function_name() const
{
return "length";
}
};
int main(int argc, char** argv)
......
......@@ -1172,6 +1172,11 @@ public:
{
return false;
}
virtual std::string get_length_function_name() const
{
return "char_length";
}
};
int main(int argc, char** argv)
......
......@@ -379,6 +379,11 @@ public:
// SQLite does not support right padded char type.
return false;
}
virtual std::string get_length_function_name() const
{
return "length";
}
};
int main(int argc, char** argv)
......
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