MySQL Forums
Forum List  »  Optimizer & Parser

Plugin For Obtaining Tokenized Query
Posted by: JustADude Tester
Date: October 19, 2022 08:23AM

Dear Community,
I need for a private project to get from the mysql database any query, that is processed, in a tokenized form.

Example:
Select * from users where 1 = 1;
Desired Output:
["Select", "*", "from", "users", "where", "1", "=", "1"]


I started developing a PoC by implementing a simple query rewrite plugin. Currently I want to call the 'get_command' method of a MYSQL_THD object. However,
every time I try to compile my plugin it gives me the following error

'error: invalid use of incomplete type ‘class THD’'

I have included the following files in my plugin:
#include <my_global.h>
#include <mysql/plugin.h>
#include <mysql/plugin_audit.h>
#include <mysql/service_mysql_alloc.h>
#include <mysql/services.h>
#include <mysql/service_parser.h>
#include <mysql/mysql_lex_string.h>
#include <sql_class.h>

The following snippet is my code:

if (event_class == MYSQL_AUDIT_PARSE_CLASS)
{
const struct mysql_event_parse *event_parse=
static_cast<const struct mysql_event_parse *>(event);

if (event_parse->event_subclass == MYSQL_AUDIT_PARSE_POSTPARSE)
{
thd->get_command();
}
}

However, it still wont compile. What header file am I missing or better question why can't I access any variable or method of the MYSQL_THD object.

I hope this is the right place for this question and hope that you guys can help me :)

Options: ReplyQuote


Subject
Views
Written By
Posted
Plugin For Obtaining Tokenized Query
256
October 19, 2022 08:23AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.