mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
MDEV-21166 Add Mroonga initialized check to Mroonga UDFs
Mroonga UDFs can't be used without loading Mroonga.
This commit is contained in:
parent
49dff5a4b6
commit
383d53edbc
11 changed files with 110 additions and 0 deletions
|
@ -20,6 +20,7 @@
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
*/
|
||||
|
||||
#include "mrn.hpp"
|
||||
#include "mrn_mysql.h"
|
||||
#include "mrn_mysql_compat.h"
|
||||
|
||||
|
@ -296,6 +297,7 @@ static PSI_mutex_info mrn_mutexes[] =
|
|||
#endif
|
||||
|
||||
/* global variables */
|
||||
bool mrn_initialized = false;
|
||||
handlerton *mrn_hton_ptr;
|
||||
HASH mrn_open_tables;
|
||||
mysql_mutex_t mrn_open_tables_mutex;
|
||||
|
@ -1957,6 +1959,8 @@ static int mrn_init(void *p)
|
|||
mrn::PathMapper::default_mysql_data_home_path = mysql_data_home;
|
||||
#endif
|
||||
|
||||
mrn_initialized = true;
|
||||
|
||||
return 0;
|
||||
|
||||
error_allocated_long_term_share_hash_init:
|
||||
|
@ -2051,6 +2055,8 @@ static int mrn_deinit(void *p)
|
|||
mysql_mutex_destroy(&mrn_query_log_mutex);
|
||||
mysql_mutex_destroy(&mrn_log_mutex);
|
||||
|
||||
mrn_initialized = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
29
storage/mroonga/mrn.hpp
Normal file
29
storage/mroonga/mrn.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
Copyright (C) 2024 Sutou Kouhei <kou@clear-code.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern bool mrn_initialized;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,4 +1,5 @@
|
|||
sources = \
|
||||
mrn.hpp \
|
||||
mrn_macro.hpp \
|
||||
mrn_constants.hpp \
|
||||
ha_mroonga.cpp \
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
*/
|
||||
|
||||
#include <mrn.hpp>
|
||||
#include <mrn_mysql.h>
|
||||
#include <mrn_mysql_compat.h>
|
||||
#include <mrn_path_mapper.hpp>
|
||||
|
@ -51,6 +52,15 @@ MRN_API my_bool mroonga_command_init(UDF_INIT *init, UDF_ARGS *args,
|
|||
CommandInfo *info = NULL;
|
||||
|
||||
init->ptr = NULL;
|
||||
|
||||
if (!mrn_initialized)
|
||||
{
|
||||
snprintf(message,
|
||||
MYSQL_ERRMSG_SIZE,
|
||||
"mroonga_command(): Mroonga isn't initialized");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (args->arg_count == 0) {
|
||||
grn_snprintf(message,
|
||||
MYSQL_ERRMSG_SIZE,
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
*/
|
||||
|
||||
#include <mrn.hpp>
|
||||
#include <mrn_mysql.h>
|
||||
#include <mrn_mysql_compat.h>
|
||||
#include <mrn_path_mapper.hpp>
|
||||
|
@ -44,6 +45,15 @@ MRN_API my_bool mroonga_escape_init(UDF_INIT *init, UDF_ARGS *args,
|
|||
bool script_mode = false;
|
||||
|
||||
init->ptr = NULL;
|
||||
|
||||
if (!mrn_initialized)
|
||||
{
|
||||
snprintf(message,
|
||||
MYSQL_ERRMSG_SIZE,
|
||||
"mroonga_escape(): Mroonga isn't initialized");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(1 <= args->arg_count && args->arg_count <= 2)) {
|
||||
snprintf(message,
|
||||
MYSQL_ERRMSG_SIZE,
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
*/
|
||||
|
||||
#include <mrn.hpp>
|
||||
#include <mrn_mysql.h>
|
||||
#include <mrn_mysql_compat.h>
|
||||
#include <mrn_err.h>
|
||||
|
@ -211,6 +212,14 @@ MRN_API my_bool mroonga_highlight_html_init(UDF_INIT *init,
|
|||
|
||||
init->ptr = NULL;
|
||||
|
||||
if (!mrn_initialized)
|
||||
{
|
||||
snprintf(message,
|
||||
MYSQL_ERRMSG_SIZE,
|
||||
"mroonga_highlight_html(): Mroonga isn't initialized");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (args->arg_count < 1) {
|
||||
snprintf(message, MYSQL_ERRMSG_SIZE,
|
||||
"mroonga_highlight_html(): wrong number of arguments: %u for 1+",
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
*/
|
||||
|
||||
#include <mrn.hpp>
|
||||
#include <mrn_mysql.h>
|
||||
#include <mrn_windows.hpp>
|
||||
#include <mrn_table.hpp>
|
||||
|
@ -29,6 +30,13 @@ MRN_BEGIN_DECLS
|
|||
|
||||
MRN_API my_bool last_insert_grn_id_init(UDF_INIT *init, UDF_ARGS *args, char *message)
|
||||
{
|
||||
if (!mrn_initialized)
|
||||
{
|
||||
snprintf(message,
|
||||
MYSQL_ERRMSG_SIZE,
|
||||
"last_insert_grn_id(): Mroonga isn't initialized");
|
||||
return 1;
|
||||
}
|
||||
if (args->arg_count != 0) {
|
||||
strcpy(message, "last_insert_grn_id must not have arguments");
|
||||
return 1;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
*/
|
||||
|
||||
#include <mrn.hpp>
|
||||
#include <mrn_mysql.h>
|
||||
#include <mrn_mysql_compat.h>
|
||||
#include <mrn_encoding.hpp>
|
||||
|
@ -53,6 +54,15 @@ MRN_API my_bool mroonga_normalize_init(UDF_INIT *init, UDF_ARGS *args,
|
|||
String *result_str = NULL;
|
||||
|
||||
init->ptr = NULL;
|
||||
|
||||
if (!mrn_initialized)
|
||||
{
|
||||
snprintf(message,
|
||||
MYSQL_ERRMSG_SIZE,
|
||||
"mroonga_normalize(): Mroonga isn't initialized");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(1 <= args->arg_count && args->arg_count <= 2)) {
|
||||
sprintf(message,
|
||||
"mroonga_normalize(): Incorrect number of arguments: %u for 1..2",
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
*/
|
||||
|
||||
#include <mrn.hpp>
|
||||
#include <mrn_mysql.h>
|
||||
#include <mrn_mysql_compat.h>
|
||||
#include <mrn_path_mapper.hpp>
|
||||
|
@ -74,6 +75,15 @@ MRN_API my_bool mroonga_query_expand_init(UDF_INIT *init,
|
|||
MRN_DBUG_ENTER_FUNCTION();
|
||||
|
||||
init->ptr = NULL;
|
||||
|
||||
if (!mrn_initialized)
|
||||
{
|
||||
snprintf(message,
|
||||
MYSQL_ERRMSG_SIZE,
|
||||
"mroonga_query_expand(): Mroonga isn't initialized");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (args->arg_count != 4) {
|
||||
sprintf(message,
|
||||
"mroonga_query_expand(): wrong number of arguments: %u for 4",
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
*/
|
||||
|
||||
#include <mrn.hpp>
|
||||
#include <mrn_mysql.h>
|
||||
#include <mrn_mysql_compat.h>
|
||||
#include <mrn_err.h>
|
||||
|
@ -135,6 +136,13 @@ MRN_API my_bool mroonga_snippet_init(UDF_INIT *init, UDF_ARGS *args, char *messa
|
|||
st_mrn_snip_info *snip_info = NULL;
|
||||
bool can_open_snippet = TRUE;
|
||||
init->ptr = NULL;
|
||||
if (!mrn_initialized)
|
||||
{
|
||||
snprintf(message,
|
||||
MYSQL_ERRMSG_SIZE,
|
||||
"mroonga_snippet(): Mroonga isn't initialized");
|
||||
goto error;
|
||||
}
|
||||
if (args->arg_count < 11 || (args->arg_count - 11) % 3)
|
||||
{
|
||||
sprintf(message, "Incorrect number of arguments for mroonga_snippet(): %u",
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
||||
*/
|
||||
|
||||
#include <mrn.hpp>
|
||||
#include <mrn_mysql.h>
|
||||
#include <mrn_mysql_compat.h>
|
||||
#include <mrn_err.h>
|
||||
|
@ -194,6 +195,14 @@ MRN_API my_bool mroonga_snippet_html_init(UDF_INIT *init,
|
|||
|
||||
init->ptr = NULL;
|
||||
|
||||
if (!mrn_initialized)
|
||||
{
|
||||
snprintf(message,
|
||||
MYSQL_ERRMSG_SIZE,
|
||||
"mroonga_snippet_html(): Mroonga isn't initialized");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (args->arg_count < 1) {
|
||||
snprintf(message, MYSQL_ERRMSG_SIZE,
|
||||
"mroonga_snippet_html(): wrong number of arguments: %u for 1+",
|
||||
|
|
Loading…
Reference in a new issue