syscdrview.sql 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. --
  2. --
  3. -- Licensed Materials - Property of IBM and/or HCL
  4. --
  5. -- IBM Informix Dynamic Server
  6. -- Copyright IBM Corporation 1996, 2011
  7. -- (c) Copyright HCL Technologies Ltd. 2017. All Rights Reserved.
  8. --
  9. -- Title: syscdrview.sql
  10. -- Setup sysmaster views for Enterprise Replication
  11. --
  12. -- N.B. all SQL commands should be in lower case only
  13. --
  14. database sysmaster;
  15. { add flag text values for ER states }
  16. insert into flags_text values ('cdrstate', 0, 'Catalog');
  17. insert into flags_text values ('cdrstate', 1, 'Definition failed');
  18. insert into flags_text values ('cdrstate', 2, 'Inactive');
  19. insert into flags_text values ('cdrstate', 4, 'Active');
  20. insert into flags_text values ('cdrstate', 8, 'Suspend');
  21. insert into flags_text values ('cdrstate', 16, 'Pending Delete');
  22. insert into flags_text values ('cdrstate', 32, 'Quiescent');
  23. insert into flags_text values ('cdr_rsncjob_state', 1, 'Being Defined');
  24. insert into flags_text values ('cdr_rsncjob_state', 2, 'Defined');
  25. insert into flags_text values ('cdr_rsncjob_state', 4, 'Definition failed');
  26. insert into flags_text values ('cdr_rsncjob_state', 8, 'Running');
  27. insert into flags_text values ('cdr_rsncjob_state', 16, 'Being Stopped');
  28. insert into flags_text values ('cdr_rsncjob_state', 32, 'Stopped');
  29. insert into flags_text values ('cdr_rsncjob_state', 64, 'Pending Completion');
  30. insert into flags_text values ('cdr_rsncjob_state', 128, 'Completed');
  31. insert into flags_text values ('cdr_rsncjob_state', 256, 'Pending Delete');
  32. insert into flags_text values ('cdr_rsncjob_state', 512, 'Being Aborted');
  33. insert into flags_text values ('cdr_rsncjob_state', 1024, 'Aborted');
  34. create view informix.syscdrhost (servid, name, url)
  35. as select
  36. h.servid, cdrgcdisp(h.name),
  37. cdrgcdisp(p.protocol) || ':' || cdrgcdisp(p.address)
  38. from syscdr:informix.hostdef_tab h, outer syscdr:informix.protodef_tab p
  39. where h.servid = p.servid;
  40. grant select on informix.syscdrhost to public as informix;
  41. create view informix.syscdrserver (
  42. servid, servername, connstate, connstatechange,
  43. servstate, ishub, isleaf, rootserverid, forwardnodeid,
  44. idletimeout, atsdir, risdir)
  45. as select
  46. m.servid, m.servname, m.cnnstate, m.cnnstatechg,
  47. f.txt, m.ishub, m.isleaf, m.rootserverid, m.forwardnodeid,
  48. a.idletimeout, cdrgcdisp(a.atsdir), cdrgcdisp(a.risdir)
  49. from informix.syscdrs m, informix.flags_text f, syscdr:informix.servdef_tab a
  50. where a.servid = m.servid and
  51. f.tabname = 'cdrstate' and
  52. f.flags = a.servstate;
  53. grant select on informix.syscdrserver to public as informix;
  54. create view informix.syscdrerror (
  55. errornum, errorserv, errorseqnum, errortime,
  56. sendserv, reviewed, errorstmnt)
  57. as select
  58. error_number, b.servname, remote_seqnum, timestamp,
  59. c.servname, errreviewed, error_desc
  60. from syscdr:informix.cdr_errors a, outer informix.syscdrs b, outer informix.syscdrs c
  61. where a.source_id = b.servid and a.ctrl_id = c.servid;
  62. grant select on informix.syscdrerror to public as informix;
  63. create view informix.syscdrreplset (replsetname, replname, replsetattr)
  64. as select cdrgcdisp(a.replsetname), cdrgcdisp(c.repname), a.replsetattr
  65. from syscdr:informix.replsetdef_tab a, OUTER( syscdr:informix.replsetpartdef b,
  66. syscdr:informix.repdef_tab c )
  67. where a.replsetid = b.replsetid and
  68. b.repid = c.repid;
  69. grant select on informix.syscdrreplset to public as informix;
  70. { Stored proced for returning 'Y' for true and 'N' for false }
  71. create procedure informix.bityesno ( bitset int, bitmask int) returning char;
  72. if (bitval(bitset, bitmask) <> 0) then return 'Y';
  73. else return 'N';
  74. end if;
  75. end procedure;
  76. grant execute on informix.bityesno to public as informix;
  77. { Stored proced for returning 'N', 'C', or 'I' according to whether the }
  78. { floating point flags specify Native, Canonical, or IEEE transport }
  79. create procedure informix.replfloattype ( flags int) returning char;
  80. if (bitval(flags, '0x2') <> 0) then return 'C';
  81. else
  82. if (bitval(flags, '0x40000000') <> 0) then return 'I';
  83. else return 'N';
  84. end if;
  85. end if;
  86. end procedure;
  87. grant execute on informix.replfloattype to public as informix;
  88. create procedure informix.bitrow (flags int) returning char;
  89. if (bitval(flags, '0x100') <> 0) then return 'T';
  90. else return 'R';
  91. end if;
  92. end procedure;
  93. grant execute on informix.bitrow to public as informix;
  94. { Stored proced for returning replicate name given replid }
  95. create procedure informix.replid2Name (replicateid int) returning char(256);
  96. define replicatename char(256);
  97. if (replicateid <> 0)
  98. then
  99. select cdrgcdisp(repname) into replicatename
  100. from syscdr:repdef_tab a
  101. where a.repid = replicateid;
  102. return replicatename;
  103. else
  104. return NULL;
  105. end if;
  106. end procedure;
  107. grant execute on informix.replid2Name to public as informix;
  108. create view informix.syscdrrepl (
  109. replname, replstate, replid,
  110. freqtype, freqmin, freqhour, freqday,
  111. scope, invokerowspool, invoketranspool,
  112. primresolution, secresolution, storedprocname,
  113. ismasterrepl, isshadowrepl, shadowparentrepl,
  114. floattype, istriggerfire, isfullrow, isgrid)
  115. as select cdrgcdisp(repname), f.txt, a.repid,
  116. freqtype, min, hour, day,
  117. bitrow(a.flags), bityesno(a.flags,'0x400'), bityesno(a.flags,'0x800'),
  118. cr_primary, cr_secondary, cdrgcdisp(cr_spname),
  119. bityesno(a.flags,'0x800000'), bityesno(a.flags,'0x2000000'),
  120. replid2Name(a.primaryrepid), replfloattype(a.flags),
  121. bityesno(a.flags,'0x1000'), bityesno(a.flags,'0x10000000'),
  122. bityesno(a.flags,'0x00100000')
  123. from syscdr:informix.repdef_tab a,
  124. outer syscdr:informix.freqdef b,
  125. flags_text f
  126. where a.repid = b.repid
  127. and f.tabname = 'cdrstate' and f.flags = a.repstate;
  128. grant select on informix.syscdrrepl to public as informix;
  129. create view informix.syscdrpart (
  130. replname, servername, partstate, partmode,
  131. usetabowner, dbsname, owner, tabname, pendingsync
  132. )
  133. as select
  134. cdrgcdisp(b.repname), c.servname, f.txt, a.partmode,
  135. bitval(a.flags, '0x04'),
  136. cdrgcdisp(a.db), cdrgcdisp(a.owner), cdrgcdisp(a.table),
  137. bitval(a.flags, '0x040')
  138. from syscdr:informix.partdef_tab a, syscdr:informix.repdef_tab b,
  139. syscdrs c, outer flags_text f
  140. where b.repid = a.repid and c.servid = a.servid
  141. and f.tabname = 'cdrstate' and f.flags = a.partstate;
  142. grant select on informix.syscdrpart to public as informix;
  143. create view informix.syscdrqueued (servername, name, bytesqueued)
  144. as select srvname, replname, SUM(bytesqued)
  145. from syscdrq group by srvname, replname;
  146. grant select on informix.syscdrqueued to public as informix;
  147. create view informix.syscdrtxproc (
  148. servername, txprocessed, txcommitted, txaborted,
  149. rowscommitted, rowsaborted, txbadcnt)
  150. as select
  151. srvname, txprocssd, txcmmtd, txabrtd,
  152. rowscmmtd, rowsabrtd, txbadcnt
  153. from informix.syscdrtx;
  154. grant select on informix.syscdrtxproc to public as informix;
  155. close database;