/* 
 * © 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.
 */
#ifndef _DB_SQL_EDITOR_H_
#define _DB_SQL_EDITOR_H_


#include "wbpublic_public_interface.h"
#include "grt/grt_manager.h"
#include "cppdbc.h"
#include "sqlide/sql_editor_be.h"
#include "grts/structs.workbench.h"
#include "grts/structs.db.mgmt.h"


class Recordset;


class WBPUBLICBACKEND_PUBLIC_FUNC Db_sql_editor
{
public:
  Db_sql_editor(bec::GRTManager *grtm);
  virtual ~Db_sql_editor();

  db_mgmt_ConnectionRef stored_connection();
  void stored_connection(db_mgmt_ConnectionRef val);
  db_mgmt_RdbmsRef rdbms();
  Sql_editor * sql_editor();

  void reset();
  void exec_sql(const std::string &sql);
  int recordset_count();
  Recordset * recordset(int index);

private:
  void connect();

private:
  bec::GRTManager *_grtm;
  db_mgmt_ConnectionRef _stored_connection;
  std::auto_ptr<Sql_editor> _sql_editor;
  std::auto_ptr<sql::Connection> _dbc_conn;
  std::vector<Recordset*> _recordsets;
};


#endif /* _DB_SQL_EDITOR_H_ */
