MCPcopy Create free account
hub / github.com/MariaDB/server / get_field_default_value

Function get_field_default_value

sql/sql_show.cc:1848–1924  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1846
1847
1848static bool get_field_default_value(THD *thd, Field *field, String *def_value,
1849 bool quoted)
1850{
1851 bool has_default;
1852 enum enum_field_types field_type= field->type();
1853
1854 has_default= (field->default_value ||
1855 (!(field->flags & NO_DEFAULT_VALUE_FLAG) &&
1856 !field->vers_sys_field() &&
1857 field->unireg_check != Field::NEXT_NUMBER));
1858
1859 def_value->length(0);
1860 if (has_default)
1861 {
1862 StringBuffer<MAX_FIELD_WIDTH> str(&my_charset_utf8mb4_general_ci);
1863 if (field->default_value)
1864 {
1865 field->default_value->print(&str);
1866 if (field->default_value->expr->need_parentheses_in_default())
1867 {
1868 def_value->set_charset(&my_charset_utf8mb4_general_ci);
1869 def_value->append('(');
1870 def_value->append(str);
1871 def_value->append(')');
1872 }
1873 else
1874 def_value->append(str);
1875 }
1876 else if (!field->is_null())
1877 { // Not null by default
1878 if (field_type == MYSQL_TYPE_BIT)
1879 {
1880 str.qs_append('b');
1881 str.qs_append('\'');
1882 str.qs_append(field->val_int(), 2);
1883 str.qs_append('\'');
1884 def_value->append(str);
1885 }
1886 else
1887 {
1888 field->val_str(&str);
1889 if (!field->str_needs_quotes())
1890 quoted= 0;
1891 if (str.length())
1892 {
1893 if (str.charset() == &my_charset_bin)
1894 {
1895 def_value->append('x');
1896 def_value->append('\'');
1897 def_value->append_hex(str.ptr(), str.length());
1898 def_value->append('\'');
1899 }
1900 else
1901 {
1902 StringBuffer<MAX_FIELD_WIDTH> def_val;
1903 uint dummy_errors;
1904 /* convert to system_charset_info == utf8 */
1905 def_val.copy(str.ptr(), str.length(), field->charset(),

Callers 2

show_create_table_exFunction · 0.85
get_schema_column_recordFunction · 0.85

Calls 15

append_unescapedFunction · 0.85
typeMethod · 0.45
vers_sys_fieldMethod · 0.45
lengthMethod · 0.45
printMethod · 0.45
set_charsetMethod · 0.45
appendMethod · 0.45
is_nullMethod · 0.45
qs_appendMethod · 0.45
val_intMethod · 0.45
val_strMethod · 0.45

Tested by

no test coverage detected