diff options
author | unknown <monty@mysql.com> | 2005-04-01 15:04:50 +0300 |
---|---|---|
committer | unknown <monty@mysql.com> | 2005-04-01 15:04:50 +0300 |
commit | db7561ecf8b703e285320f2e0fcec7daf72ca9d6 (patch) | |
tree | 7920c948db7d0f2174fb24ba26cd648144fa4850 /sql/sql_table.cc | |
parent | 750180d2998cc7d04e4a0fb4ccec8b5214c3f145 (diff) | |
download | mariadb-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/sql_table.cc')
-rw-r--r-- | sql/sql_table.cc | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc index b125eeaf03a..7f5c3a52017 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -620,11 +620,12 @@ int prepare_create_field(create_field *sql_field, -1 error */ -int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, - List<create_field> &fields, - List<Key> &keys, bool tmp_table, uint &db_options, - handler *file, KEY *&key_info_buffer, - uint *key_count, int select_field_count) +static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, + List<create_field> *fields, + List<Key> *keys, bool tmp_table, + uint *db_options, + handler *file, KEY **key_info_buffer, + uint *key_count, int select_field_count) { const char *key_name; create_field *sql_field,*dup_field; @@ -636,11 +637,11 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, int timestamps= 0, timestamps_with_niladic= 0; int field_no,dup_no; int select_field_pos,auto_increment=0; - List_iterator<create_field> it(fields),it2(fields); + List_iterator<create_field> it(*fields),it2(*fields); uint total_uneven_bit_length= 0; DBUG_ENTER("mysql_prepare_table"); - select_field_pos=fields.elements - select_field_count; + select_field_pos= fields->elements - select_field_count; null_fields=blob_columns=0; create_info->varchar= 0; @@ -845,11 +846,11 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, if ((sql_field->flags & BLOB_FLAG) || sql_field->sql_type == MYSQL_TYPE_VARCHAR && create_info->row_type != ROW_TYPE_FIXED) - db_options|= HA_OPTION_PACK_RECORD; + (*db_options)|= HA_OPTION_PACK_RECORD; it2.rewind(); } /* If fixed row records, we need one bit to check for deleted rows */ - if (!(db_options & HA_OPTION_PACK_RECORD)) + if (!((*db_options) & HA_OPTION_PACK_RECORD)) null_fields++; pos= (null_fields + total_uneven_bit_length + 7) / 8; @@ -897,7 +898,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, /* Create keys */ - List_iterator<Key> key_iterator(keys), key_iterator2(keys); + List_iterator<Key> key_iterator(*keys), key_iterator2(*keys); uint key_parts=0, fk_key_count=0; bool primary_key=0,unique_key=0; Key *key, *key2; @@ -984,9 +985,9 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, DBUG_RETURN(-1); } - key_info_buffer=key_info=(KEY*) sql_calloc(sizeof(KEY)* *key_count); + (*key_info_buffer) = key_info= (KEY*) sql_calloc(sizeof(KEY)* *key_count); key_part_info=(KEY_PART_INFO*) sql_calloc(sizeof(KEY_PART_INFO)*key_parts); - if (!key_info_buffer || ! key_part_info) + if (!*key_info_buffer || ! key_part_info) DBUG_RETURN(-1); // Out of memory key_iterator.rewind(); @@ -1260,7 +1261,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } key_part_info->length=(uint16) length; /* Use packed keys for long strings on the first column */ - if (!(db_options & HA_OPTION_NO_PACK_KEYS) && + if (!((*db_options) & HA_OPTION_NO_PACK_KEYS) && (length >= KEY_DEFAULT_PACK_LENGTH && (sql_field->sql_type == MYSQL_TYPE_STRING || sql_field->sql_type == MYSQL_TYPE_VARCHAR || @@ -1291,8 +1292,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } else if (!(key_name = key->name)) key_name=make_unique_key_name(sql_field->field_name, - key_info_buffer,key_info); - if (check_if_keyname_exists(key_name,key_info_buffer,key_info)) + *key_info_buffer, key_info); + if (check_if_keyname_exists(key_name, *key_info_buffer, key_info)) { my_error(ER_DUP_KEYNAME, MYF(0), key_name); DBUG_RETURN(-1); @@ -1327,7 +1328,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, DBUG_RETURN(-1); } /* Sort keys in optimized order */ - qsort((gptr) key_info_buffer, *key_count, sizeof(KEY), + qsort((gptr) *key_info_buffer, *key_count, sizeof(KEY), (qsort_cmp) sort_keys); DBUG_RETURN(0); @@ -1393,7 +1394,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, ha_get_storage_engine(new_db_type), table_name); } - db_options=create_info->table_options; + db_options= create_info->table_options; if (create_info->row_type == ROW_TYPE_DYNAMIC) db_options|=HA_OPTION_PACK_RECORD; alias= table_case_name(create_info, table_name); @@ -1432,9 +1433,9 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, create_info->default_table_charset= db_info.default_table_charset; } - if (mysql_prepare_table(thd, create_info, fields, - keys, internal_tmp_table, db_options, file, - key_info_buffer, &key_count, + if (mysql_prepare_table(thd, create_info, &fields, + &keys, internal_tmp_table, &db_options, file, + &key_info_buffer, &key_count, select_field_count)) DBUG_RETURN(TRUE); @@ -2706,9 +2707,9 @@ int mysql_create_indexes(THD *thd, TABLE_LIST *table_list, List<Key> &keys) create_info.db_type=DB_TYPE_DEFAULT; create_info.default_table_charset= thd->variables.collation_database; db_options= 0; - if (mysql_prepare_table(thd, &create_info, fields, - keys, /*tmp_table*/ 0, db_options, table->file, - key_info_buffer, key_count, + if (mysql_prepare_table(thd, &create_info, &fields, + &keys, /*tmp_table*/ 0, &db_options, table->file, + &key_info_buffer, key_count, /*select_field_count*/ 0)) DBUG_RETURN(-1); @@ -2839,9 +2840,9 @@ int mysql_drop_indexes(THD *thd, TABLE_LIST *table_list, { db_options= 0; if (table->file->drop_index(table, key_numbers, key_count)|| - mysql_prepare_table(thd, &create_info, fields, - keys, /*tmp_table*/ 0, db_options, table->file, - key_info_buffer, key_count, + mysql_prepare_table(thd, &create_info, &fields, + &keys, /*tmp_table*/ 0, &db_options, table->file, + &key_info_buffer, key_count, /*select_field_count*/ 0)|| (snprintf(path, sizeof(path), "%s/%s/%s%s", mysql_data_home, table_list->db, (lower_case_table_names == 2)? @@ -3666,6 +3667,13 @@ copy_data_between_tables(TABLE *from,TABLE *to, if (to->file->external_lock(thd, F_WRLCK)) DBUG_RETURN(-1); + + /* We can abort alter table for any table type */ + thd->no_trans_update= 0; + thd->abort_on_warning= !ignore && test(thd->variables.sql_mode & + (MODE_STRICT_TRANS_TABLES | + MODE_STRICT_ALL_TABLES)); + from->file->info(HA_STATUS_VARIABLE); to->file->start_bulk_insert(from->file->records); @@ -3745,6 +3753,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, else to->next_number_field->reset(); } + for (Copy_field *copy_ptr=copy ; copy_ptr != copy_end ; copy_ptr++) { copy_ptr->do_copy(copy_ptr); @@ -3789,6 +3798,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, err: thd->variables.sql_mode= save_sql_mode; + thd->abort_on_warning= 0; free_io_cache(from); *copied= found_count; *deleted=delete_count; |