Adam Nielsen wrote:
> Well for one, I don't have any control over the source system. I'm
> not designing my own database like this, I have to read data from
> somebody else's system with very wide tables.
It looks like you're stuck with having to hand roll the SQL. mysql++
can soften the blow though - you can pass a functor to Query::for_each
(or store_if) to handle SELECT into an object. Define a constructor
that takes a mysqlpp::Row& for your object. Something like what follows
at the bottom of this mail. Note you don't even need to store the
records, you could just process them in the functor.
For INSERT I guess you'll just have to add an insert function to the
Book object and write the INSERT statement yourself.
Good luck!
class Book
{
public:
Book(const mysqlpp::Row& row)
: m_title(row["title"].data(),row["title"].length())
{
}
private:
std::string m_title;
};
struct collect_books
{
void operator(const mysqlpp::Row& row)
{
m_books.push_back(Book(row));
}
std::vector<Book> m_books;
};
mysqlpp::Connection connection(blah);
mysqlpp::Query query = connection.query();
query << "SELECT * FROM `books`";
std::vector<Book> books;
collect_books b = query.for_each(collect_books(books));