cnv50t92.sql 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. { ************************************************************************* }
  2. { }
  3. { Licensed Materials - Property of IBM and/or HCL }
  4. { }
  5. { IBM Informix Dynamic Server }
  6. { (c) Copyright IBM Corporation 1996, 2004 All rights reserved. }
  7. { (c) Copyright HCL Technologies Ltd. 2017. All Rights Reserved. }
  8. { }
  9. { ************************************************************************* }
  10. { }
  11. { Title: cnv50t92.sql }
  12. { Description: }
  13. { Add protected database procedure during database construction }
  14. { }
  15. { ************************************************************************* }
  16. { Danish locale (da_dk.ISO-7-Danish) seems to be unique in that it contains }
  17. { no [,], { or } character at all. That is why we avoid using these }
  18. { characters. User should not use subscript operators and change it to }
  19. { substr function. }
  20. { ************************************************************************* }
  21. create dba procedure informix.systdist (table_id int, column_no int)
  22. returning int, date, char(1),
  23. smallfloat, smallfloat, stat, char(1);
  24. define v_tabauth char(8);
  25. define v_colauth char(3);
  26. define is_allowed int;
  27. define search_columns int;
  28. define v_colno smallint;
  29. define v_seqno int;
  30. define v_constructed date;
  31. define v_mode char(1);
  32. define v_resolution smallfloat;
  33. define v_confidence smallfloat;
  34. define v_encdat stat;
  35. define v_owner char(8);
  36. define user procedure;
  37. define v_stattype char(1);
  38. -- First verify that the current user has select privileges on this column
  39. let is_allowed = 0;
  40. let search_columns = 0;
  41. -- Check sysusers to see if the usertype is 'D', ie., the
  42. -- current user has dba privileges and may see any columns.
  43. select usertype
  44. into v_mode
  45. from informix.sysusers
  46. where username = user;
  47. if v_mode = 'D' then
  48. let is_allowed = 1;
  49. else
  50. -- See if the user owns the table, and therefore can see the columns.
  51. select owner
  52. into v_owner
  53. from informix.systables
  54. where tabid = table_id;
  55. if v_owner = user then
  56. let is_allowed = 1;
  57. end if
  58. end if
  59. if is_allowed = 0 then
  60. foreach
  61. select tabauth
  62. into v_tabauth
  63. from informix.systabauth
  64. where tabid = table_id and
  65. (grantee = user or
  66. grantee = 'public')
  67. if substr(v_tabauth, 1, 1) = 's' or substr(v_tabauth, 1, 1) = 'S' then
  68. let is_allowed = 1;
  69. exit foreach;
  70. elif substr(v_tabauth, 3, 1) = '*' then
  71. let search_columns = 1;
  72. end if
  73. end foreach
  74. end if
  75. -- Search syscolauth only if user does not have select
  76. -- privileges on all columns. If the user has no select
  77. -- privileges on any column, then we need search no further.
  78. if is_allowed = 0 and search_columns = 1 then
  79. foreach
  80. select colauth
  81. into v_colauth
  82. from informix.syscolauth
  83. where tabid = table_id and
  84. colno = column_no and
  85. (grantee = user or
  86. grantee = 'public')
  87. if substr(v_colauth, 1, 1) = 's' or substr(v_colauth, 1, 1) = 'S' then
  88. let is_allowed = 1;
  89. exit foreach;
  90. end if
  91. end foreach
  92. end if
  93. -- Return with no rows found if not allowed to select from
  94. -- the column designated by (tabid,colno).
  95. if is_allowed = 0 then
  96. raise exception -272;
  97. end if
  98. -- Now find the distribution rows
  99. foreach
  100. select seqno, constructed, mode,
  101. resolution, confidence, encdat, type
  102. into v_seqno, v_constructed, v_mode,
  103. v_resolution, v_confidence, v_encdat, v_stattype
  104. from informix.sysdistrib
  105. where tabid = table_id and
  106. colno = column_no
  107. order by seqno
  108. return v_seqno, v_constructed, v_mode,
  109. v_resolution, v_confidence, v_encdat, v_stattype
  110. with resume;
  111. end foreach
  112. -- Engine will return 100 to user
  113. end procedure;
  114. grant execute on informix.systdist to public as informix;