MySQL Forums
Forum List  »  Source, Builds, Binaries

Re: Preparse Query Rewrite Plugin DLL
Posted by: Francois Haddad
Date: August 12, 2016 05:13PM

Thank you. It has been a long time since I checked this forum. Moved off this project temporarily but now I'm back.
I still can't seem to get it to work. I will put the steps I've used this far in hopes someone can help.



***Step 1: MS Visual Studio 2013 (I can switch to 2010 and 2012 if needed)

***Step 2: Mine is a Windows 7 PC (64 bit)

***Step 3: Created new DLL project called MySQLQueryPreParserDLL.
--> .Net Framework 3.0
--> Win32 Console Application
--> Application Type: DLL
--> Removed "Security Dev Lifecycle (SDL) checks

***Step 4: I set [Project Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories] to "C:\Program Files\MySQL\MySQL Server 5.7\include".

***Step 5: I pasted this code in MySQLQueryPreParserDLL.cpp...

// MySQLQueryPreParser4.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"


/* Copyright (c) 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 */

#include <ctype.h>
#include <string.h>

#include <my_global.h>
#include <mysql/plugin.h>
#include <mysql/plugin_audit.h>
#include <mysql/service_mysql_alloc.h>
#include <my_thread.h> // my_thread_handle needed by mysql_memory.h
#include <mysql/psi/mysql_memory.h>

/* instrument the memory allocation */
#ifdef HAVE_PSI_INTERFACE
static PSI_memory_key key_memory_rewrite_example;

static PSI_memory_info all_rewrite_memory[] =
{
{ &key_memory_rewrite_example, "rewrite_example", 0 }
};

static int plugin_init(MYSQL_PLUGIN)
{
const char* category = "sql";
int count;

count = array_elements(all_rewrite_memory);
mysql_memory_register(category, all_rewrite_memory, count);
return 0; /* success */
}
#else
#define plugin_init NULL
#define key_memory_rewrite_example PSI_NOT_INSTRUMENTED
#endif /* HAVE_PSI_INTERFACE */


static int rewrite_lower(MYSQL_THD thd, mysql_event_class_t event_class,
const void *event)
{
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_PREPARSE)
{

// I REMOVED A PART FROM HERE BECAUSE IT DOESN'T COMPILE,
// SO I ADDED THIS PART BECAUSE IT'S SIMPLE AND COMPILES.

size_t query_length = event_parse->query.length;
char *rewritten_query = (char *)malloc(sizeof(char) * 2048);
unsigned int i;

for (i = 0; i < query_length + 1; i++)
{
rewritten_query = toupper(event_parse->query.str);
}

// BACK TO THE CODE I GOT FROM ONLINE

event_parse->rewritten_query->str = rewritten_query;
event_parse->rewritten_query->length = query_length;
*((int *)event_parse->flags) |= (int)MYSQL_AUDIT_PARSE_REWRITE_PLUGIN_QUERY_REWRITTEN;

}
}

return 0;
}

/* Audit plugin descriptor */
static struct st_mysql_audit rewrite_example_descriptor =
{
MYSQL_AUDIT_INTERFACE_VERSION, /* interface version */
NULL, /* release_thd() */
rewrite_lower, /* event_notify() */
{ 0,
0,
(unsigned long)MYSQL_AUDIT_PARSE_ALL, } /* class mask */
};

/* Plugin descriptor */
mysql_declare_plugin(audit_log)
{
MYSQL_AUDIT_PLUGIN, /* plugin type */
&rewrite_example_descriptor, /* type specific descriptor */
"rewrite_example", /* plugin name */
"CompanyName", /* author */
"An example of a query rewrite"
" plugin that rewrites all queries"
" to upper case", /* description */
PLUGIN_LICENSE_GPL, /* license */
plugin_init, /* plugin initializer */
NULL, /* plugin deinitializer */
0x0002, /* version */
NULL, /* status variables */
NULL, /* system variables */
NULL, /* reserverd */
0 /* flags */
}
mysql_declare_plugin_end;



***Step 6: I get the error [LNK2001: unresolved external symbol _PSI_server].

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Preparse Query Rewrite Plugin DLL
353
August 12, 2016 05:13PM


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.