diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2018-12-16 02:21:41 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2018-12-16 02:21:41 +0400 |
commit | c4ab352b670618bb478138cfbf3ed195317b3ccb (patch) | |
tree | 3dc86ad7d504865798871ae869ab5bac40e804b2 /sql | |
parent | 0a2edddbf4f4737863edf51970cbbaa91e72e11f (diff) | |
download | mariadb-git-c4ab352b670618bb478138cfbf3ed195317b3ccb.tar.gz |
MDEV-14576 Include full name of object in message about incorrect value for column.
The error message modified.
Then the TABLE_SHARE::error_table_name() implementation taken from 10.3,
to be used as a name of the table in this message.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.cc | 33 | ||||
-rw-r--r-- | sql/item.cc | 14 | ||||
-rw-r--r-- | sql/item.h | 1 | ||||
-rw-r--r-- | sql/item_create.cc | 2 | ||||
-rw-r--r-- | sql/item_func.cc | 3 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 6 | ||||
-rw-r--r-- | sql/item_timefunc.cc | 8 | ||||
-rw-r--r-- | sql/share/errmsg-utf8.txt | 4 | ||||
-rw-r--r-- | sql/sql_class.cc | 9 | ||||
-rw-r--r-- | sql/sql_table.cc | 24 | ||||
-rw-r--r-- | sql/sql_time.cc | 44 | ||||
-rw-r--r-- | sql/sql_time.h | 12 | ||||
-rw-r--r-- | sql/table.h | 10 |
13 files changed, 121 insertions, 49 deletions
diff --git a/sql/field.cc b/sql/field.cc index 6cd8940a893..c2317e9a748 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -2092,7 +2092,7 @@ bool Field_num::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) longlong nr= val_int(); bool neg= !(flags & UNSIGNED_FLAG) && nr < 0; return int_to_datetime_with_warn(neg, neg ? -nr : nr, ltime, fuzzydate, - field_name); + table->s, field_name); } @@ -3397,7 +3397,7 @@ bool Field_new_decimal::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) { my_decimal value; return decimal_to_datetime_with_warn(val_decimal(&value), - ltime, fuzzydate, field_name); + ltime, fuzzydate, table->s, field_name); } @@ -4868,7 +4868,8 @@ bool Field_real::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) { ASSERT_COLUMN_MARKED_FOR_READ; double nr= val_real(); - return double_to_datetime_with_warn(nr, ltime, fuzzydate, field_name); + return double_to_datetime_with_warn(nr, ltime, fuzzydate, + table->s, field_name); } @@ -6351,7 +6352,7 @@ bool Field_year::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) if (tmp || field_length != 4) tmp+= 1900; return int_to_datetime_with_warn(false, tmp * 10000, - ltime, fuzzydate, field_name); + ltime, fuzzydate, table->s, field_name); } @@ -8633,10 +8634,18 @@ int Field_geom::store(const char *from, uint length, CHARSET_INFO *cs) geom_type != Field::GEOM_GEOMETRYCOLLECTION && (uint32) geom_type != wkb_type) { + const char *db= table->s->db.str; + const char *tab_name= table->s->error_table_name(); + + if (!db) + db= ""; + if (!tab_name) + tab_name= ""; + my_error(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, MYF(0), Geometry::ci_collection[geom_type]->m_name.str, Geometry::ci_collection[wkb_type]->m_name.str, - field_name, + db, tab_name, field_name, (ulong) table->in_use->get_stmt_da()-> current_row_for_warning()); goto err_exit; @@ -10800,7 +10809,8 @@ void Field::set_datetime_warning(Sql_condition::enum_warning_level level, { THD *thd= get_thd(); if (thd->really_abort_on_warning() && level >= Sql_condition::WARN_LEVEL_WARN) - make_truncated_value_warning(thd, level, str, ts_type, field_name); + make_truncated_value_warning(thd, level, str, ts_type, + table->s, field_name); else set_warning(level, code, cuted_increment); } @@ -10810,10 +10820,19 @@ void Field::set_warning_truncated_wrong_value(const char *type_arg, const char *value) { THD *thd= get_thd(); + const char *db_name= table->s->db.str; + const char *table_name= table->s->error_table_name(); + + if (!db_name) + db_name= ""; + if (!table_name) + table_name= ""; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), - type_arg, value, field_name, + type_arg, value, + db_name, table_name, field_name, static_cast<ulong>(thd->get_stmt_da()-> current_row_for_warning())); } diff --git a/sql/item.cc b/sql/item.cc index 25fb9be22eb..1c0b6cc4043 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -500,6 +500,15 @@ Item::Item(THD *thd): } +const TABLE_SHARE *Item::field_table_or_null() +{ + if (real_item()->type() != Item::FIELD_ITEM) + return NULL; + + return ((Item_field *) this)->field->table->s; +} + + /** Constructor used by Item_field, Item_ref & aggregate (sum) functions. @@ -1358,6 +1367,7 @@ bool Item::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) } if (null_value || int_to_datetime_with_warn(neg, neg ? -value : value, ltime, fuzzydate, + field_table_or_null(), field_name_or_null())) goto err; return null_value= false; @@ -1366,6 +1376,7 @@ bool Item::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) { double value= val_real(); if (null_value || double_to_datetime_with_warn(value, ltime, fuzzydate, + field_table_or_null(), field_name_or_null())) goto err; return null_value= false; @@ -1375,6 +1386,7 @@ bool Item::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) my_decimal value, *res; if (!(res= val_decimal(&value)) || decimal_to_datetime_with_warn(res, ltime, fuzzydate, + field_table_or_null(), field_name_or_null())) goto err; return null_value= false; @@ -3630,7 +3642,7 @@ void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type, { ErrConvTime str(&value.time); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &str, time_type, 0); + &str, time_type, 0, 0); set_zero_time(&value.time, time_type); } maybe_null= 0; diff --git a/sql/item.h b/sql/item.h index da1483a5a80..b941c57896c 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1186,6 +1186,7 @@ public: virtual const char *full_name() const { return name ? name : "???"; } const char *field_name_or_null() { return real_item()->type() == Item::FIELD_ITEM ? name : NULL; } + const TABLE_SHARE *field_table_or_null(); /* *result* family of methods is analog of *val* family (see above) but diff --git a/sql/item_create.cc b/sql/item_create.cc index b6430ecf18d..3218d4df844 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -7299,7 +7299,7 @@ Item *create_temporal_literal(THD *thd, ErrConvString err(str, length, cs); make_truncated_value_warning(thd, Sql_condition::time_warn_level(status.warnings), - &err, ltime.time_type, 0); + &err, ltime.time_type, 0, 0); } return item; } diff --git a/sql/item_func.cc b/sql/item_func.cc index dcf3a6f3c29..512c8fccab0 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1023,6 +1023,7 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime, my_decimal value, *res; if (!(res= decimal_op_with_null_check(&value)) || decimal_to_datetime_with_warn(res, ltime, fuzzydate, + field_table_or_null(), field_name_or_null())) goto err; break; @@ -1033,6 +1034,7 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime, bool neg= !unsigned_flag && value < 0; if (null_value || int_to_datetime_with_warn(neg, neg ? -value : value, ltime, fuzzydate, + field_table_or_null(), field_name_or_null())) goto err; break; @@ -1041,6 +1043,7 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime, { double value= real_op(); if (null_value || double_to_datetime_with_warn(value, ltime, fuzzydate, + field_table_or_null(), field_name_or_null())) goto err; break; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 57a1e7ec55b..76f3a98cd2d 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -5097,7 +5097,7 @@ bool Item_dyncol_get::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) bool neg = llval < 0; if (int_to_datetime_with_warn(neg, (ulonglong)(neg ? -llval : llval), - ltime, fuzzy_date, 0 /* TODO */)) + ltime, fuzzy_date, 0, 0 /* TODO */)) goto null; return 0; } @@ -5106,12 +5106,12 @@ bool Item_dyncol_get::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) /* fall through */ case DYN_COL_DOUBLE: if (double_to_datetime_with_warn(val.x.double_value, ltime, fuzzy_date, - 0 /* TODO */)) + 0, 0 /* TODO */)) goto null; return 0; case DYN_COL_DECIMAL: if (decimal_to_datetime_with_warn((my_decimal*)&val.x.decimal.value, ltime, - fuzzy_date, 0 /* TODO */)) + fuzzy_date, 0, 0 /* TODO */)) goto null; return 0; case DYN_COL_STRING: diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index dc5a0891538..82dbca5b23c 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -430,7 +430,7 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, val_begin, length, - cached_timestamp_type, NullS); + cached_timestamp_type, 0, NullS); break; } } while (++val != val_end); @@ -1866,13 +1866,13 @@ overflow: { ErrConvInteger err2(sec, unsigned_flag); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &err2, MYSQL_TIMESTAMP_TIME, NullS); + &err2, MYSQL_TIMESTAMP_TIME, 0, NullS); } else { ErrConvString err2(err); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &err2, MYSQL_TIMESTAMP_TIME, NullS); + &err2, MYSQL_TIMESTAMP_TIME, 0, NullS); } return 0; } @@ -2894,7 +2894,7 @@ bool Item_func_maketime::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) int len = (int)(ptr - buf) + sprintf(ptr, ":%02u:%02u", (uint)minute, (uint)second); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, buf, len, MYSQL_TIMESTAMP_TIME, - NullS); + 0, NullS); } return (null_value= 0); diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 0bb1974b6cd..8e54fa10ac5 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -5449,8 +5449,8 @@ ER_DIVISION_BY_ZERO 22012 ger "Division durch 0" hindi "0 से विभाजन" ER_TRUNCATED_WRONG_VALUE_FOR_FIELD 22007 - eng "Incorrect %-.32s value: '%-.128s' for column '%.192s' at row %lu" - ger "Falscher %-.32s-Wert: '%-.128s' für Feld '%.192s' in Zeile %lu" + eng "Incorrect %-.32s value: '%-.128s' for column `%.192s`.`%.192s`.`%.192s` at row %lu" + ger "Falscher %-.32s-Wert: '%-.128s' für Feld '`%.192s`.`%.192s`.`%.192s` in Zeile %lu" ER_ILLEGAL_VALUE_FOR_TYPE 22007 eng "Illegal %s '%-.192s' value found during parsing" ger "Nicht zulässiger %s-Wert '%-.192s' beim Parsen gefunden" diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 86eb6f28807..29a9a58f13c 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -3009,6 +3009,10 @@ int select_export::send_data(List<Item> &items) error_pos= copier.most_important_error_pos(); if (error_pos) { + /* + TODO: + add new error message that will show user this printable_buff + char printable_buff[32]; convert_to_printable(printable_buff, sizeof(printable_buff), error_pos, res->ptr() + res->length() - error_pos, @@ -3018,6 +3022,11 @@ int select_export::send_data(List<Item> &items) ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), "string", printable_buff, item->name, static_cast<long>(row_count)); + */ + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, + ER_THD(thd, WARN_DATA_TRUNCATED), + item->name, static_cast<long>(row_count)); } else if (copier.source_end_pos() < res->ptr() + res->length()) { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 02780e7d1e0..1765e352b88 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -9546,6 +9546,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, goto err_new_table_cleanup; } } + new_table->s->orig_table_name= table->s->table_name.str; + /* Note: In case of MERGE table, we do not attach children. We do not copy data for MERGE tables. Only the children have data. @@ -9768,16 +9770,6 @@ end_temporary: err_new_table_cleanup: my_free(const_cast<uchar*>(frm.str)); - if (new_table) - { - thd->drop_temporary_table(new_table, NULL, true); - } - else - (void) quick_rm_table(thd, new_db_type, - alter_ctx.new_db, alter_ctx.tmp_name, - (FN_IS_TMP | (no_ha_table ? NO_HA_TABLE : 0)), - alter_ctx.get_tmp_path()); - /* No default value was provided for a DATE/DATETIME field, the current sql_mode doesn't allow the '0000-00-00' value and @@ -9809,10 +9801,22 @@ err_new_table_cleanup: thd->abort_on_warning= true; make_truncated_value_warning(thd, Sql_condition::WARN_LEVEL_WARN, f_val, strlength(f_val), t_type, + new_table->s, alter_ctx.datetime_field->field_name); thd->abort_on_warning= save_abort_on_warning; } + if (new_table) + { + thd->drop_temporary_table(new_table, NULL, true); + } + else + (void) quick_rm_table(thd, new_db_type, + alter_ctx.new_db, alter_ctx.tmp_name, + (FN_IS_TMP | (no_ha_table ? NO_HA_TABLE : 0)), + alter_ctx.get_tmp_path()); + + DBUG_RETURN(true); err_with_mdl_after_alter: diff --git a/sql/sql_time.cc b/sql/sql_time.cc index cdb9f4e5b79..53e380f59c8 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -223,7 +223,7 @@ check_date_with_warn(const MYSQL_TIME *ltime, ulonglong fuzzy_date, { ErrConvTime str(ltime); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &str, ts_type, 0); + &str, ts_type, 0, 0); return true; } return false; @@ -240,7 +240,7 @@ adjust_time_range_with_warn(MYSQL_TIME *ltime, uint dec) return true; if (warnings) make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &str, MYSQL_TIMESTAMP_TIME, NullS); + &str, MYSQL_TIMESTAMP_TIME, 0, NullS); return false; } @@ -329,7 +329,7 @@ str_to_datetime_with_warn(CHARSET_INFO *cs, ret_val ? Sql_condition::WARN_LEVEL_WARN : Sql_condition::time_warn_level(status.warnings), str, length, flags & TIME_TIME_ONLY ? - MYSQL_TIMESTAMP_TIME : l_time->time_type, NullS); + MYSQL_TIMESTAMP_TIME : l_time->time_type, 0, NullS); DBUG_EXECUTE_IF("str_to_datetime_warn", push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_YES, str);); @@ -353,7 +353,7 @@ str_to_datetime_with_warn(CHARSET_INFO *cs, static bool number_to_time_with_warn(bool neg, ulonglong nr, ulong sec_part, MYSQL_TIME *ltime, ulonglong fuzzydate, const ErrConv *str, - const char *field_name) + const TABLE_SHARE *s, const char *field_name) { int was_cut; longlong res; @@ -387,14 +387,15 @@ static bool number_to_time_with_warn(bool neg, ulonglong nr, ulong sec_part, Sql_condition::WARN_LEVEL_WARN, str, res < 0 ? MYSQL_TIMESTAMP_ERROR : mysql_type_to_time_type(f_type), - field_name); + s, field_name); } return res < 0; } bool double_to_datetime_with_warn(double value, MYSQL_TIME *ltime, - ulonglong fuzzydate, const char *field_name) + ulonglong fuzzydate, + const TABLE_SHARE *s, const char *field_name) { const ErrConvDouble str(value); bool neg= value < 0; @@ -408,28 +409,30 @@ bool double_to_datetime_with_warn(double value, MYSQL_TIME *ltime, longlong nr= static_cast<ulonglong>(floor(value)); uint sec_part= static_cast<ulong>((value - floor(value))*TIME_SECOND_PART_FACTOR); return number_to_time_with_warn(neg, nr, sec_part, ltime, fuzzydate, &str, - field_name); + s, field_name); } bool decimal_to_datetime_with_warn(const my_decimal *value, MYSQL_TIME *ltime, - ulonglong fuzzydate, const char *field_name) + ulonglong fuzzydate, + const TABLE_SHARE *s, const char *field_name) { const ErrConvDecimal str(value); ulonglong nr; ulong sec_part; bool neg= my_decimal2seconds(value, &nr, &sec_part); return number_to_time_with_warn(neg, nr, sec_part, ltime, fuzzydate, &str, - field_name); + s, field_name); } bool int_to_datetime_with_warn(bool neg, ulonglong value, MYSQL_TIME *ltime, - ulonglong fuzzydate, const char *field_name) + ulonglong fuzzydate, + const TABLE_SHARE *s, const char *field_name) { const ErrConvInteger str(neg ? - (longlong) value : (longlong) value, !neg); return number_to_time_with_warn(neg, value, 0, ltime, - fuzzydate, &str, field_name); + fuzzydate, &str, s, field_name); } @@ -856,7 +859,7 @@ void make_truncated_value_warning(THD *thd, Sql_condition::enum_warning_level level, const ErrConv *sval, timestamp_type time_type, - const char *field_name) + const TABLE_SHARE *s, const char *field_name) { char warn_buff[MYSQL_ERRMSG_SIZE]; const char *type_str; @@ -875,10 +878,21 @@ void make_truncated_value_warning(THD *thd, break; } if (field_name) + { + const char *db_name= s->db.str; + const char *table_name= s->error_table_name(); + + if (!db_name) + db_name= ""; + if (!table_name) + table_name= ""; + cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff), ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), - type_str, sval->ptr(), field_name, + type_str, sval->ptr(), + db_name, table_name, field_name, (ulong) thd->get_stmt_da()->current_row_for_warning()); + } else { if (time_type > MYSQL_TIMESTAMP_ERROR) @@ -1205,7 +1219,7 @@ make_date_with_warn(MYSQL_TIME *ltime, ulonglong fuzzy_date, /* e.g. negative time */ ErrConvTime str(ltime); make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &str, ts_type, 0); + &str, ts_type, 0, 0); return true; } if ((ltime->time_type= ts_type) == MYSQL_TIMESTAMP_DATE) @@ -1369,7 +1383,7 @@ time_to_datetime_with_warn(THD *thd, { ErrConvTime str(from); make_truncated_value_warning(thd, Sql_condition::WARN_LEVEL_WARN, - &str, MYSQL_TIMESTAMP_DATETIME, 0); + &str, MYSQL_TIMESTAMP_DATETIME, 0, 0); return true; } return false; diff --git a/sql/sql_time.h b/sql/sql_time.h index d560edc296e..260e6e36268 100644 --- a/sql/sql_time.h +++ b/sql/sql_time.h @@ -44,13 +44,13 @@ bool str_to_datetime_with_warn(CHARSET_INFO *cs, const char *str, ulonglong flags); bool double_to_datetime_with_warn(double value, MYSQL_TIME *ltime, ulonglong fuzzydate, - const char *name); + const TABLE_SHARE *s, const char *name); bool decimal_to_datetime_with_warn(const my_decimal *value, MYSQL_TIME *ltime, ulonglong fuzzydate, - const char *name); + const TABLE_SHARE *s, const char *name); bool int_to_datetime_with_warn(bool neg, ulonglong value, MYSQL_TIME *ltime, ulonglong fuzzydate, - const char *name); + const TABLE_SHARE *s, const char *name); bool time_to_datetime(THD *thd, const MYSQL_TIME *tm, MYSQL_TIME *dt); bool time_to_datetime_with_warn(THD *thd, @@ -120,15 +120,15 @@ void make_truncated_value_warning(THD *thd, Sql_condition::enum_warning_level level, const ErrConv *str_val, timestamp_type time_type, - const char *field_name); + const TABLE_SHARE *s, const char *field_name); static inline void make_truncated_value_warning(THD *thd, Sql_condition::enum_warning_level level, const char *str_val, uint str_length, timestamp_type time_type, - const char *field_name) + const TABLE_SHARE *s, const char *field_name) { const ErrConvString str(str_val, str_length, &my_charset_bin); - make_truncated_value_warning(thd, level, &str, time_type, field_name); + make_truncated_value_warning(thd, level, &str, time_type, s, field_name); } extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type, diff --git a/sql/table.h b/sql/table.h index 4cd5c3ba5f3..b8bd0c86ff4 100644 --- a/sql/table.h +++ b/sql/table.h @@ -625,6 +625,16 @@ struct TABLE_SHARE LEX_STRING normalized_path; /* unpack_filename(path) */ LEX_STRING connect_string; + const char* orig_table_name; /* Original table name for this tmp table */ + const char* error_table_name() const /* Get table name for error messages */ + { + return tmp_table ? ( + orig_table_name ? + orig_table_name : + "(temporary)") : + table_name.str; + } + /* Set of keys in use, implemented as a Bitmap. Excludes keys disabled by ALTER TABLE ... DISABLE KEYS. |