ORACLE trigger-based report version saving tool

Source: Internet
Author: User

Cognos itself does not have a version control tool. The project files of frameworkmanager and transformer can be controlled using version control tools such as CVS and SVN. However, all reports are stored in the content store, if the report is accidentally modified or deleted, it will be permanent. If there is no backup, the report will disappear forever.
I studied content store some time ago and learned that all the report definitions are stored in the cmobjprops7 table. I was wondering if I could use the trigger to capture update and delete operations, save the previous report definition? So I created a table cmobjversion in Oracle, a trigger cmrep_tr, and a method getcmobjpath. The trigger is for table cmobjprops7. When it is updated or deleted, obtain the previous report definition and call getcmobjpath to obtain the report storage path and store it in the cmobjversion table.
Create Table cmobjversion
(
Modifydate date,
Spec clob,
Action varchar2 (32 ),
Reportpath nvarchar2 (1000)
);
Comment on column cmobjversion. modifydate is 'modification time ';
Comment on column cmobjversion. spec is 'report defination ';
Comment on column cmobjversion. Action is 'action (delete, modify )';
Comment on column cmobjversion. reportpath is 'report storage path ';
/
Create or replace function getcmobjpath (ID in number) return varchar2 is
Result varchar2 (4000 );
Pcmid number;
CID number;
Cmname varchar2 (4000 );
Begin
/*
Author: interboy
Description: This function is used to input the cmid of the report, and the path of the returned report.
*/
CID: = ID;
Loop
Select a. pcmid, B. Name
Into pcmid, cmname
From cmobjects A, cmobjnames B
Where a. cmid = B. cmid and B. isdefault = 1
And a. cmid = CID;
CID: = pcmid;
Result: = cmname | '/' | result;
Exit when pcmid = 0;
End loop;

Return (substr (result, 0, length (result)-1 ));
End getcmobjpath;
/

Create or replace trigger cmrep_tr
Before delete or update on cmobjprops7
For each row
Begin
/*
Author: interboy
Note: This trigger stores previous reports to the cmobjversion table when the reports are saved and deleted to save the versions.
*/
If: Old. spec is not null then
Case
When updating then
Insert into cmobjversion
(Reportpath, modifydate, spec, Action)
Values
(Getcmobjpath (: Old. cmid), sysdate,: Old. spec, 'update ');
When deleting then
Insert into cmobjversion
(Reportpath, modifydate, spec, Action)
Values
(Getcmobjpath (: Old. cmid), sysdate,: Old. spec, 'delete ');
End case; end if;
End cmrep_tr;
/
After the preceding script is executed, the report is updated, or when the previous report definition is deleted, it is stored in the spec field of the cmobjversion table. In the past, a buddy asked how to restore a report that was accidentally deleted. He cannot recover the backup.
Recovery steps
1. Find the corresponding report definition, copy it to ultraedit, and save it as an XML file. Note that the encoding must be set to utf8.
2. Use reportstudio to open the local report and save
The script file and Demo Video have been sent to the Forum. If you are interested, go to http://www.cognoschina.net/club/thread-7582-1-1.html.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.