List:MySQL++« Previous MessageNext Message »
From:Joel Fielder Date:January 29 2010 8:45am
Subject:Re: How to do a large template query?
View as plain text  
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));
Thread
How to do a large template query?Adam Nielsen27 Jan
  • Re: How to do a large template query?Warren Young27 Jan
    • Re: How to do a large template query?Adam Nielsen28 Jan
      • Re: How to do a large template query?Joel Fielder28 Jan
        • Re: How to do a large template query?Warren Young28 Jan
          • Re: How to do a large template query?Adam Nielsen29 Jan
            • Re: How to do a large template query?Joel Fielder29 Jan
              • Re: How to do a large template query?Joel Fielder29 Jan
              • Re: How to do a large template query?Adam Nielsen1 Feb
            • Re: How to do a large template query?Warren Young29 Jan
              • Re: How to do a large template query?Adam Nielsen1 Feb
                • Re: How to do a large template query?Warren Young1 Feb
                  • Re: How to do a large template query?Warren Young7 Feb
          • Re: How to do a large template query?Warren Young7 Feb