[Maria-developers] Executing query inside mysql server
![](https://secure.gravatar.com/avatar/be3ec03063ff111a3c3ec45f6f3ec5db.jpg?s=120&d=mm&r=g)
Hi, I wonder what is the simplest way to execute SQL query inside server? In PostgreSQL there is SPI API, SQLite allows to use client API,... but I failed to find right way of running queries inside mySQL server. My task is the following: I want to patch mySQL server by redirecting execution of some queries to some external executor. The text of this queries will be stored inside database in some special table. So when some query is executed by mySQL server, I want to perform lookup in this table. What is the simplest way to do it in mySQL?
![](https://secure.gravatar.com/avatar/39b623a1559cf9c69ac3d9d4fb44e7fe.jpg?s=120&d=mm&r=g)
Hi, knizhnik! On Jun 17, knizhnik wrote:
Hi,
I wonder what is the simplest way to execute SQL query inside server? In PostgreSQL there is SPI API, SQLite allows to use client API,... but I failed to find right way of running queries inside mySQL server.
There is no API for that at the moment.
My task is the following: I want to patch mySQL server by redirecting execution of some queries to some external executor. The text of this queries will be stored inside database in some special table. So when some query is executed by mySQL server, I want to perform lookup in this table. What is the simplest way to do it in mySQL?
There are many examples for that in the code, but they all use low-level API. The typical sequence for your use case is: prepare a TABLE_LIST structure open_and_lock_tables() ha_index_read_idx_map() read values using Field methods Something alike is done in sql_acl.cc (loading privileges), in sql_help.cc, sp.cc (stored routines), event_db_repository.cc, sql_plugin.cc, sql_udf.cc, tztime.cc (time zones), etc. Regards, Sergei Chief Architect MariaDB and security@mariadb.org
participants (2)
-
knizhnik
-
Sergei Golubchik