mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 17:56:13 -04:00
Cleanup unit test for Variadic bind()
This commit is contained in:
parent
3e56274e69
commit
390efbd301
@ -17,61 +17,57 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
//this requires c++14. seems like visual studio 2015 should work (yet untested).
|
// this requires c++14. visual studio 2015 is working
|
||||||
#if ( __cplusplus>= 201402L) || ( defined(_MSC_VER) && (_MSC_VER >= 1900) )
|
#if ( __cplusplus>= 201402L) || ( defined(_MSC_VER) && (_MSC_VER >= 1900) )
|
||||||
|
|
||||||
TEST(VariadicBind, invalid) {
|
TEST(VariadicBind, invalid) {
|
||||||
// Create a new database
|
// Create a new database
|
||||||
#if 0
|
SQLite::Database db(":memory:", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
|
||||||
SQLite::Database db("variadic_bind_test.db3", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
|
|
||||||
#else
|
|
||||||
SQLite::Database db(":memory:", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
EXPECT_EQ(0, db.exec("DROP TABLE IF EXISTS test"));
|
EXPECT_EQ(0, db.exec("DROP TABLE IF EXISTS test"));
|
||||||
EXPECT_EQ(0,
|
EXPECT_EQ(0,
|
||||||
db.exec(
|
db.exec(
|
||||||
"CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT DEFAULT 'default') "));
|
"CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT DEFAULT 'default') "));
|
||||||
EXPECT_TRUE(db.tableExists("test"));
|
EXPECT_TRUE(db.tableExists("test"));
|
||||||
|
|
||||||
{
|
{
|
||||||
SQLite::Statement query(db, "INSERT INTO test VALUES (?, ?)");
|
SQLite::Statement query(db, "INSERT INTO test VALUES (?, ?)");
|
||||||
|
|
||||||
//zero arguments - should give compile time error through a static assert
|
// zero arguments - should give compile time error through a static assert
|
||||||
//SQLite::bind(query);
|
// SQLite::bind(query);
|
||||||
|
|
||||||
//bind one argument less than expected - should be fine.
|
// bind one argument less than expected - should be fine.
|
||||||
//the unspecified argument should be set to null, not the default.
|
// the unspecified argument should be set to null, not the default.
|
||||||
SQLite::bind(query, 1);
|
SQLite::bind(query, 1);
|
||||||
EXPECT_EQ(1, query.exec());
|
EXPECT_EQ(1, query.exec());
|
||||||
query.reset();
|
query.reset();
|
||||||
|
|
||||||
//bind all arguments - should work just fine
|
// bind all arguments - should work just fine
|
||||||
SQLite::bind(query, 2, "two");
|
SQLite::bind(query, 2, "two");
|
||||||
EXPECT_EQ(1, query.exec());
|
EXPECT_EQ(1, query.exec());
|
||||||
query.reset();
|
query.reset();
|
||||||
|
|
||||||
//bind too many arguments - should throw.
|
// bind too many arguments - should throw.
|
||||||
EXPECT_THROW(SQLite::bind(query, 3, "three", 0), SQLite::Exception);
|
EXPECT_THROW(SQLite::bind(query, 3, "three", 0), SQLite::Exception);
|
||||||
EXPECT_EQ(1, query.exec());
|
EXPECT_EQ(1, query.exec());
|
||||||
}
|
}
|
||||||
|
|
||||||
//make sure the content is as expected
|
// make sure the content is as expected
|
||||||
{
|
{
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
SQLite::Statement query(db, "SELECT id, value FROM test ORDER BY id"s);
|
SQLite::Statement query(db, "SELECT id, value FROM test ORDER BY id"s);
|
||||||
std::vector<std::pair<int, std::string> > results;
|
std::vector<std::pair<int, std::string> > results;
|
||||||
while (query.executeStep()) {
|
while (query.executeStep()) {
|
||||||
const int id = query.getColumn(0);
|
const int id = query.getColumn(0);
|
||||||
std::string value = query.getColumn(1);
|
std::string value = query.getColumn(1);
|
||||||
results.emplace_back( id, std::move(value) );
|
results.emplace_back( id, std::move(value) );
|
||||||
}
|
}
|
||||||
EXPECT_EQ(std::size_t(3), results.size());
|
EXPECT_EQ(std::size_t(3), results.size());
|
||||||
|
|
||||||
EXPECT_EQ(std::make_pair(1,""s), results.at(0));
|
EXPECT_EQ(std::make_pair(1,""s), results.at(0));
|
||||||
EXPECT_EQ(std::make_pair(2,"two"s), results.at(1));
|
EXPECT_EQ(std::make_pair(2,"two"s), results.at(1));
|
||||||
EXPECT_EQ(std::make_pair(3,"three"s), results.at(2));
|
EXPECT_EQ(std::make_pair(3,"three"s), results.at(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // c++14
|
#endif // c++14
|
||||||
|
Loading…
x
Reference in New Issue
Block a user