由于初期规划不好,项目管理的action都存入到数据库中了,而实际上应该以配置文件的形式保存的,所以现在想改过来。一条条复制是不可能的,几百条记录,可以用java编写个小程序或者其他语言编写个脚本来实现,都很简单,但因为这两天在学存储过程,所以就试着写一个了(数据库的过程、函数和触发器等真的很好玩啊!)。 (select max(I_ID) from p_link group by C_ACTION);
repeat fetch c_cursor into tmp_action,tmp_power; if not i_done then set c_content = concat(c_content, tmp_action, '=', tmp_power, char(13)); end if; until i_done end repeat; 最终可得到一行行结构为 XXX=XXX 键值对。 |
drop procedure if exists get_all_links;
delimiter $$
create procedure get_all_links()
begin
declare c_content text;
declare i_done int default 0;
declare tmp_action varchar(100);
declare tmp_power tinyint;
declare c_cursor cursor for
select C_ACTION,B_POWER from p_link where I_ID in
(select max(I_ID) from p_link group by C_ACTION);
declare continue handler for sqlstate '02000' set i_done = 1;
open c_cursor;
set c_content = '';
repeat
fetch c_cursor into tmp_action,tmp_power;
if not i_done then
set c_content = concat(c_content, tmp_action, '=', tmp_power, char(13));
end if;
until i_done end repeat;
close c_cursor;
select c_content into outfile 'D:\\action.properties';
end
$$
delimiter ;
call get_all_links();
drop procedure get_all_links;