主题 : 删除文*--解决方法
级别: 秀才
UID: 2428
积分:77 加为好友
威望: 0 精华: 0
主题:5 回复:47
注册时间:2010-01-29
在线时长:0
1#   发表于:2010-04-01 09:24:52  IP:202.251.*.*
删除文章,有问题。因为表的关联,要处理很多步骤。其中上下篇的处理没有完成!

不过,我觉得删除文章牵涉到很多张表,而且有可能在日后的功能增加中还会涉及更多。
我觉得删除文章,这步骤应该放在存储过程来完成(效率提高非常多,否则在hibenrate要操作很多),以下是我写的存储过程,已经成功实现了:

begin
set @next_id = null;
set @pre_id = null;
select @next_id:=next_id,  @pre_id:=pre_id  from  arti_article  where  article_id=id;

/**  处理  上一篇、下一篇 ***/
update arti_article set next_id=@next_id  where  next_id=id;
update arti_article set pre_id=@pre_id    where   pre_id=id;
/** 为了避免next_id或pre_id指向自己id,多以下步骤 **/
update arti_article set pre_id=null, next_id=null  where   pre_id=id or next_id=id;

/** 删除专题 ***/
delete from cms_article_topic where article_id=id;
/** 删除评论 ***/
delete from cms_comment where ref_doc_id=id;
/** 删除附件 ***/
delete  arti_article_attachment  ,core_attachment     from arti_article_attachment   ,core_attachment   where arti_article_attachment.article_id=id and arti_article_attachment.attachment_id=core_attachment.attachment_id;
/** 删除本身 ***/
delete from arti_article where article_id=id;

end
其中需要传递一个参数,就是文章ID。另外执行存储过程后,再实际删除文章txt以及附近文件等,这在原有基础上稍微修改下就行了。


想问下JEECMS作者,觉得如何呢?交流下,谢谢
级别: 童生
UID: 5187
积分:8 加为好友
威望: 0 精华: 0
主题:0 回复:5
注册时间:2010-04-01
在线时长:0
2#   发表于:2010-04-01 20:25:33  IP:218.60.*.*
楼主的探索精神值得敬佩
用存储过程固然效率好,可是移植性就大打折扣了
1 共1页