mirror of
https://github.com/allankoechke/SQLiteCpp.git
synced 2026-12-02 17:11:59 +00:00
Add VariadicBind.h from PR #85 to CMake for Visual Studio
+ fix style issues (cpplint)
This commit is contained in:
@@ -82,35 +82,6 @@ private:
|
||||
SQLite::Statement mQuery; ///< Database prepared SQL query
|
||||
};
|
||||
|
||||
void demonstrateVariadicBind() {
|
||||
#if ( __cplusplus>= 201402L) || ( defined(_MSC_VER) && (_MSC_VER >= 1900) )
|
||||
// Open a database file in create/write mode
|
||||
SQLite::Database db(":memory:", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
|
||||
|
||||
db.exec("DROP TABLE IF EXISTS test");
|
||||
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)");
|
||||
|
||||
{
|
||||
SQLite::Statement query(db, "INSERT INTO test VALUES (?, ?)");
|
||||
|
||||
SQLite::bind(query, 42, "fortytwo");
|
||||
// Execute the one-step query to insert the blob
|
||||
int nb = query.exec();
|
||||
std::cout << "INSERT INTO test VALUES (NULL, ?)\", returned " << nb
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
SQLite::Statement query(db, "SELECT * FROM test");
|
||||
std::cout << "SELECT * FROM test :\n";
|
||||
if (query.executeStep()) {
|
||||
std::cout << query.getColumn(0).getInt() << "\t\""
|
||||
<< query.getColumn(1).getText() << "\"\n";
|
||||
}
|
||||
#else
|
||||
throw std::runtime_error("demonstrateVariadicBind(): sorry, no c++14 support in this build.");
|
||||
#endif
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
std::cout << "SQlite3 version " << SQLITE_VERSION << std::endl;
|
||||
@@ -452,14 +423,37 @@ int main ()
|
||||
}
|
||||
remove("out.png");
|
||||
|
||||
//example with variadic bind (requires c++14)
|
||||
#if ( __cplusplus>= 201402L) || ( defined(_MSC_VER) && (_MSC_VER >= 1900) )
|
||||
try {
|
||||
demonstrateVariadicBind();
|
||||
} catch (std::exception& e) {
|
||||
std::cout << "SQLite exception: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE; // unexpected error : exit the example program
|
||||
}
|
||||
#if (__cplusplus >= 201402L) || ( defined(_MSC_VER) && (_MSC_VER >= 1900) ) // c++14: Visual Studio 2015
|
||||
// example with C++14 variadic bind
|
||||
try
|
||||
{
|
||||
// Open a database file in create/write mode
|
||||
SQLite::Database db(":memory:", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
|
||||
|
||||
db.exec("DROP TABLE IF EXISTS test");
|
||||
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)");
|
||||
|
||||
{
|
||||
SQLite::Statement query(db, "INSERT INTO test VALUES (?, ?)");
|
||||
|
||||
SQLite::bind(query, 42, "fortytwo");
|
||||
// Execute the one-step query to insert the blob
|
||||
int nb = query.exec();
|
||||
std::cout << "INSERT INTO test VALUES (NULL, ?)\", returned " << nb << std::endl;
|
||||
}
|
||||
|
||||
SQLite::Statement query(db, "SELECT * FROM test");
|
||||
std::cout << "SELECT * FROM test :\n";
|
||||
if (query.executeStep())
|
||||
{
|
||||
std::cout << query.getColumn(0).getInt() << "\t\"" << query.getColumn(1).getText() << "\"\n";
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cout << "SQLite exception: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE; // unexpected error : exit the example program
|
||||
}
|
||||
#endif
|
||||
|
||||
std::cout << "everything ok, quitting\n";
|
||||
|
||||
Reference in New Issue
Block a user