File: mysql_parser_services.h

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (127 lines) | stat: -rw-r--r-- 5,459 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the
 * License.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301  USA 
 */

#pragma once

#include "wbpublic_public_interface.h"

#include "mysql-recognition-types.h"
#include "grtdb/db_helpers.h"

#ifndef HAVE_PRECOMPILED_HEADERS
 #include "grts/structs.db.mysql.h"
#endif

class MySQLRecognizer;
class MySQLSyntaxChecker;
class MySQLScanner;
class MySQLQueryIdentifier;

namespace parser {

  typedef struct
  {
    std::string message;
    size_t position;
    size_t line;
    size_t length;
  } ParserErrorEntry;

  class WBPUBLICBACKEND_PUBLIC_FUNC ParserContext {

  private:
    MySQLRecognizer *_recognizer;
    MySQLSyntaxChecker *_syntax_checker;

    GrtVersionRef _version;
    bool _case_sensitive;
    std::string _sql_mode;
    std::set<std::string> _filtered_charsets;

    void update_filtered_charsets(long version);
  public:
    typedef boost::shared_ptr<ParserContext> Ref;

    ParserContext(GrtCharacterSetsRef charsets, GrtVersionRef version, bool case_sensitive);
    ~ParserContext();

    MySQLRecognizer *recognizer() { return _recognizer; };
    MySQLSyntaxChecker *syntax_checker() { return _syntax_checker; };
    boost::shared_ptr<MySQLScanner> createScanner(const std::string &text); // The scanner uses the same version etc as the other recognizers.
    boost::shared_ptr<MySQLQueryIdentifier> createQueryIdentifier();

    void use_sql_mode(const std::string &mode);
    std::string get_sql_mode();

    void use_server_version(GrtVersionRef version);
    GrtVersionRef get_server_version() { return _version; };

    bool case_sensitive() { return _case_sensitive; };

    std::vector<ParserErrorEntry> get_errors_with_offset(size_t offset, bool for_syntax_check);

    uint32_t get_keyword_token(const std::string &keyword);
    char ** get_token_name_list();
  };

  /**
  * Defines an abstract interface for parser services. The actual implementation is done in a module
  * (and hence a singleton).
  */
  class WBPUBLICBACKEND_PUBLIC_FUNC MySQLParserServices
  {
  public:
    typedef MySQLParserServices *Ref; // We only have a singleton, so define Ref only to keep the pattern.

    static MySQLParserServices::Ref get(grt::GRT *grt);
    static ParserContext::Ref createParserContext(GrtCharacterSetsRef charsets, GrtVersionRef version,
      bool case_sensitive);

    virtual size_t stopProcessing() = 0;

    virtual size_t parseTable(parser::ParserContext::Ref context, db_mysql_TableRef table, const std::string &sql) = 0;
    virtual size_t parseRoutine(parser::ParserContext::Ref context, db_mysql_RoutineRef routine, const std::string &sql) = 0;
    virtual size_t parseRoutines(parser::ParserContext::Ref context, db_mysql_RoutineGroupRef group, const std::string &sql) = 0;
    virtual size_t parseTrigger(ParserContext::Ref context, db_mysql_TriggerRef trigger, const std::string &sql) = 0;
    virtual size_t parseView(parser::ParserContext::Ref context, db_mysql_ViewRef view, const std::string &sql) = 0;
    virtual size_t parseSchema(parser::ParserContext::Ref context, db_mysql_SchemaRef schema, const std::string &sql) = 0;
    virtual size_t parseIndex(parser::ParserContext::Ref context, db_mysql_IndexRef index, const std::string &sql) = 0;
    virtual size_t parseEvent(parser::ParserContext::Ref context, db_mysql_EventRef event, const std::string &sql) = 0;
    virtual size_t parseLogfileGroup(parser::ParserContext::Ref context, db_mysql_LogFileGroupRef group, const std::string &sql) = 0;
    virtual size_t parseServer(parser::ParserContext::Ref context, db_mysql_ServerLinkRef server, const std::string &sql) = 0;
    virtual size_t parseTablespace(parser::ParserContext::Ref context, db_mysql_TablespaceRef tablespace, const std::string &sql) = 0;

    virtual size_t parseSQLIntoCatalog(parser::ParserContext::Ref context, db_mysql_CatalogRef catalog,
      const std::string &sql, grt::DictRef options) = 0;

    virtual size_t checkSqlSyntax(ParserContext::Ref context, const char *sql, size_t length, MySQLQueryType type) = 0;
    virtual size_t renameSchemaReferences(parser::ParserContext::Ref context, db_mysql_CatalogRef catalog,
      const std::string old_name, const std::string new_name) = 0;

    virtual size_t determineStatementRanges(const char *sql, size_t length, const std::string &initial_delimiter,
      std::vector<std::pair<size_t, size_t> > &ranges, const std::string &line_break = "\n") = 0;

    virtual grt::DictRef parseStatement(ParserContext::Ref context, grt::GRT *grt, const std::string &sql) = 0;

    // Query manipulation services.
    virtual std::string replaceTokenSequenceWithText(parser::ParserContext::Ref context,
      const std::string &sql, size_t start_token, size_t count, const std::vector<std::string> replacements) = 0;
  };

} // namespace parser