You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
proxysql/include/query_processor.h

126 lines
4.2 KiB

#ifndef __CLASS_QUERY_PROCESSOR_H
#define __CLASS_QUERY_PROCESSOR_H
#include "proxysql.h"
#include "cpp.h"
enum MYSQL_COM_QUERY_command {
MYSQL_COM_QUERY_ALTER_TABLE,
MYSQL_COM_QUERY_ANALYZE,
MYSQL_COM_QUERY_BEGIN,
MYSQL_COM_QUERY_CHANGE_MASTER,
MYSQL_COM_QUERY_CREATE_DATABASE,
MYSQL_COM_QUERY_CREATE_INDEX,
MYSQL_COM_QUERY_CREATE_TABLE,
MYSQL_COM_QUERY_CREATE_TEMPORARY,
MYSQL_COM_QUERY_CREATE_TRIGGER,
MYSQL_COM_QUERY_CREATE_USER,
MYSQL_COM_QUERY_DELETE,
MYSQL_COM_QUERY_DESCRIBE,
MYSQL_COM_QUERY_DROP_DATABASE,
MYSQL_COM_QUERY_DROP_INDEX,
MYSQL_COM_QUERY_DROP_TABLE,
MYSQL_COM_QUERY_DROP_TRIGGER,
MYSQL_COM_QUERY_DROP_USER,
MYSQL_COM_QUERY_GRANT,
MYSQL_COM_QUERY_EXPLAIN,
MYSQL_COM_QUERY_FLUSH,
MYSQL_COM_QUERY_INSERT,
MYSQL_COM_QUERY_KILL,
MYSQL_COM_QUERY_LOAD,
MYSQL_COM_QUERY_LOCK_TABLE,
MYSQL_COM_QUERY_OPTIMIZE,
MYSQL_COM_QUERY_PREPARE,
MYSQL_COM_QUERY_PURGE,
MYSQL_COM_QUERY_RENAME_TABLE,
MYSQL_COM_QUERY_RESET_MASTER,
MYSQL_COM_QUERY_RESET_SLAVE,
MYSQL_COM_QUERY_REPLACE,
MYSQL_COM_QUERY_REVOKE,
MYSQL_COM_QUERY_ROLLBACK,
MYSQL_COM_QUERY_SAVEPOINT,
MYSQL_COM_QUERY_SELECT,
MYSQL_COM_QUERY_SELECT_FOR_UPDATE,
MYSQL_COM_QUERY_SET,
MYSQL_COM_QUERY_START_TRANSACTION,
MYSQL_COM_QUERY_UNLOCK_TABLES,
MYSQL_COM_QUERY_UPDATE,
MYSQL_COM_QUERY_USE,
MYSQL_COM_QUERY_SHOW,
MYSQL_COM_QUERY___UNKNOWN
};
struct _Query_Processor_rule_t {
int rule_id;
bool active;
char *username;
char *schemaname;
int flagIN;
char *match_pattern;
bool negate_match_pattern;
int flagOUT;
char *replace_pattern;
int destination_hostgroup;
int cache_ttl;
bool apply;
void *regex_engine;
int hits;
struct _Query_Processor_rule_t *parent; // pointer to parent, to speed up parent update
};
struct _Query_Processor_output_t {
void *ptr;
unsigned int size;
int destination_hostgroup;
int cache_ttl;
std::string *new_query;
};
typedef struct _Query_Processor_rule_t QP_rule_t;
typedef struct _Query_Processor_output_t QP_out_t;
class Query_Processor {
protected:
rwlock_t rwlock;
public:
Query_Processor() {};
virtual ~Query_Processor() {};
virtual const char *version() {return NULL;};
virtual void print_version() {};
virtual void reset_all(bool lock=true) {};
virtual void wrlock() {}; // explicit write lock, to be used in multi-isert
virtual void wrunlock() {}; // explicit write unlock
virtual bool insert(QP_rule_t *qr, bool lock=true) {return false;}; // insert a new rule. Uses a generic void pointer to a structure that may vary depending from the Query Processor
// virtual bool insert_locked(QP_rule_t *qr) {return false;}; // call this instead of insert() in case lock was already acquired via wrlock()
virtual QP_rule_t * new_query_rule(int rule_id, bool active, char *username, char *schemaname, int flagIN, char *match_pattern, bool negate_match_pattern, int flagOUT, char *replace_pattern, int destination_hostgroup, int cache_ttl, bool apply) {return NULL;}; // to use a generic query rule struct, this is generated by this function and returned as generic void pointer
virtual void delete_query_rule(QP_rule_t *qr) {}; // destructor
virtual bool remove(int rule_id, bool lock=true) {return false;};
// virtual bool remove_locked(int rule_id) {return false;}; // call this instead of remove() in case lock was already acquired via wrlock()
virtual QP_out_t * process_mysql_query(MySQL_Session *sess, void *ptr, unsigned int size, bool delete_original) {return NULL;};
virtual void delete_QP_out(QP_out_t *o) {};
virtual void sort(bool lock=true) {};
virtual void init_thread() {};
virtual void end_thread() {};
virtual void commit() {}; // this applies all the changes in memory
virtual SQLite3_result * get_current_query_rules() {return NULL;};
virtual SQLite3_result * get_stats_query_rules() {return NULL;};
virtual void update_query_processor_stats() {};
virtual void * query_parser_init(char *query, int query_length, int flags) {return NULL;};
virtual enum MYSQL_COM_QUERY_command query_parser_command_type(void *args) {return MYSQL_COM_QUERY___UNKNOWN;}
virtual char * query_parser_first_comment(void *args) { return NULL; }
virtual void query_parser_free(void *args) {};
};
typedef Query_Processor * create_Query_Processor_t();
#endif /* __CLASS_QUERY_PROCESSOR_H */