准备选用iBatis.Net做博客的数据持久层,准备写几个demo测测。看它能和mysql数据库友好的玩耍不。
刚开始还挺好的,iBatis.Net能访问mysql数据库。但到了一个存储过程的demo时,好运气终于用光了。我就在网查了查iBatis调用存储过程的例子(IBatisNet系列-执行存储过程,IBatis.Net如何获取存储过程的Output的参数值)。
看了这篇文章,我本以为问题已经解决。可以继续愉快的玩耍了。这个是我代码。
create table `SysNum`(
Id int AUTO_INCREMENT not null
,Name varchar(100) not null comment '表名'
,Num bigint not null default 0 comment '该表对应的编号'
,Status int default 0 not null
,`Time` TIMESTAMP default now() not null
,primary key `P_Id`(`Id`)
,unique key `U_Name`(`Name`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='编号表';
create PROCEDURE proc_GetSysNum(in name varchar(100),out n bigint) comment '获取编号'
begin
declare value bigint default (select exists (select Num from SysNum where Name=name));
set @m=0;
if value<>1 then
begin
insert into SysNum(Name,Num,Status)values(name,(select @m:=1),0);
end;
else
begin
update SysNum set Num=@m:=Num+1 where Name=name;
set n=@m;
end;
select n;
end if;
end;
===2014.12.24修正。Name=name永远为true。
DROP PROCEDURE IF EXISTS Duger.proc_GetSysNum;
CREATE PROCEDURE Duger.`proc_GetSysNum`(in m varchar(100),out n bigint)
COMMENT '获取编号'
begin
set @v:= (select exists (select Num from SysNum where Name=m));
set @m