1 /* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. 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 DD__PARAMETER_IMPL_INCLUDED 24 #define DD__PARAMETER_IMPL_INCLUDED 25 26 #include <stddef.h> 27 #include <sys/types.h> 28 #include <memory> // std::unique_ptr 29 #include <new> 30 31 #include "my_dbug.h" 32 #include "sql/dd/impl/properties_impl.h" // dd::Properties_imp 33 #include "sql/dd/impl/raw/raw_record.h" 34 #include "sql/dd/impl/types/entity_object_impl.h" // dd::Entity_object_impl 35 #include "sql/dd/impl/types/weak_object_impl.h" 36 #include "sql/dd/object_id.h" 37 #include "sql/dd/string_type.h" 38 #include "sql/dd/types/column.h" 39 #include "sql/dd/types/parameter.h" // dd::Parameter 40 #include "sql/dd/types/parameter_type_element.h" // IWYU pragma: keep 41 42 namespace dd { 43 44 /////////////////////////////////////////////////////////////////////////// 45 46 class Object_table; 47 class Open_dictionary_tables_ctx; 48 class Routine; 49 class Routine_impl; 50 class Weak_object; 51 52 /////////////////////////////////////////////////////////////////////////// 53 54 class Parameter_impl : public Entity_object_impl, public Parameter { 55 public: 56 Parameter_impl(); 57 58 Parameter_impl(Routine_impl *routine); 59 60 Parameter_impl(const Parameter_impl &src, Routine_impl *parent); 61 ~Parameter_impl()62 virtual ~Parameter_impl() {} 63 64 public: 65 virtual const Object_table &object_table() const; 66 67 virtual bool validate() const; 68 69 virtual bool restore_children(Open_dictionary_tables_ctx *otx); 70 71 virtual bool store_children(Open_dictionary_tables_ctx *otx); 72 73 virtual bool drop_children(Open_dictionary_tables_ctx *otx) const; 74 75 virtual bool store_attributes(Raw_record *r); 76 77 virtual bool restore_attributes(const Raw_record &r); 78 79 virtual void debug_print(String_type &outb) const; 80 set_ordinal_position(uint ordinal_position)81 void set_ordinal_position(uint ordinal_position) { 82 m_ordinal_position = ordinal_position; 83 } 84 85 public: 86 static void register_tables(Open_dictionary_tables_ctx *otx); 87 88 ///////////////////////////////////////////////////////////////////////// 89 // Name is nullable in case of function return type. 90 ///////////////////////////////////////////////////////////////////////// 91 set_name_null(bool is_null)92 virtual void set_name_null(bool is_null) { m_is_name_null = is_null; } 93 is_name_null()94 virtual bool is_name_null() const { return m_is_name_null; } 95 96 ///////////////////////////////////////////////////////////////////////// 97 // ordinal_position. 98 ///////////////////////////////////////////////////////////////////////// 99 ordinal_position()100 virtual uint ordinal_position() const { return m_ordinal_position; } 101 102 ///////////////////////////////////////////////////////////////////////// 103 // parameter_mode. 104 ///////////////////////////////////////////////////////////////////////// 105 mode()106 virtual enum_parameter_mode mode() const { return m_parameter_mode; } 107 set_mode(enum_parameter_mode mode)108 virtual void set_mode(enum_parameter_mode mode) { m_parameter_mode = mode; } 109 set_parameter_mode_null(bool is_null)110 virtual void set_parameter_mode_null(bool is_null) { 111 m_parameter_mode_null = is_null; 112 } 113 is_parameter_mode_null()114 virtual bool is_parameter_mode_null() const { return m_parameter_mode_null; } 115 116 ///////////////////////////////////////////////////////////////////////// 117 // parameter_mode. 118 ///////////////////////////////////////////////////////////////////////// 119 data_type()120 virtual enum_column_types data_type() const { return m_data_type; } 121 set_data_type(enum_column_types type)122 virtual void set_data_type(enum_column_types type) { m_data_type = type; } 123 124 ///////////////////////////////////////////////////////////////////////// 125 // display type 126 ///////////////////////////////////////////////////////////////////////// 127 data_type_utf8()128 virtual const String_type &data_type_utf8() const { return m_data_type_utf8; } 129 set_data_type_utf8(const String_type & data_type_utf8)130 virtual void set_data_type_utf8(const String_type &data_type_utf8) { 131 m_data_type_utf8 = data_type_utf8; 132 } 133 134 ///////////////////////////////////////////////////////////////////////// 135 // is_zerofill. 136 ///////////////////////////////////////////////////////////////////////// 137 is_zerofill()138 virtual bool is_zerofill() const { return m_is_zerofill; } 139 set_zerofill(bool zerofill)140 virtual void set_zerofill(bool zerofill) { m_is_zerofill = zerofill; } 141 142 ///////////////////////////////////////////////////////////////////////// 143 // is_unsigned. 144 ///////////////////////////////////////////////////////////////////////// 145 is_unsigned()146 virtual bool is_unsigned() const { return m_is_unsigned; } 147 set_unsigned(bool unsigned_flag)148 virtual void set_unsigned(bool unsigned_flag) { 149 m_is_unsigned = unsigned_flag; 150 } 151 152 ///////////////////////////////////////////////////////////////////////// 153 // char_length. 154 ///////////////////////////////////////////////////////////////////////// 155 char_length()156 virtual size_t char_length() const { return m_char_length; } 157 set_char_length(size_t char_length)158 virtual void set_char_length(size_t char_length) { 159 m_char_length = char_length; 160 } 161 162 ///////////////////////////////////////////////////////////////////////// 163 // numeric_precision. 164 ///////////////////////////////////////////////////////////////////////// 165 numeric_precision()166 virtual uint numeric_precision() const { return m_numeric_precision; } 167 set_numeric_precision(uint numeric_precision)168 virtual void set_numeric_precision(uint numeric_precision) { 169 m_numeric_precision_null = false; 170 m_numeric_precision = numeric_precision; 171 } 172 set_numeric_precision_null(bool is_null)173 virtual void set_numeric_precision_null(bool is_null) { 174 m_numeric_precision_null = is_null; 175 } 176 is_numeric_precision_null()177 virtual bool is_numeric_precision_null() const { 178 return m_numeric_precision_null; 179 } 180 181 ///////////////////////////////////////////////////////////////////////// 182 // numeric_scale. 183 ///////////////////////////////////////////////////////////////////////// 184 numeric_scale()185 virtual uint numeric_scale() const { return m_numeric_scale; } 186 set_numeric_scale(uint numeric_scale)187 virtual void set_numeric_scale(uint numeric_scale) { 188 m_numeric_scale_null = false; 189 m_numeric_scale = numeric_scale; 190 } 191 set_numeric_scale_null(bool is_null)192 virtual void set_numeric_scale_null(bool is_null) { 193 m_numeric_scale_null = is_null; 194 } 195 is_numeric_scale_null()196 virtual bool is_numeric_scale_null() const { return m_numeric_scale_null; } 197 198 ///////////////////////////////////////////////////////////////////////// 199 // datetime_precision. 200 ///////////////////////////////////////////////////////////////////////// 201 datetime_precision()202 virtual uint datetime_precision() const { return m_datetime_precision; } 203 set_datetime_precision(uint datetime_precision)204 virtual void set_datetime_precision(uint datetime_precision) { 205 m_datetime_precision_null = false; 206 m_datetime_precision = datetime_precision; 207 } 208 set_datetime_precision_null(bool is_null)209 virtual void set_datetime_precision_null(bool is_null) { 210 m_datetime_precision_null = is_null; 211 } 212 is_datetime_precision_null()213 virtual bool is_datetime_precision_null() const { 214 return m_datetime_precision_null; 215 } 216 217 ///////////////////////////////////////////////////////////////////////// 218 // collation. 219 ///////////////////////////////////////////////////////////////////////// 220 collation_id()221 virtual Object_id collation_id() const { return m_collation_id; } 222 set_collation_id(Object_id collation_id)223 virtual void set_collation_id(Object_id collation_id) { 224 m_collation_id = collation_id; 225 } 226 227 ///////////////////////////////////////////////////////////////////////// 228 // Options. 229 ///////////////////////////////////////////////////////////////////////// 230 options()231 virtual const Properties &options() const { return m_options; } 232 options()233 virtual Properties &options() { return m_options; } 234 set_options(const String_type & options_raw)235 virtual bool set_options(const String_type &options_raw) { 236 return m_options.insert_values(options_raw); 237 } 238 239 ///////////////////////////////////////////////////////////////////////// 240 // routine. 241 ///////////////////////////////////////////////////////////////////////// 242 243 virtual const Routine &routine() const; 244 245 virtual Routine &routine(); 246 247 ///////////////////////////////////////////////////////////////////////// 248 // Elements. 249 ///////////////////////////////////////////////////////////////////////// 250 251 virtual Parameter_type_element *add_element(); 252 elements()253 virtual const Parameter_type_element_collection &elements() const { 254 DBUG_ASSERT(data_type() == enum_column_types::ENUM || 255 data_type() == enum_column_types::SET); 256 return m_elements; 257 } 258 elements_count()259 virtual size_t elements_count() const { return m_elements.size(); } 260 261 // Fix "inherits ... via dominance" warnings impl()262 virtual Entity_object_impl *impl() { return Entity_object_impl::impl(); } impl()263 virtual const Entity_object_impl *impl() const { 264 return Entity_object_impl::impl(); 265 } id()266 virtual Object_id id() const { return Entity_object_impl::id(); } is_persistent()267 virtual bool is_persistent() const { 268 return Entity_object_impl::is_persistent(); 269 } name()270 virtual const String_type &name() const { return Entity_object_impl::name(); } set_name(const String_type & name)271 virtual void set_name(const String_type &name) { 272 Entity_object_impl::set_name(name); 273 } 274 275 public: restore_item(Routine_impl * routine)276 static Parameter_impl *restore_item(Routine_impl *routine) { 277 return new (std::nothrow) Parameter_impl(routine); 278 } 279 clone(const Parameter_impl & other,Routine_impl * routine)280 static Parameter_impl *clone(const Parameter_impl &other, 281 Routine_impl *routine) { 282 return new (std::nothrow) Parameter_impl(other, routine); 283 } 284 285 private: 286 // Fields 287 bool m_is_name_null; 288 289 enum_parameter_mode m_parameter_mode; 290 bool m_parameter_mode_null; 291 enum_column_types m_data_type; 292 String_type m_data_type_utf8; 293 294 bool m_is_zerofill; 295 bool m_is_unsigned; 296 297 uint m_ordinal_position; 298 size_t m_char_length; 299 uint m_numeric_precision; 300 bool m_numeric_precision_null; 301 uint m_numeric_scale; 302 bool m_numeric_scale_null; 303 uint m_datetime_precision; 304 bool m_datetime_precision_null; 305 306 Parameter_type_element_collection m_elements; 307 308 Properties_impl m_options; 309 310 // References to other tightly coupled objects 311 Routine_impl *m_routine; 312 313 // References to loosely-coupled objects. 314 315 Object_id m_collation_id; 316 }; 317 318 /////////////////////////////////////////////////////////////////////////// 319 320 } // namespace dd 321 322 #endif // DD__PARAMETER_IMPL_INCLUDED 323