#ifndef _MYSQL_INVALID_SQL_PARSER_H_
#define _MYSQL_INVALID_SQL_PARSER_H_


#include "mysql_sql_parser.h"
#include "grtsqlparser/invalid_sql_parser.h"


/** Implements DBMS specifics.
 * 
 * @ingroup sqlparser
 */
class Mysql_invalid_sql_parser
  : protected Mysql_sql_parser, public Invalid_sql_parser
{
public:
  Mysql_invalid_sql_parser(grt::GRT *grt);
  virtual ~Mysql_invalid_sql_parser() {}

  int parse_inserts(db_TableRef table, const std::string &sql);
  int parse_triggers(db_TableRef table, const std::string &sql);
  int parse_routines(db_RoutineGroupRef routine_group, const std::string &sql);
  int parse_routine(db_RoutineRef routine, const std::string &sql);
  int parse_view(db_ViewRef view, const std::string &sql);

protected:
  int parse_invalid_sql_script(const std::string &sql);
  int process_sql_statement(const MyxSQLTreeItem *tree);
  Parse_result process_create_trigger_statement(const MyxSQLTreeItem *tree) { return Mysql_sql_parser::process_create_trigger_statement(tree); }
  Parse_result process_create_routine_statement(const MyxSQLTreeItem *tree) { return Mysql_sql_parser::process_create_routine_statement(tree); }
  Parse_result process_create_view_statement(const MyxSQLTreeItem *tree) { return Mysql_sql_parser::process_create_view_statement(tree); }

  void create_stub_routine(db_DatabaseDdlObjectRef &obj);
  void create_stub_group_routine(db_DatabaseDdlObjectRef &obj);
  void remove_stub_group_routine(db_DatabaseDdlObjectRef &obj);
  void shape_group_routine(db_mysql_RoutineRef &obj);
  void create_stub_trigger(db_DatabaseDdlObjectRef &obj);
  void create_stub_view(db_DatabaseDdlObjectRef &obj);
  void shape_trigger(db_mysql_TriggerRef &obj);

  void setup_stub_obj(db_DatabaseDdlObjectRef obj, bool set_name);
  std::string stub_obj_name();

  virtual GrtNamedObjectRef get_active_object() { return _active_obj; };

  // data members
  typedef sigc::slot<void, db_DatabaseDdlObjectRef &> Proces_stub_object;
  Proces_stub_object _create_stub_object;
  Proces_stub_object _remove_stub_object;
  db_DatabaseObjectRef _active_grand_obj; // container for objects to parse
  db_DatabaseDdlObjectRef _active_obj; // object to parse
  grt::ListRef<db_DatabaseDdlObject> _active_obj_list; // default container of objects
  grt::ListRef<db_DatabaseDdlObject> _active_obj_list2; // container of objects (narrowed contatiner for objects being contained in 2 collections)
  std::string _stub_name;
  int _stub_num;
  int _next_group_routine_seqno;
  int _next_trigger_seqno;

  class Null_state_keeper : Mysql_sql_parser::Null_state_keeper
  {
  public:
    Null_state_keeper(Mysql_invalid_sql_parser *sql_parser)
      : Mysql_sql_parser::Null_state_keeper(sql_parser), _sql_parser(sql_parser) {}
    ~Null_state_keeper();
  private:
    Mysql_invalid_sql_parser *_sql_parser;
  };
};


#endif // _MYSQL_INVALID_SQL_PARSER_H_
