我正在尝试调用 AddCluster 女巫的存储过程调用参数“title”和“alt”
情况1:
如果“标题”在数据库中,则只需返回“旧”行!
案例二:
如果“标题”不在数据库中,那么,
根据 parmerer 'title' 和 'alt' 插入一行
然后通过 LAST_INSERT_ID() 选择新添加的行
问题出在案例 2 上,它只返回空!!
-- --------------------------------------------------------------------------------
-- AddCluster Group Routines
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`linkbay_dk`@`%` PROCEDURE `AddCluster`(in in_title varchar(45), in in_alt text)
BEGIN
/* check if 'in_title' is in db */
IF EXISTS
(
SELECT count(*) FROM Cluster
WHERE title=in_title
)
THEN
/* returns old Cluster there is in db */
SELECT * FROM Cluster WHERE title=in_title;
ELSE
INSERT INTO Cluster
(
`id`,
`create_at`,
`title`,
`alt`
)
VALUES
(
null,
NOW(),
in_title,
in_alt
);
/* returns the newly added Cluster */
SELECT * FROM Cluster WHERE id=LAST_INSERT_ID();
END IF;
END$$