INSERT, UPDATE 의 경우 변한 로우수 반환 SELECT 의 경우 0,
COMMIT, ROLLBACK 의 경우 0
저희 테스트 프로시저가 맨 마지막에 COMMIT , ROLLBACK 을 날려서
해당 SQL에 영향 받은 로우수가 0으로 리턴 되는 거네요
* START TARNSACTION 과 COMMIT, ROLLBACK 구문 제외하면 로우수 대로 나옴
DROP PROCEDURE `spTest`; DELIMITER $$ CREATE DEFINER=`dpk`@`124.137.204.78` PROCEDURE `spTest`( ) BEGIN DECLARE v_effected_row INT DEFAULT 0; DECLARE v_error_cnt INT DEFAULT 0; DECLARE v_flow_error_cnt INT DEFAULT 0; DECLARE v_insert_id INT DEFAULT 0; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; SELECT -999; END; DECLARE EXIT HANDLER FOR SQLWARNING BEGIN ROLLBACK; SELECT -998; END; FLOW_START: BEGIN START TRANSACTION; INSERT INTO TEST (num)VALUES (1); SET v_insert_id = LAST_INSERT_ID(); SELECT ROW_COUNT(), @@error_count INTO v_effected_row, v_error_cnt; IF(v_effected_row != 1 OR v_error_cnt <> 0 ) THEN SELECT -1; END IF; UPDATE TEST SET num = 2 WHERE idx = v_insert_id; SELECT ROW_COUNT(), @@error_count INTO v_effected_row, v_error_cnt; IF(v_effected_row != 1 OR v_error_cnt <> 0 ) THEN SELECT -2; END IF; IF(v_flow_error_cnt > 0) THEN ROLLBACK; LEAVE FLOW_START; ELSE SELECT 0; COMMIT; END IF; END; END $$ DELIMITER ; delimiter $$ CREATE TABLE `TEST` ( `idx` bigint(20) NOT NULL AUTO_INCREMENT, `num` bigint(20) NOT NULL, PRIMARY KEY (`idx`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8$$
참고 The documentation says: the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client. Re: LAST_INSERT_ID() on which Connection? Feb 26, 2012 08:30 PM|LINK Andy22 each time my web sever connects to the mysql sever it's considerd a different connection correct? Correct. Andy22 Will different instances of the above connection example be considered as different connections by MySQL? Yes. Andy22 if somehow my different web sessions use the same connection Can't happen.