Description:
Hello,
i have the following problem with a Cursor:
###########################################################
### The test-environment:
###########################################################
### the table which is selected by the cursor
CREATE TABLE IF NOT EXISTS `act_cache` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ts` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
### some test data
INSERT INTO `act_cache` (`id`, `ts`) VALUES
(1, 1273072721),
(2, 1273072722),
(3, 1273072723);
### this table is only for writing debug data in it from the testProc()
CREATE TABLE IF NOT EXISTS `log` (
`ts` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`name` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`valueInt` int(11) DEFAULT NULL,
`valueDouble` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
### the test procedure
DELIMITER $$
CREATE PROCEDURE `testProc` ()
BEGIN
DECLARE done BOOLEAN DEFAULT 0;
DECLARE act_cache_id INT;
DECLARE ts INT;
DECLARE cur1 CURSOR FOR SELECT id, ts FROM act_cache;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
INSERT INTO log (`name`) VALUE ("testProc.start");
OPEN cur1;
REPEAT
FETCH cur1 INTO act_cache_id, ts;
INSERT INTO log (`name`, `value`) VALUE ("testProc.act_cache_id", act_cache_id);
INSERT INTO log (`name`, `value`) VALUE ("testProc.ts", ts);
INSERT INTO log (`name`, `value`) VALUE ("testProc.done", done);
IF NOT done THEN
INSERT INTO log (`name`) VALUE ("testProc.doSomething");
END IF;
UNTIL done END REPEAT;
CLOSE cur1;
INSERT INTO log (`name`) VALUE ("testProc.end");
END$$
###########################################################
### The problem:
###########################################################
The testProc() should walk through the table `act_cache` and give back the fields `id` and `ts` which are used for further processing.
When i execute
CALL testProc();
the procedure is succesfully executed, but the cursor only fetches the `id` field. The `ts` field is always NULL. Why?
The log content shows the trace of the procedure which looks like this:
----------------------------------------------------------
| TS | NAME | VALUE|
----------------------------------------------------------
| '2010-05-05 17:33:01' | 'testProc.start' | NULL |
| '2010-05-05 17:33:01' | 'testProc.act_cache_id' | 1 |
| '2010-05-05 17:33:01' | 'testProc.ts' | NULL |
| '2010-05-05 17:33:01' | 'testProc.done' | 0 |
| '2010-05-05 17:33:01' | 'testProc.doSomething' | NULL |
| '2010-05-05 17:33:01' | 'testProc.act_cache_id' | 2 |
| '2010-05-05 17:33:01' | 'testProc.ts' | NULL |
| '2010-05-05 17:33:01' | 'testProc.done' | 0 |
| '2010-05-05 17:33:01' | 'testProc.doSomething' | NULL |
| '2010-05-05 17:33:01' | 'testProc.act_cache_id' | 3 |
| '2010-05-05 17:33:01' | 'testProc.ts' | NULL |
| '2010-05-05 17:33:01' | 'testProc.done' | 0 |
| '2010-05-05 17:33:01' | 'testProc.doSomething' | NULL |
| '2010-05-05 17:33:01' | 'testProc.act_cache_id' | 3 |
| '2010-05-05 17:33:01' | 'testProc.ts' | NULL |
| '2010-05-05 17:33:01' | 'testProc.done' | 1 |
| '2010-05-05 17:33:01' | 'testProc.end' | NULL |
----------------------------------------------------------
Thank you for your help!
Stefan Gottschalk
How to repeat:
See description