1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Strict mode & better warnings

Under strict mode MySQL will generate an error message if there was any conversion when assigning data to a field.
Added checking of date/datetime fields.
If strict mode, give error if we have not given value to field without a default value (for INSERT)


client/mysqltest.c:
  Added --exit as an option to abort a test in a middle (good for debugging)
include/my_time.h:
  Added flags to allow checking of dates in strict mode
include/mysql_com.h:
  Added flag to check if field has a default value or not
include/mysqld_error.h:
  New error messages for strict mode
include/sql_state.h:
  Fixed SQL states (for strict mode tests)
mysql-test/r/auto_increment.result:
  Updated error messages
mysql-test/r/func_sapdb.result:
  Added test for ALLOW_INVALID_DATES
mysql-test/r/func_str.result:
  Updated error messages
mysql-test/r/func_time.result:
  Updated error messages
mysql-test/r/insert.result:
  Updated error messages
mysql-test/r/loaddata.result:
  Updated error messages
mysql-test/r/select.result:
  Updated error messages
mysql-test/r/sp.result:
  Updated error messages
mysql-test/r/timezone2.result:
  Updated error messages
mysql-test/r/type_datetime.result:
  Updated error messages
mysql-test/r/type_decimal.result:
  Updated error messages
mysql-test/r/type_float.result:
  Updated error messages
mysql-test/r/type_ranges.result:
  Updated error messages
mysql-test/r/type_time.result:
  Updated error messages
mysql-test/r/type_uint.result:
  Updated error messages
mysql-test/r/warnings.result:
  Updated error messages
mysql-test/t/func_sapdb.test:
  Aded test
sql-common/my_time.c:
  Added checking of dates
sql/field.cc:
  Better error messages
  Optimization of warning handling (by introducing of check_int())
  Changed to use my_strtoll10()
sql/field.h:
  Added check_int()
sql/item_func.cc:
  Warnings when dividing by NULL
sql/item_func.h:
  Warnings when dividing by NULL
sql/item_timefunc.cc:
  Testing of date/datetime
  Use macros instead of constants
sql/mysql_priv.h:
  New modes (part of strict mode)
sql/mysqld.cc:
  New modes (part of strict mode)
sql/opt_range.cc:
  Simple optimizations
sql/protocol.cc:
  Add note/warning level to find_handler()
sql/set_var.cc:
  Added mode 'traditional'
sql/share/czech/errmsg.txt:
  New error messages for strict mode
sql/share/danish/errmsg.txt:
  New error messages for strict mode
sql/share/dutch/errmsg.txt:
  New error messages for strict mode
sql/share/english/errmsg.txt:
  New error messages for strict mode
sql/share/estonian/errmsg.txt:
  New error messages for strict mode
sql/share/french/errmsg.txt:
  New error messages for strict mode
sql/share/german/errmsg.txt:
  New error messages for strict mode
sql/share/greek/errmsg.txt:
  New error messages for strict mode
sql/share/hungarian/errmsg.txt:
  New error messages for strict mode
sql/share/italian/errmsg.txt:
  New error messages for strict mode
sql/share/japanese/errmsg.txt:
  New error messages for strict mode
sql/share/korean/errmsg.txt:
  New error messages for strict mode
sql/share/norwegian-ny/errmsg.txt:
  New error messages for strict mode
sql/share/norwegian/errmsg.txt:
  New error messages for strict mode
sql/share/polish/errmsg.txt:
  New error messages for strict mode
sql/share/portuguese/errmsg.txt:
  New error messages for strict mode
sql/share/romanian/errmsg.txt:
  New error messages for strict mode
sql/share/russian/errmsg.txt:
  New error messages for strict mode
sql/share/serbian/errmsg.txt:
  New error messages for strict mode
sql/share/slovak/errmsg.txt:
  New error messages for strict mode
sql/share/spanish/errmsg.txt:
  New error messages for strict mode
sql/share/swedish/errmsg.txt:
  New error messages for strict mode
sql/share/ukrainian/errmsg.txt:
  New error messages for strict mode
sql/sp_rcontext.cc:
  Add note/warning level to find_handler()
sql/sp_rcontext.h:
  Add note/warning level to find_handler()
sql/sql_base.cc:
  Fix bug for detecting crashed table
sql/sql_class.cc:
  Variables for strct mode
sql/sql_class.h:
  Variables for strct mode
sql/sql_error.cc:
  In strict mode, convert warnings to errors
sql/sql_insert.cc:
  Strict mode
  If strict mode, give error if we have not given value to field without a default value
sql/sql_load.cc:
  Strict mode
sql/sql_parse.cc:
  Strict mode.
  Add flag to field if it doesn't have a default value
sql/sql_select.cc:
  Added comment
  Prepare for upper level handling of table->status
sql/sql_union.cc:
  Added THD to write_record()
sql/sql_update.cc:
  Strict mode
sql/table.cc:
  Handling of default values
sql/time.cc:
  Checking of dates
This commit is contained in:
unknown
2004-09-28 20:08:00 +03:00
parent e74b00bbc9
commit 2a49121590
72 changed files with 1965 additions and 446 deletions

View File

@@ -270,13 +270,24 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
if (lock_type != TL_WRITE_DELAYED)
table->file->start_bulk_insert(values_list.elements);
thd->no_trans_update= 0;
thd->abort_on_warning= (duplic != DUP_IGNORE &&
(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)));
if (check_that_all_fields_are_given_values(thd, table))
{
/* thd->net.report_error is now set, which will abort the next loop */
error= 1;
}
while ((values= its++))
{
if (fields.elements || !value_count)
{
restore_record(table,default_values); // Get empty record
if (fill_record(fields, *values, 0)|| thd->net.report_error ||
check_null_fields(thd,table))
if (fill_record(fields, *values, 0)|| thd->net.report_error)
{
if (values_list.elements != 1 && !thd->net.report_error)
{
@@ -305,10 +316,13 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
}
}
// FIXME: Actually we should do this before check_null_fields.
// Or even go into write_record ?
/*
FIXME: Actually we should do this before
check_that_all_fields_are_given_values Or even go into write_record ?
*/
if (table->triggers)
table->triggers->process_triggers(thd, TRG_EVENT_INSERT, TRG_ACTION_BEFORE);
table->triggers->process_triggers(thd, TRG_EVENT_INSERT,
TRG_ACTION_BEFORE);
#ifndef EMBEDDED_LIBRARY
if (lock_type == TL_WRITE_DELAYED)
@@ -318,7 +332,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
}
else
#endif
error=write_record(table,&info);
error=write_record(thd, table ,&info);
/*
If auto_increment values are used, save the first one
for LAST_INSERT_ID() and for the update log.
@@ -447,6 +461,7 @@ abort:
#endif
free_underlaid_joins(thd, &thd->lex->select_lex);
table->insert_values=0;
thd->abort_on_warning= 0;
DBUG_RETURN(-1);
}
@@ -633,10 +648,12 @@ static int last_uniq_key(TABLE *table,uint keynr)
/*
Write a record to table with optional deleting of conflicting records
Sets thd->no_trans_update if table which is updated didn't have transactions
*/
int write_record(TABLE *table,COPY_INFO *info)
int write_record(THD *thd, TABLE *table,COPY_INFO *info)
{
int error;
char *key=0;
@@ -735,6 +752,8 @@ int write_record(TABLE *table,COPY_INFO *info)
else if ((error=table->file->delete_row(table->record[1])))
goto err;
info->deleted++;
if (!table->file->has_transactions())
thd->no_trans_update= 1;
}
}
info->copied++;
@@ -750,6 +769,8 @@ int write_record(TABLE *table,COPY_INFO *info)
info->copied++;
if (key)
my_safe_afree(key,table->max_unique_length,MAX_KEY_LENGTH);
if (!table->file->has_transactions())
thd->no_trans_update= 1;
DBUG_RETURN(0);
err:
@@ -767,22 +788,22 @@ err:
fields.
******************************************************************************/
static int check_null_fields(THD *thd __attribute__((unused)),
TABLE *entry __attribute__((unused)))
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry)
{
#ifdef DONT_USE_DEFAULT_FIELDS
if (!thd->abort_on_warning)
return 0;
for (Field **field=entry->field ; *field ; field++)
{
if ((*field)->query_id != thd->query_id && !(*field)->maybe_null() &&
*field != entry->timestamp_field &&
*field != entry->next_number_field)
if ((*field)->query_id != thd->query_id &&
((*field)->flags & NO_DEFAULT_VALUE_FLAG))
{
my_printf_error(ER_BAD_NULL_ERROR, ER(ER_BAD_NULL_ERROR),MYF(0),
my_printf_error(ER_NO_DEFAULT_FOR_FIELD,
ER(ER_NO_DEFAULT_FOR_FIELD),MYF(0),
(*field)->field_name);
return 1;
}
}
#endif
return 0;
}
@@ -1503,7 +1524,7 @@ bool delayed_insert::handle_inserts(void)
using_ignore=1;
}
thd.clear_error(); // reset error for binlog
if (write_record(table,&info))
if (write_record(&thd, table, &info))
{
info.error_count++; // Ignore errors
thread_safe_increment(delayed_insert_errors,&LOCK_delayed_status);
@@ -1640,7 +1661,12 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
info.handle_duplicates == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
table->file->start_bulk_insert((ha_rows) 0);
DBUG_RETURN(0);
thd->no_trans_update= 0;
thd->abort_on_warning= (info.handle_duplicates != DUP_IGNORE &&
(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)));
DBUG_RETURN(check_that_all_fields_are_given_values(thd, table));
}
@@ -1659,6 +1685,7 @@ select_insert::~select_insert()
table->file->reset();
}
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
thd->abort_on_warning= 0;
DBUG_VOID_RETURN;
}
@@ -1675,7 +1702,7 @@ bool select_insert::send_data(List<Item> &values)
fill_record(*fields, values, 1);
else
fill_record(table->field, values, 1);
if (thd->net.report_error || write_record(table,&info))
if (thd->net.report_error || write_record(thd, table, &info))
DBUG_RETURN(1);
if (table->next_number_field) // Clear for next record
{
@@ -1824,7 +1851,12 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
info.handle_duplicates == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
table->file->start_bulk_insert((ha_rows) 0);
DBUG_RETURN(0);
thd->no_trans_update= 0;
thd->abort_on_warning= (info.handle_duplicates != DUP_IGNORE &&
(thd->variables.sql_mode &
(MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES)));
DBUG_RETURN(check_that_all_fields_are_given_values(thd, table));
}
@@ -1836,7 +1868,7 @@ bool select_create::send_data(List<Item> &values)
return 0;
}
fill_record(field, values, 1);
if (thd->net.report_error ||write_record(table,&info))
if (thd->net.report_error || write_record(thd, table, &info))
return 1;
if (table->next_number_field) // Clear for next record
{