mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
References lp:1066784 - bzr merge lp:maria/5.5 (rev: 3562)
This commit is contained in:
@ -2563,6 +2563,8 @@ int handler::update_auto_increment()
|
||||
bool append= FALSE;
|
||||
THD *thd= table->in_use;
|
||||
struct system_variables *variables= &thd->variables;
|
||||
int result=0, tmp;
|
||||
enum enum_check_fields save_count_cuted_fields;
|
||||
DBUG_ENTER("handler::update_auto_increment");
|
||||
|
||||
/*
|
||||
@ -2580,8 +2582,10 @@ int handler::update_auto_increment()
|
||||
statement (case of INSERT VALUES(null),(3763),(null):
|
||||
the last NULL needs to insert 3764, not the value of the first NULL plus
|
||||
1).
|
||||
Ignore negative values.
|
||||
*/
|
||||
adjust_next_insert_id_after_explicit_value(nr);
|
||||
if ((longlong) nr > 0 || (table->next_number_field->flags & UNSIGNED_FLAG))
|
||||
adjust_next_insert_id_after_explicit_value(nr);
|
||||
insert_id_for_cur_row= 0; // didn't generate anything
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
@ -2640,7 +2644,6 @@ int handler::update_auto_increment()
|
||||
else
|
||||
nb_desired_values= AUTO_INC_DEFAULT_NB_MAX;
|
||||
}
|
||||
/* This call ignores all its parameters but nr, currently */
|
||||
get_auto_increment(variables->auto_increment_offset,
|
||||
variables->auto_increment_increment,
|
||||
nb_desired_values, &nr,
|
||||
@ -2677,32 +2680,28 @@ int handler::update_auto_increment()
|
||||
}
|
||||
|
||||
if (unlikely(nr == ULONGLONG_MAX))
|
||||
DBUG_RETURN(HA_ERR_AUTOINC_ERANGE);
|
||||
|
||||
DBUG_PRINT("info",("auto_increment: %lu", (ulong) nr));
|
||||
|
||||
if (unlikely(table->next_number_field->store((longlong) nr, TRUE)))
|
||||
{
|
||||
/*
|
||||
first test if the query was aborted due to strict mode constraints
|
||||
*/
|
||||
if (killed_mask_hard(thd->killed) == KILL_BAD_DATA)
|
||||
DBUG_RETURN(HA_ERR_AUTOINC_ERANGE);
|
||||
|
||||
DBUG_PRINT("info",("auto_increment: %llu",nr));
|
||||
|
||||
/* Store field without warning (Warning will be printed by insert) */
|
||||
save_count_cuted_fields= thd->count_cuted_fields;
|
||||
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
|
||||
tmp= table->next_number_field->store((longlong) nr, TRUE);
|
||||
thd->count_cuted_fields= save_count_cuted_fields;
|
||||
|
||||
if (unlikely(tmp)) // Out of range value in store
|
||||
{
|
||||
/*
|
||||
field refused this value (overflow) and truncated it, use the result of
|
||||
the truncation (which is going to be inserted); however we try to
|
||||
decrease it to honour auto_increment_* variables.
|
||||
That will shift the left bound of the reserved interval, we don't
|
||||
bother shifting the right bound (anyway any other value from this
|
||||
interval will cause a duplicate key).
|
||||
It's better to return an error here than getting a confusing
|
||||
'duplicate key error' later.
|
||||
*/
|
||||
nr= prev_insert_id(table->next_number_field->val_int(), variables);
|
||||
if (unlikely(table->next_number_field->store((longlong) nr, TRUE)))
|
||||
nr= table->next_number_field->val_int();
|
||||
result= HA_ERR_AUTOINC_ERANGE;
|
||||
}
|
||||
if (append)
|
||||
{
|
||||
DBUG_PRINT("info",("nb_reserved_values: %llu",nb_reserved_values));
|
||||
|
||||
auto_inc_interval_for_cur_row.replace(nr, nb_reserved_values,
|
||||
variables->auto_increment_increment);
|
||||
auto_inc_intervals_count++;
|
||||
@ -2726,6 +2725,10 @@ int handler::update_auto_increment()
|
||||
already set.
|
||||
*/
|
||||
insert_id_for_cur_row= nr;
|
||||
|
||||
if (result) // overflow
|
||||
DBUG_RETURN(result);
|
||||
|
||||
/*
|
||||
Set next insert id to point to next auto-increment value to be able to
|
||||
handle multi-row statements.
|
||||
@ -2849,7 +2852,7 @@ void handler::ha_release_auto_increment()
|
||||
}
|
||||
|
||||
|
||||
void handler::print_keydup_error(uint key_nr, const char *msg)
|
||||
void handler::print_keydup_error(uint key_nr, const char *msg, myf errflag)
|
||||
{
|
||||
/* Write the duplicated key in the error message */
|
||||
char key[MAX_KEY_LENGTH];
|
||||
@ -2859,7 +2862,7 @@ void handler::print_keydup_error(uint key_nr, const char *msg)
|
||||
{
|
||||
/* Key is unknown */
|
||||
str.copy("", 0, system_charset_info);
|
||||
my_printf_error(ER_DUP_ENTRY, msg, MYF(0), str.c_ptr(), "*UNKNOWN*");
|
||||
my_printf_error(ER_DUP_ENTRY, msg, errflag, str.c_ptr(), "*UNKNOWN*");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2872,7 +2875,7 @@ void handler::print_keydup_error(uint key_nr, const char *msg)
|
||||
str.append(STRING_WITH_LEN("..."));
|
||||
}
|
||||
my_printf_error(ER_DUP_ENTRY, msg,
|
||||
MYF(0), str.c_ptr_safe(), table->key_info[key_nr].name);
|
||||
errflag, str.c_ptr_safe(), table->key_info[key_nr].name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2940,7 +2943,7 @@ void handler::print_error(int error, myf errflag)
|
||||
uint key_nr=get_dup_key(error);
|
||||
if ((int) key_nr >= 0)
|
||||
{
|
||||
print_keydup_error(key_nr, ER(ER_DUP_ENTRY_WITH_KEY_NAME));
|
||||
print_keydup_error(key_nr, ER(ER_DUP_ENTRY_WITH_KEY_NAME), errflag);
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
}
|
||||
@ -3103,7 +3106,10 @@ void handler::print_error(int error, myf errflag)
|
||||
textno= ER_AUTOINC_READ_FAILED;
|
||||
break;
|
||||
case HA_ERR_AUTOINC_ERANGE:
|
||||
textno= ER_WARN_DATA_OUT_OF_RANGE;
|
||||
textno= error;
|
||||
my_error(textno, errflag, table->next_number_field->field_name,
|
||||
table->in_use->warning_info->current_row_for_warning());
|
||||
DBUG_VOID_RETURN;
|
||||
break;
|
||||
case HA_ERR_TOO_MANY_CONCURRENT_TRXS:
|
||||
textno= ER_TOO_MANY_CONCURRENT_TRXS;
|
||||
@ -4620,7 +4626,20 @@ int handler::read_range_first(const key_range *start_key,
|
||||
DBUG_RETURN((result == HA_ERR_KEY_NOT_FOUND)
|
||||
? HA_ERR_END_OF_FILE
|
||||
: result);
|
||||
DBUG_RETURN (compare_key(end_range) <= 0 ? 0 : HA_ERR_END_OF_FILE);
|
||||
|
||||
if (compare_key(end_range) <= 0)
|
||||
{
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
The last read row does not fall in the range. So request
|
||||
storage engine to release row lock if possible.
|
||||
*/
|
||||
unlock_row();
|
||||
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4652,7 +4671,20 @@ int handler::read_range_next()
|
||||
result= ha_index_next(table->record[0]);
|
||||
if (result)
|
||||
DBUG_RETURN(result);
|
||||
DBUG_RETURN(compare_key(end_range) <= 0 ? 0 : HA_ERR_END_OF_FILE);
|
||||
|
||||
if (compare_key(end_range) <= 0)
|
||||
{
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
The last read row does not fall in the range. So request
|
||||
storage engine to release row lock if possible.
|
||||
*/
|
||||
unlock_row();
|
||||
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user