#ifndef _MYSQL_SQL_FACADE_H_
#define _MYSQL_SQL_FACADE_H_


#include "mysql_sql_parser_public_interface.h"
#include "grtsqlparser/sql_facade.h"
#include "mysql_sql_parser_base.h"
#include "grts/structs.db.mysql.h"
#include "grtpp_module_cpp.h"


#define MysqlSqlFacade_VERSION "1.0"
 

/** Implements DBMS specifics.
 * 
 * @ingroup sqlparser
 */
class MYSQL_SQL_PARSER_PUBLIC_FUNC MysqlSqlFacade
  : public SqlFacade, public grt::ModuleImplBase
{
public:
  MysqlSqlFacade(grt::CPPModuleLoader *ldr) : grt::ModuleImplBase(ldr) {}

  DEFINE_INIT_MODULE(MysqlSqlFacade_VERSION, "MySQL AB", grt::ModuleImplBase,
    DECLARE_MODULE_FUNCTION(MysqlSqlFacade::getPluginInfo),
    NULL);
  virtual grt::ListRef<app_Plugin> getPluginInfo();

  int splitSqlScript(const std::string &sql, std::list<std::string> &statements);

  std::auto_ptr<Sql_parser> sqlParser();
  int parseSqlScriptString(db_CatalogRef catalog, const std::string sql);
  int parseSqlScriptStringEx(db_CatalogRef catalog, const std::string sql, const grt::DictRef options);
  int parseSqlScriptFile(db_CatalogRef catalog, const std::string filename);
  int parseSqlScriptFileEx(db_CatalogRef catalog, const std::string filename, const grt::DictRef options);

  std::auto_ptr<Invalid_sql_parser> invalidSqlParser();
  int parseInserts(db_TableRef table, const std::string sql);
  int parseTriggers(db_TableRef table, const std::string sql);
  int parseRoutine(db_RoutineRef routine, const std::string sql);
  int parseRoutines(db_RoutineGroupRef routineGroup, const std::string sql);
  int parseView(db_ViewRef view, const std::string sql);

  std::auto_ptr<Sql_syntax_check> sqlSyntaxCheck();
	int checkSqlSyntax(const std::string sql);
  int checkTriggerSyntax(const std::string sql);
  int checkViewSyntax(const std::string sql);
  int checkRoutineSyntax(const std::string sql);

  std::auto_ptr<Sql_semantic_check> sqlSemanticCheck();

  std::auto_ptr<Sql_normalizer> sqlNormalizer();
  std::string normalizeSqlStatement(const std::string sql, const std::string schema_name);

  std::auto_ptr<Sql_inserts_loader> sqlInsertsLoader();

  int renameSchemaReferences(db_CatalogRef catalog, const std::string old_schema_name, const std::string new_schema_name);

  std::auto_ptr<Sql_statement_decomposer> sqlStatementDecomposer();
};


#endif // _MYSQL_SQL_FACADE_H_
