/* 
 * © 2007-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#include "stdafx.h"

#include "recordset_cdbc_storage_be.h"
#include "recordset_be.h"


using namespace bec;
using namespace grt;


Recordset_cdbc_storage::Recordset_cdbc_storage(GRTManager *grtm)
:
Recordset_data_storage(grtm),
_dbc_rs(NULL)
{
}


Recordset_cdbc_storage::~Recordset_cdbc_storage()
{
}


void Recordset_cdbc_storage::serialize(Recordset *rs)
{
}


void Recordset_cdbc_storage::unserialize(std::vector<std::string> &field_names, std::vector<std::string> &rs)
{
  if (_dbc_rs)
  {
    sql::ResultSetMetaData *dbc_rs_meta(_dbc_rs->getMetaData());
    unsigned col_count= dbc_rs_meta->getColumnCount();

    field_names.reserve(col_count);
    for (unsigned n= 0; n < col_count; ++n)
      field_names.push_back(dbc_rs_meta->getColumnLabel(n+1));

    rs.reserve(_dbc_rs->rowsCount() * col_count);
    while (_dbc_rs->next())
      for (size_t n= 0, count= col_count; n < count; ++n)
        rs.push_back(_dbc_rs->getString(n+1));
  }
}
