title: Soci: Create Custom class to store results
body: <p>I use <a href="http://soci.sourceforge.net" rel="nofollow">Soci</a> to make database queries. Now I need to have a custom resultset class that will wrap around soci::rowset. I cannot get it work in the way my code are below simply because copy constructor is private in soci (not supported according to source file). How can I accomplish having wrapper with list of soci::rows (hereby typedef-ed to Row) without complicated code? Any design or direction on how to go about is appreciated</p>
  
  <p><strong>my header file</strong></p>
  
  <pre><code>typedef soci::row Row; 
  
  
  class ResultSet
  {
  public:
      ResultSet();
      ~ResultSet();
      void Copy(soci::rowset&lt;soci::row&gt;&amp; rs);
  
      Row GetNextRow();
      bool HasRows();
  
  private:
      soci::rowset&lt;soci::row&gt; m_rows;
      soci::rowset_iterator&lt;soci::row&gt; m_iterator;
      bool m_isAccessed;//if first access on row is done
  };
  </code></pre>
  
  <p><strong>source file</strong></p>
  
  <pre><code>ResultSet::ResultSet() {
      m_isAccessed=false;
  }
  
  ResultSet::~ResultSet() {
  
  }
  
  Row ResultSet::GetNextRow() {
      if(m_isAccessed) {
          m_iterator++;//increment row
          m_isAccessed=true;
      }
      return *m_iterator;
  }
  
  bool ResultSet::HasRows() {
      return m_iterator!=m_rows.end();//it have not reached the end yet;
  }
  
  void ResultSet::Copy(soci::rowset&lt;soci::row&gt;&amp; rs) {
      m_rows = rs;
      m_iterator = rs.begin();//put it at row 1
  }
  </code></pre>
  
  <p>and here is how I use in ExecuteQuery function of connection. m_session is soci::session</p>
  
  <pre><code>void ConnectionMgr::ExecuteQuery(wxString&amp; sql, ResultSet&amp; rs) {
      try { 
          soci::rowset&lt;soci::row&gt; rsInternal = m_session.prepare&lt;&lt;sql.ToStdString();
          rs.Copy(rsInternal); 
      }
      catch (std::exception const&amp; e) {
          m_error = wxString::Format(wxT("SqlQuery close error:%s\n"), e.what());
      }
  }
  </code></pre>
  
  <p>example of how I want to use the class later</p>
  
  <pre><code>wxString sql = wxT("-- a query\n SHOW DATABASES;"); 
                  ResultSet rs;
                  m_conn-&gt;ExecuteQuery(sql, rs);
                  while(rs.HasRows())
                  {
                      wxString name = wxString(rs.GetNextRow().get&lt;std::string&gt;(0));
                      //work with name here
                  }
  </code></pre>