@@ -28,14 +28,15 @@ TEST(VariadicBind, invalid) {
2828 EXPECT_EQ (0 ,
2929 db.exec (
3030 " CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT DEFAULT 'default') " ));
31+ EXPECT_EQ (0 ,
32+ db.exec (
33+ " CREATE TABLE test2 (id INTEGER PRIMARY KEY, value TEXT DEFAULT 'default') " ));
3134 EXPECT_TRUE (db.tableExists (" test" ));
35+ EXPECT_TRUE (db.tableExists (" test2" ));
3236
3337 {
3438 SQLite::Statement query (db, " INSERT INTO test VALUES (?, ?)" );
3539
36- // zero arguments - should give compile time error through a static assert
37- // SQLite::bind(query);
38-
3940 // bind one argument less than expected - should be fine.
4041 // the unspecified argument should be set to null, not the default.
4142 SQLite::bind (query, 1 );
@@ -51,7 +52,6 @@ TEST(VariadicBind, invalid) {
5152 EXPECT_THROW (SQLite::bind (query, 3 , " three" , 0 ), SQLite::Exception);
5253 EXPECT_EQ (1 , query.exec ());
5354 }
54-
5555 // make sure the content is as expected
5656 {
5757 SQLite::Statement query (db, std::string{" SELECT id, value FROM test ORDER BY id" });
@@ -67,5 +67,40 @@ TEST(VariadicBind, invalid) {
6767 EXPECT_EQ (std::make_pair (2 ,std::string{" two" }), results.at (1 ));
6868 EXPECT_EQ (std::make_pair (3 ,std::string{" three" }), results.at (2 ));
6969 }
70+ #if (__cplusplus >= 201402L) || ( defined(_MSC_VER) && (_MSC_VER >= 1900) ) // c++14: Visual Studio 2015
71+ {
72+ SQLite::Statement query (db, " INSERT INTO test2 VALUES (?, ?)" );
73+
74+ // bind one argument less than expected - should be fine.
75+ // the unspecified argument should be set to null, not the default.
76+ SQLite::bind (query, std::make_tuple (1 ));
77+ EXPECT_EQ (1 , query.exec ());
78+ query.reset ();
79+
80+ // bind all arguments - should work just fine
81+ SQLite::bind (query, std::make_tuple (2 , " two" ));
82+ EXPECT_EQ (1 , query.exec ());
83+ query.reset ();
84+
85+ // bind too many arguments - should throw.
86+ EXPECT_THROW (SQLite::bind (query, std::make_tuple (3 , " three" , 0 )), SQLite::Exception);
87+ EXPECT_EQ (1 , query.exec ());
88+ }
89+ // make sure the content is as expected
90+ {
91+ SQLite::Statement query (db, std::string{" SELECT id, value FROM test2 ORDER BY id" });
92+ std::vector<std::pair<int , std::string> > results;
93+ while (query.executeStep ()) {
94+ const int id = query.getColumn (0 );
95+ std::string value = query.getColumn (1 );
96+ results.emplace_back ( id, std::move (value) );
97+ }
98+ EXPECT_EQ (std::size_t (3 ), results.size ());
99+
100+ EXPECT_EQ (std::make_pair (1 ,std::string{" " }), results.at (0 ));
101+ EXPECT_EQ (std::make_pair (2 ,std::string{" two" }), results.at (1 ));
102+ EXPECT_EQ (std::make_pair (3 ,std::string{" three" }), results.at (2 ));
103+ }
104+ #endif // c++14
70105}
71106#endif // c++11
0 commit comments