1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

LAST_INSERT_ID()}will now return 0 if the last INSERT didn't insert any rows.

This commit is contained in:
monty@narttu.mysql.fi
2003-06-15 12:34:04 +03:00
parent 1e62d6070a
commit d33cb08eb6
2 changed files with 14 additions and 3 deletions

View File

@ -308,6 +308,11 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
}
thd->row_count++;
}
/*
Now all rows are inserted. Time to update logs and sends response to
user
*/
if (lock_type == TL_WRITE_DELAYED)
{
if (!error)
@ -341,7 +346,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
}
if (id && values_list.elements != 1)
thd->insert_id(id); // For update log
else if (table->next_number_field)
else if (table->next_number_field && info.copied)
id=table->next_number_field->val_int(); // Return auto_increment value
/*
@ -383,9 +388,15 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
thd->next_insert_id=0; // Reset this if wrongly used
if (duplic != DUP_ERROR)
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
/* Reset value of LAST_INSERT_ID if no rows where inserted */
if (!info.copied && thd->insert_id_used)
{
thd->insert_id(0);
id=0;
}
if (error)
goto abort;
if (values_list.elements == 1 && (!(thd->options & OPTION_WARNINGS) ||
!thd->cuted_fields))
send_ok(thd,info.copied+info.deleted,id);