/* 
 * © 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 _SQL_EDITOR_H_
#define _SQL_EDITOR_H_


#include <memory>
#include "wbpublic_public_interface.h"
#include "grtsqlparser/sql_semantic_check.h"
#include "grts/structs.db.mgmt.h"
#include "grt/grt_manager.h"
//!#include "interfaces/plugin.h"


#define Sql_VERSION "1.0"


class WBPUBLICBACKEND_PUBLIC_FUNC Sql_editor
{
public:
  static std::auto_ptr<Sql_editor> create_sql_editor(db_mgmt_RdbmsRef rdbms);

public:
  Sql_editor(db_mgmt_RdbmsRef rdbms);
  virtual ~Sql_editor();

  enum KeywordList {General_Keywords, Procedure_Keywords, Client_Keywords, User_Keywords};
  virtual const char *get_keywords(KeywordList list= General_Keywords) const { return NULL; };
  virtual const char *get_function_names() const { return NULL; };
  
  db_mgmt_RdbmsRef rdbms() { return _rdbms; }

  std::string sql() { return _sql; }
  void sql(const std::string &sql) { _sql= sql; }
  Sql_semantic_check * sql_checker() { return _sql_checker.get(); }
  typedef Sql_parser_base::Parse_error_cb Sql_parser_err_cb;
  void sql_parser_err_cb(Sql_parser_err_cb cb);
  void check_sql();

  int int_option(std::string name);
  std::string string_option(std::string name);

protected:
  db_mgmt_RdbmsRef _rdbms;
  grt::DictRef _options;
  std::string _sql;
  std::auto_ptr<Sql_semantic_check> _sql_checker;
  Sql_parser_err_cb _sql_parser_err_cb;
};

#ifdef _WIN32
#pragma make_public(Sql_editor)
#endif

class WBPUBLICBACKEND_PUBLIC_FUNC Sql
{
public:
  virtual std::auto_ptr<Sql_editor> getSqlEditor(db_mgmt_RdbmsRef rdbms)= 0;
  virtual ~Sql() {}
};


#endif /* _SQL_EDITOR_H_ */
