1. Sample Problem:log of failures Problem example: Fault logging
When an insert fails, I want to be able to record it in a log file. The example of the problem we used to show the error handling is common. I want to get the wrong record. When the insert fails, I want to write down the error information in another file, such as the time of the error, the cause of the error, and so on. The reason I'm particularly interested in inserting is that it will violate the Foreign KEY association constraint
2. Sample Problem:log of Failures (2)
mysql> CREATE TABLE T2
1 INT, PRIMARY KEY (S1))
engine=innodb;//
mysql> CREATE TABLE T3 (S1 INT, KEY (S1),
FOREIGN KEY (S1) REFERENCES T2 (S1))
engine=innodb;//
mysql> INSERT into T3 VALUES (5);
...
ERROR 1216 (23000): Cannot add or update a child row:a foreign key
Constraint fails (the system error message is shown here)
I started to create a primary key table and a foreign key table. We are using InnoDB, so the foreign Key Association check is open. Then when I insert a value from a Non-key table to the Foreign key table, the action will fail. Of course this condition can quickly find error number 1216.
3. Sample Problem:log of failures
CREATE TABLE Error_log (error_message
CHAR (80))//
The next step is to create a table that stores errors when you make an error in the Insert action.
4. Sample Problem:log of Errors
CREATE PROCEDURE P22 (parameter1 INT)
BEGIN
DECLARE EXIT HANDLER for 1216
INSERT into Error_log VALUES
(CONCAT (' Time: ', current_date,
'. Foreign Key Reference failure for
Value = ', parameter1)];
INSERT into T3 VALUES (parameter1);