壹佰网|ERP100 - 企业信息化知识门户

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2801|回复: 8

adempiere里怎么删除实体

[复制链接]
发表于 2012/10/17 22:14:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622  。

您需要 登录 才可以下载或查看,没有帐号?注册

x
我创建了一个test的实体,现在不用了,怎么删除?用system用户进去能看到其它实体并删除吗?3Q
发表于 2012/10/25 16:11:08 | 显示全部楼层
pshen 曾经写过一个的
/*************************************************************************
* The contents of this file are subject to the LGPL.  
* The Original Author is Peter Shen
* The Personal Information of the contributors:
*      1,  Peter Shen
*          zpshen@gmail.com
*          Shanghai, China
*
*************************************************************************
* $Id: RemoveClient.sql,v 1.1 2005/01/26 14:47:29 pshen Exp $
***
* Title:   Remove a Client in Adempiere.
* Description:
*  - Disable all the constraints and triggers
*  - Delete the records from all the table
*  - Enable  all the constraints and triggers
*
* Warning:
*  - Please backup all the data before you use this script
*
* Guide:
*  - Log in the oracle sqlplus (or other sqlplus tools) with the schema from which you want to delete data
*  - Changed the v_Client_ID to AD_Client_ID which you want to delete
*  - This script would be a little slow, please wait patiently
*
* Known issues:
*  - the script enables the triggers/constraints that you previously disabled for some reasons
*  - if your tables are not in Application Dictionary (AD_Table) then the script won't touch them
*
* Contributor(s):
* Carlos Ruiz - globalqss - 2006/12/11
*   - Test it in Oracle 10G XE
*   - Add reference columns not named AD_Client_ID (like AD_Replication.Remote_Client_ID   
*   - Add novalidate variable for faster but unsure process (or even for failed)
* Teo Sarca <teo.sarca@gmail.com> - 2007/06/12
*   - fixed: trigger enabling issue
*   - fixed: check if the AD_Table row is really a table
*   - fixed: role dependencies issue
*   - fixed: more verbose - this is a critical task so it should be more verbose
*   - tested on Oracle 10G XE
************************************************************************/

DECLARE
   /**
    * Please change this one to any client id you want to delete
    **/
   v_client_id    NUMBER          := 1000002;
   -- novalidate will make the process faster but the constraints won't be validated
   v_novalidate   VARCHAR2 (10)   := ' ';                  -- slower but sure
   -- v_novalidate  VARCHAR2(10)    := 'novalidate'; -- faster but unsure
   v_sql1         VARCHAR2 (1024);

   CURSOR cur_contraints_ena
   IS
      SELECT table_name, constraint_name
        FROM user_constraints
       WHERE constraint_type = 'R' AND status = 'ENABLED';

   CURSOR cur_contraints_dis
   IS
      SELECT table_name, constraint_name
        FROM user_constraints
       WHERE constraint_type = 'R' AND status = 'DISABLED';

   CURSOR cur_triggers_ena
   IS
      SELECT trigger_name
        FROM user_triggers
       WHERE status = 'ENABLED';

   CURSOR cur_triggers_dis
   IS
      SELECT trigger_name
        FROM user_triggers
       WHERE status = 'DISABLED';

   CURSOR cur_removedata
   IS
      SELECT    'delete from '
             || tablename
             || ' where AD_Client_ID='
             || v_client_id AS v_sql
             , a.TableName
        FROM AD_TABLE a
       WHERE a.isview = 'N'
         AND EXISTS (
                SELECT ad_column_id
                  FROM AD_COLUMN c
                 WHERE a.ad_table_id = c.ad_table_id
                   AND UPPER (c.columnname) = 'AD_CLIENT_ID')
         -- Assure that the table is really a table in database
         AND EXISTS (SELECT 1 FROM user_objects dbo WHERE UPPER(dbo.object_name)=UPPER(a.TableName) AND dbo.object_type='TABLE')
      UNION
      SELECT    'delete from '
             || t.tablename
             || ' where '
             || columnname
             || '='
             || v_client_id AS v_sql
             , t.TableName
        FROM AD_COLUMN c, AD_TABLE t
       WHERE ad_reference_value_id = 129
         AND UPPER (columnname) <> 'AD_CLIENT_ID'
         AND t.ad_table_id = c.ad_table_id
         -- Assure that the table is really a table in database
         AND EXISTS (SELECT 1 FROM user_objects dbo WHERE UPPER(dbo.object_name)=UPPER(t.TableName) AND dbo.object_type='TABLE')
        ;

    -- Role dependencies
    cursor cur_role_dep is
        select TableName from AD_Table t, AD_Column c
        where t.AD_Table_ID=c.AD_Table_ID AND t.TableName<>'AD_Role_ID' AND c.ColumnName='AD_Role_ID';

BEGIN
   DBMS_OUTPUT.PUT_LINE ('  Delete Client Where AD_Client_ID=' || v_client_id);
   /****************************************************************
    *  Disable all triggers and constraints one by one
    ****************************************************************/
   DBMS_OUTPUT.PUT_LINE (' Disable the triggers ');
   FOR p IN cur_triggers_ena
   LOOP
      v_sql1 := 'alter trigger ' || p.trigger_name || ' disable ';

      -- DBMS_OUTPUT.put_line ('..' || v_sql1);
      EXECUTE IMMEDIATE v_sql1;
   END LOOP;                                             -- Disable contraints

   DBMS_OUTPUT.PUT_LINE (' Disable the contraints '||v_novalidate);
   FOR p IN cur_contraints_ena
   LOOP
      v_sql1 :=
            'alter table '
         || p.table_name
         || ' disable constraint '
         || p.constraint_name;

      -- DBMS_OUTPUT.put_line ('..' || v_sql1);
      EXECUTE IMMEDIATE v_sql1;
   END LOOP;                                             -- Disable contraints

   /****************************************************************
   *  Remove all the records belongs to that client
   ****************************************************************/
   FOR p IN cur_removedata
   LOOP
      v_sql1 := p.v_sql;

      -- DBMS_OUTPUT.put_line ('..' || v_sql1);
      EXECUTE IMMEDIATE v_sql1;
      IF SQL%ROWCOUNT > 0 THEN
         DBMS_OUTPUT.put_line('Deleted from '||p.TableName || ': #'||SQL%ROWCOUNT);
      END IF;
   END LOOP;                                                    -- Remove data
   
   FOR p IN cur_role_dep loop
      v_sql1 := 'delete from '||p.TableName||' where AD_Role_ID not in (select AD_Role_ID from AD_Role)';
      EXECUTE IMMEDIATE v_sql1;
      IF SQL%ROWCOUNT > 0 THEN
         DBMS_OUTPUT.put_line('Deleted from '||p.TableName||': #'||SQL%ROWCOUNT);
      END IF;
   END LOOP;
   

   /****************************************************************
   *  Disable all constraints and triggers one by one
   ****************************************************************/
   DBMS_OUTPUT.PUT_LINE (' Enable the contraints '||v_novalidate);
   FOR p IN cur_contraints_dis
   LOOP
      v_sql1 :=
            'alter table '
         || p.table_name
         || ' enable '
         || v_novalidate
         || ' constraint '
         || p.constraint_name;

      -- DBMS_OUTPUT.put_line ('..' || v_sql1);
      EXECUTE IMMEDIATE v_sql1;
   END LOOP;                                              -- Enable contraints

   DBMS_OUTPUT.PUT_LINE (' Enable the triggers ');
   FOR p IN cur_triggers_dis
   LOOP
      v_sql1 := 'alter trigger ' || p.trigger_name || ' enable ';

      -- DBMS_OUTPUT.put_line ('..' || v_sql1);
      EXECUTE IMMEDIATE v_sql1;
   END LOOP;                                              -- Enable triggers
   
   COMMIT;
   DBMS_OUTPUT.PUT_LINE ('Done. ');
END;
发表于 2012/10/30 09:26:27 | 显示全部楼层
该脚本执行时会报错,并失败。经检查发现系统内登记的两个约束实际上不存在,估计是原约束只适用于美国的情况。
需要在该脚本执行前去掉那两条约束的登记,即修改CURSOR Cur_Containts 的定义为:
CURSOR Cur_Contraints  IS
                select table_name,constraint_name
                from user_constraints
                where constraint_type = 'R'
                AND status='ENABLED' and constraint_name not in ('cbank_adorginfo','ccashbook_adorginfo');
发表于 2012/10/30 09:30:04 | 显示全部楼层
本帖最后由 Poppy 于 2012/10/30 09:32 编辑

错了,我还是给一个完全能用的脚本吧,注意要把里面的实体号修改成你要删除的实体的实体号。

DeleteADempiereClient_Oracle.sql.txt

4.35 KB, 下载次数: 7, 下载积分: 努力值 -5 点

发表于 2012/12/20 15:58:24 | 显示全部楼层
Poppy 发表于 2012/10/30 09:30
错了,我还是给一个完全能用的脚本吧,注意要把里面的实体号修改成你要删除的实体的实体号。

先下了,应该马上会用到,谢谢了。
发表于 2013/5/10 12:59:17 | 显示全部楼层
没想到这论坛上面的高人都是我们群里的
发表于 2013/5/10 14:17:25 | 显示全部楼层
给的执行报错啊 兄弟 给的执行报错啊 兄弟
发表于 2013/5/10 21:55:19 | 显示全部楼层
呵呵,看看错误原因,两个方向去找:
1. 数据库是不是Oracle,
2. 报错的可能是某个约束不存在,那是因为相应的约束不适用于中国,只适用于美国或其他某个国家
我这个脚本只能用于Oracle
发表于 2013/5/18 00:41:21 | 显示全部楼层
呵呵,是oracle 的 的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|手机版|壹佰网 ERP100 ( 京ICP备19053597号-2 )

Copyright © 2005-2012 北京海之大网络技术有限责任公司 服务器托管由互联互通
手机:13911575376
网站技术点击发送消息给对方83569622   广告&合作 点击发送消息给对方27675401   点击发送消息给对方634043306   咨询及人才点击发送消息给对方138011526

GMT+8, 2025/11/29 02:00 , Processed in 0.018287 second(s), 17 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表