summaryrefslogtreecommitdiff
path: root/sql/unireg.cc
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2005-04-01 15:04:50 +0300
committerunknown <monty@mysql.com>2005-04-01 15:04:50 +0300
commitdb7561ecf8b703e285320f2e0fcec7daf72ca9d6 (patch)
tree7920c948db7d0f2174fb24ba26cd648144fa4850 /sql/unireg.cc
parent750180d2998cc7d04e4a0fb4ccec8b5214c3f145 (diff)
downloadmariadb-git-db7561ecf8b703e285320f2e0fcec7daf72ca9d6.tar.gz
Invalid DEFAULT values for CREATE TABLE now generates errors. (Bug #5902)
CAST() now produces warnings when casting a wrong INTEGER or CHAR values. This also applies to implicite string to number casts. (Bug #5912) ALTER TABLE now fails in STRICT mode if it generates warnings. Inserting a zero date in a DATE, DATETIME or TIMESTAMP column during TRADITIONAL mode now produces an error. (Bug #5933) mysql-test/r/bigint.result: New warning added mysql-test/r/cast.result: Added testing of wrong CAST's of strings to numbers and numbers to strings mysql-test/r/create.result: Added test for wrong default values (#5902) mysql-test/r/func_if.result: Changed tests to produce less warnings mysql-test/r/func_misc.result: New warning mysql-test/r/func_str.result: Added missing drop table Changed test to produce less warnings New warnings mysql-test/r/ndb_index_unique.result: Removed wrong default usage mysql-test/r/ps_1general.result: Changed tests to produce less warnings mysql-test/r/row.result: New warnings mysql-test/r/rpl_session_var.result: Changed tests to produce less warnings mysql-test/r/strict.result: New tests for CAST() and zero date handling mysql-test/r/subselect.result: Changed tests to produce less warnings mysql-test/r/type_ranges.result: Changed tests to produce less warnings mysql-test/t/cast.test: Added testing of wrong CAST's of strings to numbers and numbers to strings mysql-test/t/create.test: Added test for wrong default values (#5902) mysql-test/t/func_if.test: Changed tests to produce less warnings mysql-test/t/func_str.test: Added missing drop table Changed test to produce less warnings New warnings mysql-test/t/ndb_index_unique.test: Removed wrong default usage mysql-test/t/ps_1general.test: Changed tests to produce less warnings mysql-test/t/rpl_session_var.test: Changed tests to produce less warnings mysql-test/t/strict.test: New tests for CAST() and zero date handling mysql-test/t/subselect.test: Changed tests to produce less warnings mysql-test/t/type_ranges.test: Changed tests to produce less warnings sql/Makefile.am: Added new include file sql/field.cc: Added warnings for zero dates for DATE, DATETIME and TIMESTAMP Moved Field_blob::max_length() to a more appropriate position Changed type for 'level' in set_warning() to avoid casts sql/field.h: Changed type for 'level' in set_warning() to avoid casts sql/field_conv.cc: Copy date and datetime fields through string in 'traditional' mode to detect zero dates sql/item.cc: Removed compiler warnings Give warnings for wrong CAST of strings -> number sql/item.h: Moved Item_string::val_real() and ::val_int() to item.cc sql/item_row.cc: Better detection of null values (which doesn't produce warnings) sql/item_sum.cc: Better detection of null values (which doesn't produce warnings) sql/item_timefunc.cc: Give warnings for wrong CAST of number -> string sql/my_decimal.cc: Fixed typo in comment sql/mysql_priv.h: Removed prototype for static function Moved defines for error handling to sql_error.h (to be able to use these in field.h) sql/mysqld.cc: Simplify code sql/sql_class.h: Moved to sql_error.h sql/sql_load.cc: Removed wrong cast sql/sql_parse.cc: Fixed wrong printf() sql/sql_table.cc: Made mysql_prepare_table() static Changed references to pointers to make code more readable ALTER TABLE now aborts if one gets warnings in STRICT mode sql/time.cc: Fixed possible wrong call sql/unireg.cc: Removed one call to current_thd Give errors if one uses a wrong DEFAULT value
Diffstat (limited to 'sql/unireg.cc')
-rw-r--r--sql/unireg.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/sql/unireg.cc b/sql/unireg.cc
index 3e85767dc86..57e2c1029f1 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -40,7 +40,7 @@ static bool pack_header(uchar *forminfo,enum db_type table_type,
static uint get_interval_id(uint *int_count,List<create_field> &create_fields,
create_field *last_field);
static bool pack_fields(File file, List<create_field> &create_fields);
-static bool make_empty_rec(int file, enum db_type table_type,
+static bool make_empty_rec(THD *thd, int file, enum db_type table_type,
uint table_options,
List<create_field> &create_fields,
uint reclength,uint null_fields);
@@ -134,7 +134,7 @@ bool mysql_create_frm(THD *thd, my_string file_name,
VOID(my_seek(file,
(ulong) uint2korr(fileinfo+6)+ (ulong) key_buff_length,
MY_SEEK_SET,MYF(0)));
- if (make_empty_rec(file,create_info->db_type,create_info->table_options,
+ if (make_empty_rec(thd,file,create_info->db_type,create_info->table_options,
create_fields,reclength,null_fields))
goto err;
@@ -640,7 +640,7 @@ static bool pack_fields(File file,List<create_field> &create_fields)
/* save an empty record on start of formfile */
-static bool make_empty_rec(File file,enum db_type table_type,
+static bool make_empty_rec(THD *thd, File file,enum db_type table_type,
uint table_options,
List<create_field> &create_fields,
uint reclength, uint null_fields)
@@ -652,6 +652,7 @@ static bool make_empty_rec(File file,enum db_type table_type,
TABLE table;
create_field *field;
handler *handler;
+ enum_check_fields old_count_cuted_fields= thd->count_cuted_fields;
DBUG_ENTER("make_empty_rec");
/* We need a table to generate columns for default values */
@@ -666,7 +667,7 @@ static bool make_empty_rec(File file,enum db_type table_type,
DBUG_RETURN(1);
}
- table.in_use= current_thd;
+ table.in_use= thd;
table.s->db_low_byte_first= handler->low_byte_first();
table.s->blob_ptr_size= portable_sizeof_char_ptr;
@@ -681,6 +682,7 @@ static bool make_empty_rec(File file,enum db_type table_type,
null_pos=buff;
List_iterator<create_field> it(create_fields);
+ thd->count_cuted_fields= CHECK_FIELD_WARN; // To find wrong default values
while ((field=it++))
{
Field *regfield=make_field((char*) buff+field->offset,field->length,
@@ -709,7 +711,14 @@ static bool make_empty_rec(File file,enum db_type table_type,
if (field->def &&
(regfield->real_type() != FIELD_TYPE_YEAR ||
field->def->val_int() != 0))
- (void) field->def->save_in_field(regfield, 1);
+ {
+ if (field->def->save_in_field(regfield, 1))
+ {
+ my_error(ER_INVALID_DEFAULT, MYF(0), regfield->field_name);
+ error= 1;
+ goto err;
+ }
+ }
else if (regfield->real_type() == FIELD_TYPE_ENUM &&
(field->flags & NOT_NULL_FLAG))
{
@@ -728,7 +737,10 @@ static bool make_empty_rec(File file,enum db_type table_type,
/* Fill not used startpos */
bfill((byte*) buff+null_length,firstpos-null_length,255);
error=(int) my_write(file,(byte*) buff,(uint) reclength,MYF_RW);
+
+err:
my_free((gptr) buff,MYF(MY_FAE));
delete handler;
+ thd->count_cuted_fields= old_count_cuted_fields;
DBUG_RETURN(error);
} /* make_empty_rec */