Skip to content

Commit 1fa196a

Browse files
author
Alexey Botchkov
committed
MDEV-27595 Backport SQL service, introduced by MDEV-19275.
The SQL SERVICE backported into the 10.4.
1 parent f0fe235 commit 1fa196a

30 files changed

+1781
-351
lines changed

include/mysql.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ typedef struct st_mysql_res {
331331
} MYSQL_RES;
332332

333333

334-
#if !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT)
334+
#if !defined(MYSQL_SERVICE_SQL) && !defined(MYSQL_CLIENT)
335335
#define MYSQL_CLIENT
336336
#endif
337337

@@ -363,7 +363,7 @@ typedef struct st_mysql_parameters
363363
*/
364364
#define MYSQL_WAIT_TIMEOUT 8
365365

366-
#if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY)
366+
#if !defined(MYSQL_SERVICE_SQL)
367367
#define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet)
368368
#define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length)
369369
#endif

include/mysql/plugin_audit.h.pp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,24 @@
419419
char *json, char *json_end);
420420
int json_unescape_json(const char *json_str, const char *json_end,
421421
char *res, char *res_end);
422+
extern struct sql_service_st {
423+
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
424+
MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
425+
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
426+
const char *user, const char *passwd, const char *db, unsigned int port,
427+
const char *unix_socket, unsigned long clientflag);
428+
unsigned int(STDCALL *mysql_errno_func)(MYSQL *mysql);
429+
const char *(STDCALL *mysql_error_func)(MYSQL *mysql);
430+
int (STDCALL *mysql_real_query_func)(MYSQL *mysql, const char *q,
431+
unsigned long length);
432+
my_ulonglong (STDCALL *mysql_affected_rows_func)(MYSQL *mysql);
433+
my_ulonglong (STDCALL *mysql_num_rows_func)(MYSQL_RES *res);
434+
MYSQL_RES *(STDCALL *mysql_store_result_func)(MYSQL *mysql);
435+
void (STDCALL *mysql_free_result_func)(MYSQL_RES *result);
436+
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
437+
void (STDCALL *mysql_close_func)(MYSQL *mysql);
438+
} *sql_service;
439+
MYSQL *mysql_real_connect_local(MYSQL *mysql);
422440
struct st_mysql_xid {
423441
long formatID;
424442
long gtrid_length;

include/mysql/plugin_auth.h.pp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,24 @@
419419
char *json, char *json_end);
420420
int json_unescape_json(const char *json_str, const char *json_end,
421421
char *res, char *res_end);
422+
extern struct sql_service_st {
423+
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
424+
MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
425+
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
426+
const char *user, const char *passwd, const char *db, unsigned int port,
427+
const char *unix_socket, unsigned long clientflag);
428+
unsigned int(STDCALL *mysql_errno_func)(MYSQL *mysql);
429+
const char *(STDCALL *mysql_error_func)(MYSQL *mysql);
430+
int (STDCALL *mysql_real_query_func)(MYSQL *mysql, const char *q,
431+
unsigned long length);
432+
my_ulonglong (STDCALL *mysql_affected_rows_func)(MYSQL *mysql);
433+
my_ulonglong (STDCALL *mysql_num_rows_func)(MYSQL_RES *res);
434+
MYSQL_RES *(STDCALL *mysql_store_result_func)(MYSQL *mysql);
435+
void (STDCALL *mysql_free_result_func)(MYSQL_RES *result);
436+
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
437+
void (STDCALL *mysql_close_func)(MYSQL *mysql);
438+
} *sql_service;
439+
MYSQL *mysql_real_connect_local(MYSQL *mysql);
422440
struct st_mysql_xid {
423441
long formatID;
424442
long gtrid_length;

include/mysql/plugin_encryption.h.pp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,24 @@
419419
char *json, char *json_end);
420420
int json_unescape_json(const char *json_str, const char *json_end,
421421
char *res, char *res_end);
422+
extern struct sql_service_st {
423+
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
424+
MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
425+
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
426+
const char *user, const char *passwd, const char *db, unsigned int port,
427+
const char *unix_socket, unsigned long clientflag);
428+
unsigned int(STDCALL *mysql_errno_func)(MYSQL *mysql);
429+
const char *(STDCALL *mysql_error_func)(MYSQL *mysql);
430+
int (STDCALL *mysql_real_query_func)(MYSQL *mysql, const char *q,
431+
unsigned long length);
432+
my_ulonglong (STDCALL *mysql_affected_rows_func)(MYSQL *mysql);
433+
my_ulonglong (STDCALL *mysql_num_rows_func)(MYSQL_RES *res);
434+
MYSQL_RES *(STDCALL *mysql_store_result_func)(MYSQL *mysql);
435+
void (STDCALL *mysql_free_result_func)(MYSQL_RES *result);
436+
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
437+
void (STDCALL *mysql_close_func)(MYSQL *mysql);
438+
} *sql_service;
439+
MYSQL *mysql_real_connect_local(MYSQL *mysql);
422440
struct st_mysql_xid {
423441
long formatID;
424442
long gtrid_length;

include/mysql/plugin_ftparser.h.pp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,24 @@
419419
char *json, char *json_end);
420420
int json_unescape_json(const char *json_str, const char *json_end,
421421
char *res, char *res_end);
422+
extern struct sql_service_st {
423+
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
424+
MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
425+
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
426+
const char *user, const char *passwd, const char *db, unsigned int port,
427+
const char *unix_socket, unsigned long clientflag);
428+
unsigned int(STDCALL *mysql_errno_func)(MYSQL *mysql);
429+
const char *(STDCALL *mysql_error_func)(MYSQL *mysql);
430+
int (STDCALL *mysql_real_query_func)(MYSQL *mysql, const char *q,
431+
unsigned long length);
432+
my_ulonglong (STDCALL *mysql_affected_rows_func)(MYSQL *mysql);
433+
my_ulonglong (STDCALL *mysql_num_rows_func)(MYSQL_RES *res);
434+
MYSQL_RES *(STDCALL *mysql_store_result_func)(MYSQL *mysql);
435+
void (STDCALL *mysql_free_result_func)(MYSQL_RES *result);
436+
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
437+
void (STDCALL *mysql_close_func)(MYSQL *mysql);
438+
} *sql_service;
439+
MYSQL *mysql_real_connect_local(MYSQL *mysql);
422440
struct st_mysql_xid {
423441
long formatID;
424442
long gtrid_length;

include/mysql/plugin_password_validation.h.pp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,24 @@
419419
char *json, char *json_end);
420420
int json_unescape_json(const char *json_str, const char *json_end,
421421
char *res, char *res_end);
422+
extern struct sql_service_st {
423+
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
424+
MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
425+
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
426+
const char *user, const char *passwd, const char *db, unsigned int port,
427+
const char *unix_socket, unsigned long clientflag);
428+
unsigned int(STDCALL *mysql_errno_func)(MYSQL *mysql);
429+
const char *(STDCALL *mysql_error_func)(MYSQL *mysql);
430+
int (STDCALL *mysql_real_query_func)(MYSQL *mysql, const char *q,
431+
unsigned long length);
432+
my_ulonglong (STDCALL *mysql_affected_rows_func)(MYSQL *mysql);
433+
my_ulonglong (STDCALL *mysql_num_rows_func)(MYSQL_RES *res);
434+
MYSQL_RES *(STDCALL *mysql_store_result_func)(MYSQL *mysql);
435+
void (STDCALL *mysql_free_result_func)(MYSQL_RES *result);
436+
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
437+
void (STDCALL *mysql_close_func)(MYSQL *mysql);
438+
} *sql_service;
439+
MYSQL *mysql_real_connect_local(MYSQL *mysql);
422440
struct st_mysql_xid {
423441
long formatID;
424442
long gtrid_length;

include/mysql/service_sql.h

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* Copyright (C) 2021 MariaDB Corporation
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
15+
16+
#ifndef MYSQL_SERVICE_SQL
17+
#define MYSQL_SERVICE_SQL
18+
19+
#ifndef MYSQL_ABI_CHECK
20+
#include <mysql.h>
21+
#endif
22+
23+
/**
24+
@file
25+
SQL service
26+
27+
Interface for plugins to execute SQL queries on the local server.
28+
29+
Functions of the service are the 'server-limited' client library:
30+
mysql_init
31+
mysql_real_connect_local
32+
mysql_real_connect
33+
mysql_errno
34+
mysql_error
35+
mysql_real_query
36+
mysql_affected_rows
37+
mysql_num_rows
38+
mysql_store_result
39+
mysql_free_result
40+
mysql_fetch_row
41+
mysql_close
42+
*/
43+
44+
45+
#ifdef __cplusplus
46+
extern "C" {
47+
#endif
48+
49+
extern struct sql_service_st {
50+
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
51+
MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
52+
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
53+
const char *user, const char *passwd, const char *db, unsigned int port,
54+
const char *unix_socket, unsigned long clientflag);
55+
unsigned int(STDCALL *mysql_errno_func)(MYSQL *mysql);
56+
const char *(STDCALL *mysql_error_func)(MYSQL *mysql);
57+
int (STDCALL *mysql_real_query_func)(MYSQL *mysql, const char *q,
58+
unsigned long length);
59+
my_ulonglong (STDCALL *mysql_affected_rows_func)(MYSQL *mysql);
60+
my_ulonglong (STDCALL *mysql_num_rows_func)(MYSQL_RES *res);
61+
MYSQL_RES *(STDCALL *mysql_store_result_func)(MYSQL *mysql);
62+
void (STDCALL *mysql_free_result_func)(MYSQL_RES *result);
63+
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
64+
void (STDCALL *mysql_close_func)(MYSQL *mysql);
65+
} *sql_service;
66+
67+
#ifdef MYSQL_DYNAMIC_PLUGIN
68+
69+
#define mysql_init(M) sql_service->mysql_init_func(M)
70+
#define mysql_real_connect_local(M) sql_service->mysql_real_connect_local_func(M)
71+
#define mysql_real_connect(M,H,U,PW,D,P,S,F) sql_service->mysql_real_connect_func(M,H,U,PW,D,P,S,F)
72+
#define mysql_errno(M) sql_service->mysql_errno_func(M)
73+
#define mysql_error(M) sql_service->mysql_error_func(M)
74+
#define mysql_real_query sql_service->mysql_real_query_func
75+
#define mysql_affected_rows(M) sql_service->mysql_affected_rows_func(M)
76+
#define mysql_num_rows(R) sql_service->mysql_num_rows_func(R)
77+
#define mysql_store_result(M) sql_service->mysql_store_result_func(M)
78+
#define mysql_free_result(R) sql_service->mysql_free_result_func(R)
79+
#define mysql_fetch_row(R) sql_service->mysql_fetch_row_func(R)
80+
#define mysql_close(M) sql_service->mysql_close_func(M)
81+
82+
#else
83+
84+
/*
85+
Establishes the connection to the 'local' server that started the plugin.
86+
Like the mysql_real_connect() does for the remote server.
87+
The established connection has no user/host associated to it,
88+
neither it has the current db, so the queries should have
89+
database/table name specified.
90+
*/
91+
MYSQL *mysql_real_connect_local(MYSQL *mysql);
92+
93+
/* The rest of the function declarations mest be taken from the mysql.h */
94+
95+
#endif /*MYSQL_DYNAMIC_PLUGIN*/
96+
97+
98+
#ifdef __cplusplus
99+
}
100+
#endif
101+
102+
#endif /*MYSQL_SERVICE_SQL */
103+
104+

include/mysql/services.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern "C" {
4141
#include <mysql/service_thd_wait.h>
4242
#include <mysql/service_json.h>
4343
/*#include <mysql/service_wsrep.h>*/
44+
#include <mysql/service_sql.h>
4445

4546
#ifdef __cplusplus
4647
}

include/service_versions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@
4343
#define VERSION_thd_wait 0x0100
4444
#define VERSION_wsrep 0x0400
4545
#define VERSION_json 0x0100
46+
#define VERSION_sql_service 0x0100

include/sql_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ typedef struct st_mysql_methods
6565
MYSQL_ROW column, unsigned int field_count);
6666
void (*flush_use_result)(MYSQL *mysql, my_bool flush_all_results);
6767
int (*read_change_user_result)(MYSQL *mysql);
68+
void (*on_close_free)(MYSQL *mysql);
6869
#if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
6970
MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
7071
my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
7172
int (*stmt_execute)(MYSQL_STMT *stmt);
7273
int (*read_binary_rows)(MYSQL_STMT *stmt);
7374
int (*unbuffered_fetch)(MYSQL *mysql, char **row);
74-
void (*free_embedded_thd)(MYSQL *mysql);
7575
const char *(*read_statistics)(MYSQL *mysql);
7676
my_bool (*next_result)(MYSQL *mysql);
7777
int (*read_rows_from_cursor)(MYSQL_STMT *stmt);

0 commit comments

Comments
 (0)