Commit e4b0b0d0 authored by unknown's avatar unknown
Browse files

Fix bug #3443, better foreign key error messsages.


innobase/dict/dict0dict.c:
  Add 'add_newline' parameter to dict_print_info_on_foreign_key_in_create_format.
innobase/include/dict0dict.h:
  Add 'add_newline' parameter to dict_print_info_on_foreign_key_in_create_format.
innobase/include/os0file.h:
  Add os_file_read_string.
innobase/include/trx0trx.h:
  Add trx_set_detailed_error and trx_set_detailed_error_from_file functions
  and a detailed_error field to trx_struct.
innobase/include/ut0mem.h:
  Add ut_strlcpy.
innobase/os/os0file.c:
  Add os_file_read_string.
innobase/row/row0ins.c:
  Add row_ins_set_detailed function and call it when needed.
  
  Adapt to changes in dict_print_info_on_foreign_key_in_create_format.
innobase/trx/trx0trx.c:
  Add trx_set_detailed_error and trx_set_detailed_error_from_file.
  
  Clear trx->detailed_error in trx_create.
innobase/ut/ut0mem.c:
  Add ut_strlcpy.
mysql-test/r/innodb.result:
  Add new tests, adapt existing ones whose output was changed.
mysql-test/t/innodb.test:
  Add new tests, adapt existing ones whose output was changed.
sql/ha_innodb.cc:
  Add get_error_message.
  
  Clear trx->detailed_error in start_stmt and external_lock.
sql/ha_innodb.h:
  Add get_error_message.
sql/handler.cc:
  Add special case code in print_error for HA_ERR_ROW_IS_REFERENCED and
  HA_ERR_NO_REFERENCED_ROW.
  
  Change SETMSG to point to new error messages.
sql/share/errmsg.txt:
  Add ER_ROW_IS_REFERENCED_2 and ER_NO_REFERENCED_ROW_2.
parent abda6dc6
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -2189,7 +2189,7 @@ dict_foreign_error_report(
	dict_foreign_error_report_low(file, fk->foreign_table_name);
	fputs(msg, file);
	fputs(" Constraint:\n", file);
	dict_print_info_on_foreign_key_in_create_format(file, NULL, fk);
	dict_print_info_on_foreign_key_in_create_format(file, NULL, fk, TRUE);
	if (fk->foreign_index) {
		fputs("\nThe index in the foreign key in table is ", file);
		ut_print_name(file, NULL, fk->foreign_index->name);
@@ -4332,7 +4332,8 @@ dict_print_info_on_foreign_key_in_create_format(
/*============================================*/
	FILE*		file,		/* in: file where to print */
	trx_t*		trx,		/* in: transaction */
	dict_foreign_t*	foreign)/* in: foreign key constraint */
	dict_foreign_t*	foreign,	/* in: foreign key constraint */
	ibool		add_newline)	/* in: whether to add a newline */
{
	const char*	stripped_id;
	ulint	i;
@@ -4345,7 +4346,16 @@ dict_print_info_on_foreign_key_in_create_format(
		stripped_id = foreign->id;
	}

	fputs(",\n  CONSTRAINT ", file);
	putc(',', file);
	
	if (add_newline) {
		/* SHOW CREATE TABLE wants constraints each printed nicely
		on its own line, while error messages want no newlines
		inserted. */
		fputs("\n ", file);
	}
	
	fputs(" CONSTRAINT ", file);
	ut_print_name(file, trx, stripped_id);
	fputs(" FOREIGN KEY (", file);

@@ -4447,7 +4457,7 @@ dict_print_info_on_foreign_keys(
	while (foreign != NULL) {
		if (create_table_format) {
			dict_print_info_on_foreign_key_in_create_format(
						file, trx, foreign);
						file, trx, foreign, TRUE);
		} else {
			ulint	i;
			fputs("; (", file);
+4 −3
Original line number Diff line number Diff line
@@ -377,7 +377,8 @@ dict_print_info_on_foreign_key_in_create_format(
/*============================================*/
	FILE*		file,		/* in: file where to print */
	trx_t*		trx,		/* in: transaction */
	dict_foreign_t*	foreign);/* in: foreign key constraint */
	dict_foreign_t*	foreign,	/* in: foreign key constraint */
	ibool		add_newline);	/* in: whether to add a newline */
/************************************************************************
Displays the names of the index and the table. */
void
+11 −0
Original line number Diff line number Diff line
@@ -432,6 +432,17 @@ os_file_read(
				offset */
	ulint		n);	/* in: number of bytes to read */	
/***********************************************************************
Rewind file to its start, read at most size - 1 bytes from it to str, and
NUL-terminate str. All errors are silently ignored. This function is
mostly meant to be used with temporary files. */

void
os_file_read_string(
/*================*/
	FILE*	file,	/* in: file to read from */
	char*	str,	/* in: buffer where to read */
	ulint	size);	/* in: size of buffer */
/***********************************************************************
Requests a synchronous positioned read operation. This function does not do
any error handling. In case of error it returns FALSE. */

+19 −0
Original line number Diff line number Diff line
@@ -56,6 +56,22 @@ void
trx_search_latch_release_if_reserved(
/*=================================*/
        trx_t*     trx); /* in: transaction */
/**********************************************************************
Set detailed error message for the transaction. */
void
trx_set_detailed_error(
/*===================*/
	trx_t*	trx,	/* in: transaction struct */
	char*	msg);	/* in: detailed error message */
/*****************************************************************
Set detailed error message for the transaction from a file. Note that the
file is rewinded before reading from it. */

void
trx_set_detailed_error_from_file(
/*=============================*/
	trx_t*	trx,	/* in: transaction struct */
	FILE*	file);	/* in: file to read message from */
/********************************************************************
Retrieves the error_info field from a trx. */

@@ -649,6 +665,9 @@ struct trx_struct{
	trx_undo_arr_t*	undo_no_arr;	/* array of undo numbers of undo log
					records which are currently processed
					by a rollback operation */
	/*------------------------------*/
	char detailed_error[256];	/* detailed error message for last
					error, or empty. */
};

#define TRX_MAX_N_THREADS	32	/* maximum number of concurrent
+12 −0
Original line number Diff line number Diff line
@@ -118,6 +118,18 @@ UNIV_INLINE
int
ut_strcmp(const void* str1, const void* str2);

/**************************************************************************
Copies up to size - 1 characters from the NUL-terminated string src to
dst, NUL-terminating the result. Returns strlen(src), so truncation
occurred if the return value >= size. */
ulint
ut_strlcpy(
/*=======*/
				/* out: strlen(src) */
	char*		dst,	/* in: destination buffer */
	const char*	src,	/* in: source buffer */
	ulint		size);	/* in: size of destination buffer */

/**************************************************************************
Compute strlen(ut_strcpyq(str, q)). */
UNIV_INLINE
Loading