| 1 | #ifndef MOCK_FIELD_LONG_INCLUDED |
| 2 | #define MOCK_FIELD_LONG_INCLUDED |
| 3 | /* Copyright (c) 2013, 2026, Oracle and/or its affiliates. |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License, version 2.0, |
| 7 | as published by the Free Software Foundation. |
| 8 | |
| 9 | This program is designed to work with certain software (including |
| 10 | but not limited to OpenSSL) that is licensed under separate terms, |
| 11 | as designated in a particular file or component or in included license |
| 12 | documentation. The authors of MySQL hereby grant you an additional |
| 13 | permission to link the program and your derivative works with the |
| 14 | separately licensed software that they have either included with |
| 15 | the program or referenced in the documentation. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License, version 2.0, for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program; if not, write to the Free Software |
| 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 25 | |
| 26 | #include "sql/field.h" |
| 27 | |
| 28 | /** |
| 29 | Base class for creating mock Field objects. |
| 30 | |
| 31 | To do: Make all other tests #include this file instead of using |
| 32 | their own copy-pasted variants. |
| 33 | */ |
| 34 | class Mock_field_long : public Field_long { |
| 35 | public: |
| 36 | /// Creates a nullable column with the default name. |
| 37 | Mock_field_long(bool is_unsigned) |
| 38 | : Mock_field_long("field_name", true, is_unsigned) {} |
| 39 | |
| 40 | /** |
| 41 | Creates a nullable column. |
| 42 | @param name The column name. |
| 43 | */ |
| 44 | Mock_field_long(const char *name) : Mock_field_long(name, true, false) {} |
| 45 | |
| 46 | /** |
| 47 | Creates a nullable column. |
| 48 | @param name The column name. |
| 49 | */ |
| 50 | Mock_field_long(const std::string &&name, bool is_nullable, bool is_unsigned) |
| 51 | : Mock_field_long(name.c_str(), is_nullable, is_unsigned) {} |
| 52 | |
| 53 | /** |
| 54 | Creates a column. |
| 55 | @param name The column name. |
| 56 | @param is_nullable Whether it's nullable. |
| 57 | */ |
| 58 | Mock_field_long(const char *name, bool is_nullable, bool is_unsigned) |
| 59 | : Field_long( |
| 60 | nullptr, // ptr_arg |
| 61 | 8, // len_arg |
| 62 | is_nullable ? &Field::dummy_null_buffer : nullptr, // null_ptr_arg |
| 63 | is_nullable ? 1 : 0, // null_bit_arg |
| 64 | Field::NONE, // auto_flags_arg |
| 65 | name, // field_name_arg |
| 66 | false, // zero_arg |
| 67 | is_unsigned) // unsigned_arg |
| 68 | { |
| 69 | initialize(name); |
| 70 | } |
| 71 | |
| 72 | void make_writable() { bitmap_set_bit(table->write_set, field_index()); } |
| 73 | void make_readable() { bitmap_set_bit(table->read_set, field_index()); } |
| 74 | |
| 75 | private: |
| 76 | char m_name[1024]; |
| 77 | |
| 78 | void initialize(const char *name) { |
| 79 | static const char *table_name_buf = "table_name"; |
| 80 | table_name = &table_name_buf; |
| 81 | if (name) { |
| 82 | snprintf(m_name, sizeof(m_name), "%.1023s", name); |
| 83 | field_name = m_name; |
| 84 | } |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | #endif // MOCK_FIELD_LONG_INCLUDED |