cnv50t60.sql 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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: cnv50t60.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, char(256);
  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 char(256);
  35. define v_owner char(8);
  36. define user procedure;
  37. -- First verify that the current user has select privileges on this column
  38. let is_allowed = 0;
  39. let search_columns = 0;
  40. -- Check sysusers to see if the usertype is 'D', ie., the
  41. -- current user has dba privileges and may see any columns.
  42. select usertype
  43. into v_mode
  44. from informix.sysusers
  45. where username = user;
  46. if v_mode = 'D' then
  47. let is_allowed = 1;
  48. else
  49. -- See if the user owns the table, and therefore can see the columns.
  50. select owner
  51. into v_owner
  52. from informix.systables
  53. where tabid = table_id;
  54. if v_owner = user then
  55. let is_allowed = 1;
  56. end if
  57. end if
  58. if is_allowed = 0 then
  59. foreach
  60. select tabauth
  61. into v_tabauth
  62. from informix.systabauth
  63. where tabid = table_id and
  64. (grantee = user or
  65. grantee = 'public')
  66. if substr(v_tabauth, 1, 1) = 's' or substr(v_tabauth, 1, 1) = 'S' then
  67. let is_allowed = 1;
  68. exit foreach;
  69. elif substr(v_tabauth, 3, 1) = '*' then
  70. let search_columns = 1;
  71. end if
  72. end foreach
  73. end if
  74. -- Search syscolauth only if user does not have select
  75. -- privileges on all columns. If the user has no select
  76. -- privileges on any column, then we need search no further.
  77. if is_allowed = 0 and search_columns = 1 then
  78. foreach
  79. select colauth
  80. into v_colauth
  81. from informix.syscolauth
  82. where tabid = table_id and
  83. colno = column_no and
  84. (grantee = user or
  85. grantee = 'public')
  86. if substr(v_colauth, 1, 1) = 's' or substr(v_colauth, 1, 1) = 'S' then
  87. let is_allowed = 1;
  88. exit foreach;
  89. end if
  90. end foreach
  91. end if
  92. -- Return with no rows found if not allowed to select from
  93. -- the column designated by (tabid,colno).
  94. if is_allowed = 0 then
  95. raise exception -272;
  96. end if
  97. -- Now find the distribution rows
  98. foreach
  99. select seqno, constructed, mode,
  100. resolution, confidence, encdat
  101. into v_seqno, v_constructed, v_mode,
  102. v_resolution, v_confidence, v_encdat
  103. from informix.sysdistrib
  104. where tabid = table_id and
  105. colno = column_no
  106. order by seqno
  107. return v_seqno, v_constructed, v_mode,
  108. v_resolution, v_confidence, v_encdat
  109. with resume;
  110. end foreach
  111. -- Engine will return 100 to user
  112. end procedure;
  113. grant execute on informix.systdist to public as informix;