-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathudf_reg_int_same_func.cc
107 lines (87 loc) · 4 KB
/
udf_reg_int_same_func.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
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, version 2.0, 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 */
/* This test component register the UDF myfunc_int in init (install) and
unregister it in deiniti (uninstall).
It is used for the test case to register/unregister the same method as
another test component has registered before (or afterwards). */
#include <ctype.h>
#include <mysql/components/component_implementation.h>
#include <mysql/components/service_implementation.h>
#include <mysql/components/services/udf_registration.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <string>
REQUIRES_SERVICE_PLACEHOLDER(udf_registration);
REQUIRES_SERVICE_PLACEHOLDER(udf_registration_aggregate);
/***************************************************************************
** UDF long long function.
** Arguments:
** initid Return value from xxxx_init
** args The same structure as to xxx_init. This structure
** contains values for all parameters.
** Note that the functions MUST check and convert all
** to the type it wants! Null values are represented by
** a NULL pointer
** is_null If the result is null, one should store 1 here.
** error If something goes fatally wrong one should store 1 here.
**
** This function should return the result as a long long
***************************************************************************/
/* This function returns the sum of all arguments */
long long myfunc_int(UDF_INIT *, UDF_ARGS *args, unsigned char *,
unsigned char *) {
long long val = 0;
unsigned i;
for (i = 0; i < args->arg_count; i++) {
val += *((long long *)args->args[i]);
}
return val;
}
bool myfunc_int_init(UDF_INIT *, UDF_ARGS *, char *) { return false; }
/**************************************************************************************/
static mysql_service_status_t init() {
bool ret_int = false;
ret_int = mysql_service_udf_registration->udf_register(
"myfunc_int", INT_RESULT, (Udf_func_any)myfunc_int, myfunc_int_init,
nullptr);
return ret_int;
}
static mysql_service_status_t deinit() {
int was_present = 0;
for (int i = 0; i < 10; i++) {
mysql_service_udf_registration->udf_unregister("myfunc_int", &was_present);
if (was_present != 0) break;
}
return false;
}
BEGIN_COMPONENT_PROVIDES(test_udf_registration)
END_COMPONENT_PROVIDES();
BEGIN_COMPONENT_REQUIRES(test_udf_registration)
REQUIRES_SERVICE(udf_registration),
REQUIRES_SERVICE(udf_registration_aggregate), END_COMPONENT_REQUIRES();
BEGIN_COMPONENT_METADATA(test_udf_registration)
METADATA("mysql.author", "Oracle Corporation"),
METADATA("mysql.license", "GPL"), METADATA("test_property", "1"),
END_COMPONENT_METADATA();
DECLARE_COMPONENT(test_udf_registration, "mysql:test_udf_registration")
init, deinit END_DECLARE_COMPONENT();
DECLARE_LIBRARY_COMPONENTS &COMPONENT_REF(test_udf_registration)
END_DECLARE_LIBRARY_COMPONENTS