|
| 1 | +/* Copyright (c) 2021, Oracle and/or its affiliates. |
| 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, version 2.0, |
| 5 | +as published by the Free Software Foundation. |
| 6 | +
|
| 7 | +This program is also distributed with certain software (including |
| 8 | +but not limited to OpenSSL) that is licensed under separate terms, |
| 9 | +as designated in a particular file or component or in included license |
| 10 | +documentation. The authors of MySQL hereby grant you an additional |
| 11 | +permission to link the program and your derivative works with the |
| 12 | +separately licensed software that they have included with MySQL. |
| 13 | +
|
| 14 | +This program is distributed in the hope that it will be useful, |
| 15 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +GNU General Public License, version 2.0, for more details. |
| 18 | +
|
| 19 | +You should have received a copy of the GNU General Public License |
| 20 | +along with this program; if not, write to the Free Software |
| 21 | +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 22 | + |
| 23 | +#ifndef MYSQL_THD_ATTRIBUTES_H |
| 24 | +#define MYSQL_THD_ATTRIBUTES_H |
| 25 | + |
| 26 | +#include <mysql/components/service.h> |
| 27 | +#include <mysql/components/services/bits/thd.h> |
| 28 | + |
| 29 | +/** |
| 30 | + @ingroup group_components_services_inventory |
| 31 | +
|
| 32 | + THD Attributes service allows to obtain data associated with the THD |
| 33 | + object, which keeps various attributes of the user session. |
| 34 | +
|
| 35 | + Currently, following attributes are supported: |
| 36 | +
|
| 37 | + - Query Digest Text |
| 38 | +
|
| 39 | + @section Initialization |
| 40 | +
|
| 41 | + The service can be instantiated using the registry service with the |
| 42 | + "mysql_thd_attributes" name. |
| 43 | +
|
| 44 | + @code |
| 45 | + SERVICE_TYPE(registry) *registry = mysql_plugin_registry_acquire(); |
| 46 | + my_service<SERVICE_TYPE(mysql_thd_attributes)> |
| 47 | + svc("mysql_thd_attributes", registry); |
| 48 | + if (svc.is_valid()) { |
| 49 | + // The service is ready to be used |
| 50 | + } |
| 51 | + @endcode |
| 52 | +
|
| 53 | + @section Query Digest Text |
| 54 | +
|
| 55 | + Query Digest represents converted SQL statement to normalized form. The code |
| 56 | + below demonstrates how query digest can be obtained from the service. |
| 57 | +
|
| 58 | + @code |
| 59 | + my_h_string str; |
| 60 | +
|
| 61 | + mysql_thd_attributes->get(m_thd, "query_digest", |
| 62 | + reinterpret_cast<void *>(&str)); |
| 63 | + @endcode |
| 64 | +
|
| 65 | + The buffer can be fetched using the code below: |
| 66 | +
|
| 67 | + @code |
| 68 | + char buf[1024]; // buffer must be big enough to store the digest |
| 69 | +
|
| 70 | + mysql_string_converter->convert_to_buffer(str, buf, sizeof(buf), "utf8"); |
| 71 | + @endcode |
| 72 | +
|
| 73 | + After the string content has been copied into another buffer, it must be |
| 74 | + destroyed: |
| 75 | +
|
| 76 | + @code |
| 77 | + mysql_string_factory->destroy(str); |
| 78 | + @endcode |
| 79 | +*/ |
| 80 | +BEGIN_SERVICE_DEFINITION(mysql_thd_attributes) |
| 81 | + |
| 82 | +/** |
| 83 | + Get THD attribute. |
| 84 | +
|
| 85 | + Currently, following attributes are supported: |
| 86 | +
|
| 87 | + - Query Digest Text ("query_digest" of the returned my_h_string type). |
| 88 | +
|
| 89 | + @param thd Session THD object. |
| 90 | + @param name Name of the attribute to be set. |
| 91 | + @param[out] inout_pvalue Iterator pointer. |
| 92 | +
|
| 93 | + @return |
| 94 | + @retval FALSE Succeeded. |
| 95 | + @retval TRUE Failed. |
| 96 | +*/ |
| 97 | +DECLARE_BOOL_METHOD(get, (MYSQL_THD thd, const char *name, void *inout_pvalue)); |
| 98 | + |
| 99 | +/** |
| 100 | + Set THD attribute. |
| 101 | +
|
| 102 | + Currently the implementation does not support setting of any attribute. |
| 103 | +
|
| 104 | + @param thd Session THD object. |
| 105 | + @param name Name of the attribute to be set. |
| 106 | + @param[out] inout_pvalue Iterator pointer. |
| 107 | +
|
| 108 | + @return The function always fail and return TRUE value. |
| 109 | +*/ |
| 110 | +DECLARE_BOOL_METHOD(set, (MYSQL_THD thd, const char *name, void *inout_pvalue)); |
| 111 | + |
| 112 | +END_SERVICE_DEFINITION(mysql_thd_attributes) |
| 113 | + |
| 114 | +#endif /* MYSQL_THD_ATTRIBUTES_H */ |
0 commit comments