[Commits] 61177f7: MDEV-19275 Provide SQL service to plugins.
revision-id: 61177f75dc30403a5a6ced18ab069c1883952f5b (mariadb-10.4.4-15-g61177f7) parent(s): e4c5551964f398ebbe2b1b34fef028eff6f22fbe committer: Alexey Botchkov timestamp: 2019-04-22 11:36:37 +0400 message: MDEV-19275 Provide SQL service to plugins. Service SQL owerall design. The service_sql.h is not included in services.h, it's supposed to be included explicitly where the service is needed as it includes the mysql.h. --- include/mysql.h | 3 +- include/mysql/service_sql.h | 93 +++++++++++++++++++++++++++++++++++++++++++++ include/service_versions.h | 1 + libmysqld/libmysql.c | 5 --- libservices/CMakeLists.txt | 1 + libservices/sql_service.c | 19 +++++++++ sql-common/client.c | 17 +++++++++ sql/CMakeLists.txt | 1 + sql/service_sql.cc | 43 +++++++++++++++++++++ sql/sql_plugin_services.ic | 24 +++++++++++- 10 files changed, 199 insertions(+), 8 deletions(-) diff --git a/include/mysql.h b/include/mysql.h index 68b2e76..71c903e 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -193,7 +193,8 @@ enum mysql_option /* MariaDB options */ MYSQL_PROGRESS_CALLBACK=5999, MYSQL_OPT_NONBLOCK, - MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY + MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, + MYSQL_OPT_USE_LOCAL_CONNECTION }; /** diff --git a/include/mysql/service_sql.h b/include/mysql/service_sql.h new file mode 100644 index 0000000..587ed77 --- /dev/null +++ b/include/mysql/service_sql.h @@ -0,0 +1,93 @@ +/* Copyright (C) 2019 MariaDB Corporation + + 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 Street, Fifth Floor, Boston, MA 02111-1301 USA */ + +//#if (!defined (MYSQL_SERVICE_SQL) && defined (_mysql_h)) +#ifndef MYSQL_SERVICE_SQL +#define MYSQL_SERVICE_SQL + +#include "../mysql.h" + +/** + @file + sql service + + Provides interface for plugins to execute SQL queries. + +*/ + +#ifdef __cplusplus +extern "C" { +#endif + + +/* + TODO 5313 - decide if we should uncomment this istead of + the 'include "../mysql.h"' +typedef struct st_mysql MYSQL; +typedef struct st_mysql_res MYSQL_RES; +typedef char **MYSQL_ROW; +*/ + +extern struct sql_service_st { + MYSQL *(*init)(MYSQL *mysql); + MYSQL *(*real_connect)(MYSQL *mysql,const char *host, const char *user, + const char *passwd, const char *db, + uint port, const char *unix_socket,ulong client_flag); + int (*options)(MYSQL *mysql, enum mysql_option option, const void *arg); + void (*close)(MYSQL *mysql); + int (*real_query)(MYSQL *mysql, const char *q, + unsigned long length); + my_ulonglong (*affected_rows)(MYSQL *mysql); + unsigned int (*merrno)(MYSQL *mysql); + const char *(*error)(MYSQL *mysql); + MYSQL_RES *(*store_result)(MYSQL *mysql); + void (*free_result)(MYSQL_RES *result); + my_ulonglong (*num_rows)(MYSQL_RES *res); + unsigned int (*num_fields)(MYSQL_RES *res); + MYSQL_ROW (*fetch_row)(MYSQL_RES *result); + unsigned long * (*fetch_lengths)(MYSQL_RES *result); +} *sql_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define mysql_init sql_service->init +#define mysql_real_connect sql_service->real_connect +#define mysql_local_connect sql_service->local_connect +#define mysql_close sql_service->close +#define mysql_real_query sql_service->real_query +#define mysql_affected_rows sql_service->affected_rows +#define mysql_warning_count sql_service->warning_count +#define mysql_errno sql_service->errno +#define mysql_sqlstate sql_service->sqlstate +#define mysql_error sql_service->error +#define mysql_store_result sql_service->store_result +#define mysql_free_result sql_service->free_result +#define mysql_num_rows sql_service->num_rows +#define mysql_num_fields sql_service->num_fields +#define mysql_fetch_field sql_service->fetch_field +#define mysql_field_seek sql_service->field_seek +#define mysql_fetch_row sql_service->fetch_row +#define mysql_fetch_lengths sql_service->fetch_lengths + +#endif /*MYSQL_DYNAMIC_PLUGIN*/ + + +#ifdef __cplusplus +} +#endif + +#endif /* MYSQL_SERVICE_SQL */ + + diff --git a/include/service_versions.h b/include/service_versions.h index 050012d..4cb4725 100644 --- a/include/service_versions.h +++ b/include/service_versions.h @@ -43,3 +43,4 @@ #define VERSION_thd_wait 0x0100 #define VERSION_wsrep 0x0202 #define VERSION_json 0x0100 +#define VERSION_sql 0x0100 diff --git a/libmysqld/libmysql.c b/libmysqld/libmysql.c index cd170b4..9c826a4 100644 --- a/libmysqld/libmysql.c +++ b/libmysqld/libmysql.c @@ -1062,11 +1062,6 @@ unsigned int STDCALL mysql_field_count(MYSQL *mysql) return mysql->field_count; } -my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql) -{ - return mysql->affected_rows; -} - my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql) { return mysql->insert_id; diff --git a/libservices/CMakeLists.txt b/libservices/CMakeLists.txt index b99be71..0120648 100644 --- a/libservices/CMakeLists.txt +++ b/libservices/CMakeLists.txt @@ -38,6 +38,7 @@ SET(MYSQLSERVICES_SOURCES thd_wait_service.c wsrep_service.c json_service.c + sql_service.c ) ADD_CONVENIENCE_LIBRARY(mysqlservices ${MYSQLSERVICES_SOURCES}) diff --git a/libservices/sql_service.c b/libservices/sql_service.c new file mode 100644 index 0000000..39a9d0a --- /dev/null +++ b/libservices/sql_service.c @@ -0,0 +1,19 @@ + +/* Copyright (c) 2019, Monty Program Ab + + 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 <service_versions.h> +SERVICE_VERSION sql_service= (void*)VERSION_sql; diff --git a/sql-common/client.c b/sql-common/client.c index c66cb1a..ace5630 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -2844,6 +2844,11 @@ set_connect_attributes(MYSQL *mysql, char *buff, size_t buf_len) } +#ifdef MYSQL_SERVER +extern MYSQL * STDCALL do_local_connect(MYSQL *mysql); +#endif /*MYSQL_SERVER*/ + + MYSQL * STDCALL CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, const char *passwd, const char *db, @@ -2875,6 +2880,10 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, set_mysql_error(mysql, CR_ALREADY_CONNECTED, unknown_sqlstate); DBUG_RETURN(0); } +#ifdef MYSQL_SERVER + if (mysql->options.methods_to_use == MYSQL_OPT_USE_LOCAL_CONNECTION) + DBUG_RETURN(do_local_connect(mysql)); +#endif mysql->methods= &client_methods; mysql->client_flag=0; /* For handshake */ @@ -3907,6 +3916,11 @@ static MYSQL_RES * cli_use_result(MYSQL *mysql) } +my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql) +{ + return mysql->affected_rows; +} + /************************************************************************** Return next row of the query results **************************************************************************/ @@ -4038,6 +4052,9 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) break; case MYSQL_OPT_USE_REMOTE_CONNECTION: case MYSQL_OPT_USE_EMBEDDED_CONNECTION: +#ifdef MYSQL_SERVER + case MYSQL_OPT_USE_LOCAL_CONNECTION: +#endif /*MYSQL_SERVER*/ case MYSQL_OPT_GUESS_CONNECTION: mysql->options.methods_to_use= option; break; diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index ecca723..6a405c7 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -144,6 +144,7 @@ SET (SQL_SOURCE ${WSREP_SOURCES} table_cache.cc encryption.cc temporary_tables.cc proxy_protocol.cc backup.cc + service_sql.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_builtin.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.cc diff --git a/sql/service_sql.cc b/sql/service_sql.cc new file mode 100644 index 0000000..36f65b7 --- /dev/null +++ b/sql/service_sql.cc @@ -0,0 +1,43 @@ +/* Copyright 2018 Codership Oy <info@codership.com> + + 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 "mariadb.h" +#include "sql_prepare.h" +#include <sql_common.h> +#include <mysql.h> + +extern "C" +{ + +static MYSQL_METHODS connect_local_methods= +{ + NULL,//loc_read_query_result, + NULL,//loc_advanced_command, + NULL,//loc_read_rows, + NULL,//loc_use_result, + NULL,//loc_fetch_lengths, + NULL,//loc_flush_use_result, + NULL //loc_read_change_user_result +}; + + +MYSQL * STDCALL do_local_connect(MYSQL *mysql) +{ + mysql->methods= &connect_local_methods; + return 0; +} + + +} /* extern "C" */ + diff --git a/sql/sql_plugin_services.ic b/sql/sql_plugin_services.ic index 955b9a0..9e7a5b9 100644 --- a/sql/sql_plugin_services.ic +++ b/sql/sql_plugin_services.ic @@ -17,6 +17,7 @@ /* support for Services */ #include <service_versions.h> #include <mysql/service_wsrep.h> +#include <mysql/service_sql.h> struct st_service_ref { const char *name; @@ -208,7 +209,7 @@ static struct my_print_error_service_st my_print_error_handler= my_printv_error }; -struct json_service_st json_handler= +static struct json_service_st json_handler= { json_type, json_get_array_item, @@ -218,6 +219,24 @@ struct json_service_st json_handler= json_unescape_json }; +static struct sql_service_st sql_handler= +{ + mysql_init, + mysql_real_connect, + mysql_options, + mysql_close, + mysql_real_query, + mysql_affected_rows, + mysql_errno, + mysql_error, + mysql_store_result, + mysql_free_result, + mysql_num_rows, + mysql_num_fields, + mysql_fetch_row, + mysql_fetch_lengths +}; + static struct st_service_ref list_of_services[]= { { "base64_service", VERSION_base64, &base64_handler }, @@ -241,6 +260,7 @@ static struct st_service_ref list_of_services[]= { "thd_timezone_service", VERSION_thd_timezone, &thd_timezone_handler }, { "thd_wait_service", VERSION_thd_wait, &thd_wait_handler }, { "wsrep_service", VERSION_wsrep, &wsrep_handler }, - { "json_service", VERSION_json, &json_handler } + { "json_service", VERSION_json, &json_handler }, + { "sql_service", VERSION_sql, &sql_handler } };
participants (1)
-
holyfoot@askmonty.org