diff options
author | unknown <aivanov@mysql.com> | 2006-02-10 01:15:45 +0300 |
---|---|---|
committer | unknown <aivanov@mysql.com> | 2006-02-10 01:15:45 +0300 |
commit | 47d2d793702116322f5a41b72cd271af28e544bf (patch) | |
tree | de449c8dbd92d98743154faca130e289365fd7f3 /sql/handler.cc | |
parent | ac5257880620649f34fe97985433d13b851f7c2f (diff) | |
parent | 24cea20193a470f5ceb2c074100d5402635be1ba (diff) | |
download | mariadb-git-47d2d793702116322f5a41b72cd271af28e544bf.tar.gz |
Merge aivanov@bk-internal.mysql.com:/home/bk/mysql-5.1-new
into mysql.com:/home/alexi/innodb/mysql-5.1-merged
mysql-test/r/innodb.result:
Auto merged
mysql-test/t/innodb.test:
Auto merged
sql/ha_innodb.cc:
Auto merged
sql/handler.cc:
Auto merged
sql/share/errmsg.txt:
Auto merged
Diffstat (limited to 'sql/handler.cc')
-rw-r--r-- | sql/handler.cc | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/sql/handler.cc b/sql/handler.cc index 24e9f6aa1e2..2cb1135d319 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -358,6 +358,7 @@ static int ha_init_errors(void) SETMSG(HA_ERR_TABLE_EXIST, ER(ER_TABLE_EXISTS_ERROR)); SETMSG(HA_ERR_NO_CONNECTION, "Could not connect to storage engine"); SETMSG(HA_ERR_TABLE_DEF_CHANGED, ER(ER_TABLE_DEF_CHANGED)); + SETMSG(HA_ERR_FOREIGN_DUPLICATE_KEY, "FK constraint would lead to duplicate key"); /* Register the error messages for use with my_error(). */ return my_error_register(errmsgs, HA_ERR_FIRST, HA_ERR_LAST); @@ -1868,6 +1869,29 @@ void handler::print_error(int error, myf errflag) textno=ER_DUP_KEY; break; } + case HA_ERR_FOREIGN_DUPLICATE_KEY: + { + uint key_nr= get_dup_key(error); + if ((int) key_nr >= 0) + { + /* Write the key in the error message */ + char key[MAX_KEY_LENGTH]; + String str(key,sizeof(key),system_charset_info); + /* Table is opened and defined at this point */ + key_unpack(&str,table,(uint) key_nr); + uint max_length= MYSQL_ERRMSG_SIZE-(uint) strlen(ER(ER_FOREIGN_DUPLICATE_KEY)); + if (str.length() >= max_length) + { + str.length(max_length-4); + str.append(STRING_WITH_LEN("...")); + } + my_error(ER_FOREIGN_DUPLICATE_KEY, MYF(0), table_share->table_name.str, + str.c_ptr(), key_nr+1); + DBUG_VOID_RETURN; + } + textno= ER_DUP_KEY; + break; + } case HA_ERR_NULL_IN_SPATIAL: textno= ER_UNKNOWN_ERROR; break; @@ -2003,8 +2027,9 @@ uint handler::get_dup_key(int error) { DBUG_ENTER("handler::get_dup_key"); table->file->errkey = (uint) -1; - if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOUND_DUPP_UNIQUE || - error == HA_ERR_NULL_IN_SPATIAL || error == HA_ERR_DROP_INDEX_FK) + if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY || + error == HA_ERR_FOUND_DUPP_UNIQUE || error == HA_ERR_NULL_IN_SPATIAL || + error == HA_ERR_DROP_INDEX_FK) info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK); DBUG_RETURN(table->file->errkey); } |