Last active
August 29, 2015 14:03
-
-
Save redboltz/073d33f4de19c319352e to your computer and use it in GitHub Desktop.
An example of sqlite access using SOCI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <soci.h> | |
#include <sqlite3/soci-sqlite3.h> | |
#include <boost-fusion.h> | |
#include <iostream> | |
#include <boost/fusion/include/define_struct.hpp> | |
#include <boost/fusion/include/for_each.hpp> | |
using namespace soci; | |
using namespace std; | |
BOOST_FUSION_DEFINE_STRUCT( | |
(), user, | |
(int, user_id) | |
(std::string, name) | |
(std::string, email) | |
(std::string, password)) | |
int main() | |
{ | |
try { | |
session sql(sqlite3, "path_to_db_file/data.sqlite"); | |
user u; | |
sql << "select * from users", into(u); | |
boost::fusion::for_each(u, [](auto const& e) { std::cout << e << ' '; }); | |
std::cout << std::endl; | |
} | |
catch (exception const &e) { | |
cerr << "Error: " << e.what() << '\n'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment