Commit eb137c06 authored by venu@myvenu.com's avatar venu@myvenu.com

Support of warnings for all DML statements (Insert, Update and Alter)

Fix LOAD DATA INFILE warnings to have a better meanigful messages
Fix to make the mysql command line to automatically show the warnings count for all basic commands
parent 23a522c0
......@@ -275,9 +275,10 @@
#define ER_ZLIB_Z_BUF_ERROR 1256
#define ER_ZLIB_Z_DATA_ERROR 1257
#define ER_CUT_VALUE_GROUP_CONCAT 1258
#define ER_WARN_TOO_FEW_RECORDS 1259
#define ER_WARN_TOO_FEW_RECORDS 1259
#define ER_WARN_TOO_MANY_RECORDS 1260
#define ER_WARN_DATA_TRUNCATED 1261
#define ER_WARN_NULL_TO_NOTNULL 1262
#define ER_ERROR_MESSAGES 263
#define ER_WARN_NULL_TO_NOTNULL 1261
#define ER_WARN_DATA_OUT_OF_RANGE 1262
#define ER_WARN_DATA_TRUNCATED 1263
#define ER_ERROR_MESSAGES 264
This diff is collapsed.
......@@ -210,6 +210,8 @@ class Field
virtual bool get_time(TIME *ltime);
virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
virtual void set_charset(CHARSET_INFO *charset) { }
virtual void set_warning(const unsigned int level,
const unsigned int code);
friend bool reopen_table(THD *,struct st_table *,bool);
friend int cre_myisam(my_string name, register TABLE *form, uint options,
ulonglong auto_increment_value);
......@@ -1108,7 +1110,7 @@ bool set_field_to_null(Field *field);
bool set_field_to_null_with_conversions(Field *field, bool no_conversions);
uint find_enum(TYPELIB *typelib,const char *x, uint length);
ulonglong find_set(TYPELIB *typelib,const char *x, uint length,
char **err_pos, uint *err_len);
char **err_pos, uint *err_len, bool *set_warning);
bool test_if_int(const char *str, int length, const char *int_end,
CHARSET_INFO *cs);
......
......@@ -121,7 +121,7 @@ set_field_to_null(Field *field)
field->reset();
if (current_thd->count_cuted_fields)
{
current_thd->cuted_fields++; // Increment error counter
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,ER_WARN_DATA_TRUNCATED);
return 0;
}
if (!current_thd->no_errors)
......@@ -175,7 +175,7 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions)
return 0; // field is set in handler.cc
if (current_thd->count_cuted_fields)
{
current_thd->cuted_fields++; // Increment error counter
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,ER_WARN_NULL_TO_NOTNULL);
return 0;
}
if (!current_thd->no_errors)
......@@ -225,7 +225,8 @@ static void do_copy_not_null(Copy_field *copy)
{
if (*copy->from_null_ptr & copy->from_bit)
{
current_thd->cuted_fields++;
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DATA_TRUNCATED);
copy->to_field->reset();
}
else
......@@ -324,7 +325,8 @@ static void do_cut_string(Copy_field *copy)
{
if (!my_isspace(system_charset_info, *ptr)) // QQ: ucs incompatible
{
current_thd->cuted_fields++; // Give a warning
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DATA_TRUNCATED);
break;
}
}
......@@ -344,7 +346,8 @@ static void do_varstring(Copy_field *copy)
{
length=copy->to_length-2;
if (current_thd->count_cuted_fields)
current_thd->cuted_fields++; // Increment error counter
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DATA_TRUNCATED);
}
int2store(copy->to_ptr,length);
memcpy(copy->to_ptr+2, copy->from_ptr,length);
......
......@@ -1010,6 +1010,7 @@ bool sys_var::check_enum(THD *thd, set_var *var, TYPELIB *enum_names)
bool sys_var::check_set(THD *thd, set_var *var, TYPELIB *enum_names)
{
bool not_used;
char buff[80], *error= 0;
uint error_len= 0;
String str(buff, sizeof(buff), system_charset_info), *res;
......@@ -1019,7 +1020,7 @@ bool sys_var::check_set(THD *thd, set_var *var, TYPELIB *enum_names)
if (!(res= var->value->val_str(&str)))
goto err;
var->save_result.ulong_value= (ulong)
find_set(enum_names, res->c_ptr(), res->length(), &error, &error_len);
find_set(enum_names, res->c_ptr(), res->length(), &error, &error_len, &not_used);
if (error_len)
{
strmake(buff, error, min(sizeof(buff), error_len));
......
......@@ -260,8 +260,10 @@
"Z_MEM_ERROR: Not enough room in the output buffer for zlib (probably, length of uncompressed data was corrupted)"
"Z_DATA_ERROR: Input data was corrupted for zlib"
"%d line(s) was(were) cut by group_concat()";
"Value count is fewer than the column count at row %ld";
"Value count is more than the column count at row %ld";
"Data truncated for column '%s' at row %ld";
"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld"
"Record count is fewer than the column count at row %ld";
"Record count is more than the column count at row %ld";
"Data truncated, NULL supplied to NOT NULL column '%s' at row %ld";
"Data truncated, out of range for column '%s' at row %ld";
"Data truncated for column '%s' at row %ld"
......@@ -512,6 +512,7 @@ class THD :public ilink
ulong query_id, warn_id, version, options, thread_id, col_access;
ulong current_stmt_id;
ulong rand_saved_seed1, rand_saved_seed2;
ulong row_count; // Row counter, mainly for errors and warnings
long dbug_thread_id;
pthread_t real_id;
uint current_tablenr,tmp_table,cond_count;
......@@ -530,6 +531,7 @@ class THD :public ilink
uint8 query_cache_type; // type of query cache processing
bool slave_thread;
bool set_query_id,locked,count_cuted_fields,some_tables_deleted;
bool last_cuted_field;
bool no_errors, allow_sum_func, password, is_fatal_error;
bool query_start_used,last_insert_id_used,insert_id_used,rand_used;
bool system_thread,in_lock_tables,global_read_lock;
......
......@@ -79,6 +79,7 @@ void mysql_reset_errors(THD *thd)
free_root(&thd->warn_root,MYF(0));
bzero((char*) thd->warn_count, sizeof(thd->warn_count));
thd->warn_list.empty();
thd->row_count= 1; // by default point to row 1
}
DBUG_VOID_RETURN;
}
......
......@@ -297,6 +297,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
{ // Get auto increment value
id= thd->last_insert_id;
}
thd->row_count++;
}
if (lock_type == TL_WRITE_DELAYED)
{
......
......@@ -368,11 +368,10 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields,
List_iterator_fast<Item> it(fields);
Item_field *sql_field;
ulonglong id;
ulong row_pos;
DBUG_ENTER("read_fixed_length");
id= 0;
row_pos= 1;
/* No fields can be null in this format. mark all fields as not null */
while ((sql_field= (Item_field*) it++))
sql_field->field->set_notnull();
......@@ -391,14 +390,14 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields,
#endif
while ((sql_field= (Item_field*) it++))
{
Field *field=sql_field->field;
Field *field= sql_field->field;
if (pos == read_info.row_end)
{
thd->cuted_fields++; /* Not enough fields */
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_TOO_FEW_RECORDS,
ER(ER_WARN_TOO_FEW_RECORDS), row_pos);
field->reset();
ER(ER_WARN_TOO_FEW_RECORDS), thd->row_count);
field->reset();
}
else
{
......@@ -408,13 +407,7 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields,
field->field_length)
length=field->field_length;
save_chr=pos[length]; pos[length]='\0'; // Safeguard aganst malloc
if (field->store((char*) pos,length,read_info.read_charset))
{
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DATA_TRUNCATED,
ER(ER_WARN_DATA_TRUNCATED),
field->field_name, row_pos);
}
field->store((char*) pos,length,read_info.read_charset);
pos[length]=save_chr;
if ((pos+=length) > read_info.row_end)
pos= read_info.row_end; /* Fills rest with space */
......@@ -425,7 +418,7 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields,
thd->cuted_fields++; /* To long row */
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_TOO_MANY_RECORDS,
ER(ER_WARN_TOO_MANY_RECORDS), row_pos);
ER(ER_WARN_TOO_MANY_RECORDS), thd->row_count);
}
if (write_record(table,&info))
DBUG_RETURN(1);
......@@ -446,9 +439,9 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields,
thd->cuted_fields++; /* To long row */
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_TOO_MANY_RECORDS,
ER(ER_WARN_TOO_MANY_RECORDS), row_pos);
ER(ER_WARN_TOO_MANY_RECORDS), thd->row_count);
}
row_pos++;
thd->row_count++;
}
if (id && !read_info.error)
thd->insert_id(id); // For binary/update log
......@@ -466,12 +459,10 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
Item_field *sql_field;
uint enclosed_length;
ulonglong id;
ulong row_pos;
DBUG_ENTER("read_sep_field");
enclosed_length=enclosed.length();
id= 0;
row_pos= 1;
for (;;it.rewind())
{
......@@ -501,27 +492,15 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
{
if (field->type() == FIELD_TYPE_TIMESTAMP)
((Field_timestamp*) field)->set_time();
else if (field != table->next_number_field)
{
thd->cuted_fields++;
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_NULL_TO_NOTNULL,
ER(ER_WARN_NULL_TO_NOTNULL),
field->field_name, row_pos);
}
else if (field != table->next_number_field)
field->set_warning((uint)MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_NULL_TO_NOTNULL);
}
continue;
}
field->set_notnull();
read_info.row_end[0]=0; // Safe to change end marker
if (field->store((char*) read_info.row_start,length,read_info.read_charset))
{
// Data truncated or out of bounds
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DATA_TRUNCATED,
ER(ER_WARN_DATA_TRUNCATED),
field->field_name, row_pos);
}
field->store((char*) read_info.row_start,length,read_info.read_charset);
}
if (read_info.error)
break;
......@@ -536,7 +515,7 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
thd->cuted_fields++;
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_TOO_FEW_RECORDS,
ER(ER_WARN_TOO_FEW_RECORDS), row_pos);
ER(ER_WARN_TOO_FEW_RECORDS), thd->row_count);
}
}
if (write_record(table,&info))
......@@ -557,10 +536,10 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
{
thd->cuted_fields++; /* To long row */
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_TOO_MANY_RECORDS,
ER(ER_WARN_TOO_MANY_RECORDS), row_pos);
ER_WARN_TOO_MANY_RECORDS, ER(ER_WARN_TOO_MANY_RECORDS),
thd->row_count);
}
row_pos++;
thd->row_count++;
}
if (id && !read_info.error)
thd->insert_id(id); // For binary/update log
......
......@@ -3653,12 +3653,13 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
{
char *not_used;
uint not_used2;
bool not_used3;
thd->cuted_fields=0;
String str,*res;
res=default_value->val_str(&str);
(void) find_set(interval, res->ptr(), res->length(), &not_used,
&not_used2);
&not_used2, &not_used3);
if (thd->cuted_fields)
{
net_printf(thd,ER_INVALID_DEFAULT,field_name);
......
......@@ -5018,6 +5018,7 @@ sub_select(JOIN *join,JOIN_TAB *join_tab,bool end_of_records)
ha_rows found_records=join->found_records;
READ_RECORD *info= &join_tab->read_record;
join->thd->row_count= 0;
do
{
if (join->thd->killed) // Aborted by user
......@@ -5026,6 +5027,7 @@ sub_select(JOIN *join,JOIN_TAB *join_tab,bool end_of_records)
return -2; /* purecov: inspected */
}
join->examined_rows++;
join->thd->row_count++;
if (!on_expr || on_expr->val_int())
{
found=1;
......
......@@ -2383,6 +2383,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
handle_duplicates == DUP_REPLACE)
to->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
next_field=to->next_number_field;
thd->row_count= 0;
while (!(error=info.read_record(&info)))
{
if (thd->killed)
......@@ -2391,6 +2392,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
error= 1;
break;
}
thd->row_count++;
if (next_field)
next_field->reset();
for (Copy_field *copy_ptr=copy ; copy_ptr != copy_end ; copy_ptr++)
......@@ -2408,7 +2410,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
delete_count++;
}
else
found_count++;
found_count++;
}
end_read_record(&info);
free_io_cache(from);
......
......@@ -315,6 +315,7 @@ int mysql_update(THD *thd,
}
else
table->file->unlock_row();
thd->row_count++;
}
end_read_record(&info);
thd->proc_info="end";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment