Skip to content

Instantly share code, notes, and snippets.

@redboltz
Last active August 29, 2015 14:03
Show Gist options
  • Save redboltz/073d33f4de19c319352e to your computer and use it in GitHub Desktop.
Save redboltz/073d33f4de19c319352e to your computer and use it in GitHub Desktop.
An example of sqlite access using SOCI
#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