diff options
Diffstat (limited to 'sql/unireg.cc')
-rw-r--r-- | sql/unireg.cc | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/sql/unireg.cc b/sql/unireg.cc index 72960640b1b..82f91d1da68 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -42,7 +42,7 @@ 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, ulong data_offset); -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, @@ -144,7 +144,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, data_offset)) goto err; @@ -220,7 +220,7 @@ err3: keys number of keys to create key_info Keys to create db_file Handler to use. May be zero, in which case we use - create_info->db_type + create_info->db_type RETURN 0 ok 1 error @@ -234,11 +234,11 @@ int rea_create_table(THD *thd, my_string file_name, DBUG_ENTER("rea_create_table"); if (mysql_create_frm(thd, file_name, create_info, - create_fields, keys, key_info, NULL)) + create_fields, keys, key_info, NULL)) DBUG_RETURN(1); - if (ha_create_table(file_name,create_info,0)) + if (!create_info->frm_only && ha_create_table(file_name,create_info,0)) { - my_delete(file_name,MYF(0)); + my_delete(file_name,MYF(0)); DBUG_RETURN(1); } DBUG_RETURN(0); @@ -343,7 +343,7 @@ static uint pack_keys(uchar *keybuff, uint key_count, KEY *keyinfo, pos[6]=pos[7]=0; // For the future pos+=8; key_parts+=key->key_parts; - DBUG_PRINT("loop",("flags: %d key_parts: %d at %lx", + DBUG_PRINT("loop",("flags: %d key_parts: %d at 0x%lx", key->flags,key->key_parts, key->key_part)); for (key_part=key->key_part,key_part_end=key_part+key->key_parts ; @@ -408,7 +408,7 @@ static bool pack_header(uchar *forminfo, enum db_type table_type, if (create_fields.elements > MAX_FIELDS) { - my_error(ER_TOO_MANY_FIELDS,MYF(0)); + my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0)); DBUG_RETURN(1); } @@ -495,7 +495,7 @@ static bool pack_header(uchar *forminfo, enum db_type table_type, if (info_length+(ulong) create_fields.elements*FCOMP+288+ n_length+int_length+com_length > 65535L || int_count > 255) { - my_error(ER_TOO_MANY_FIELDS,MYF(0)); + my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0)); DBUG_RETURN(1); } @@ -518,6 +518,7 @@ static bool pack_header(uchar *forminfo, enum db_type table_type, int2store(forminfo+280,22); /* Rows needed */ int2store(forminfo+282,null_fields); int2store(forminfo+284,com_length); + /* Up to forminfo+288 is free to use for additional information */ DBUG_RETURN(0); } /* pack_header */ @@ -657,7 +658,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, @@ -665,15 +666,17 @@ static bool make_empty_rec(File file,enum db_type table_type, { int error; Field::utype type; - uint firstpos,null_count; + uint firstpos, null_count; uchar *buff,*null_pos; 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 */ bzero((char*) &table,sizeof(table)); + table.s= &table.share_not_to_be_used; handler= get_new_handler((TABLE*) 0, table_type); if (!handler || @@ -683,26 +686,30 @@ static bool make_empty_rec(File file,enum db_type table_type, DBUG_RETURN(1); } - table.in_use= current_thd; - table.db_low_byte_first= handler->low_byte_first(); - table.blob_ptr_size=portable_sizeof_char_ptr; + table.in_use= thd; + table.s->db_low_byte_first= handler->low_byte_first(); + table.s->blob_ptr_size= portable_sizeof_char_ptr; - firstpos=reclength; null_count=0; if (!(table_options & HA_OPTION_PACK_RECORD)) + { null_count++; // Need one bit for delete mark + *buff|= 1; + } DBUG_ASSERT(data_offset == ((null_fields + null_count + 7) / 8)); - bfill(buff, (uint) data_offset, 255); - null_pos=buff; + 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++)) { + /* + regfield don't have to be deleted as it's allocated with sql_alloc() + */ Field *regfield=make_field((char*) buff+field->offset + data_offset, field->length, - field->flags & NOT_NULL_FLAG ? 0: - null_pos+null_count/8, - 1 << (null_count & 7), + null_pos + null_count / 8, + null_count & 7, field->pack_flag, field->sql_type, field->charset, @@ -711,20 +718,31 @@ static bool make_empty_rec(File file,enum db_type table_type, field->interval, field->field_name, &table); + if (!regfield) + goto err; // End of memory if (!(field->flags & NOT_NULL_FLAG)) + { + *regfield->null_ptr|= regfield->null_bit; null_count++; + } - if ((uint) (field->offset + data_offset) < firstpos && - regfield->type() != FIELD_TYPE_NULL) - firstpos= field->offset + data_offset; + if (field->sql_type == FIELD_TYPE_BIT && !f_bit_as_char(field->pack_flag)) + null_count+= field->length & 7; type= (Field::utype) MTYP_TYPENR(field->unireg_check); 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)) { @@ -737,13 +755,17 @@ static bool make_empty_rec(File file,enum db_type table_type, regfield->store(ER(ER_NO), (uint) strlen(ER(ER_NO)),system_charset_info); else regfield->reset(); - delete regfield; } /* Fill not used startpos */ - bfill((byte*) buff+data_offset, firstpos- (uint) data_offset, 255); + if (null_count) + *(null_pos + null_count / 8)|= ~(((uchar) 1 << (null_count & 7)) - 1); + 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 */ |