2010年12月25日 星期六

如果你開的 table 忘記設定 public

#如果你開的 table 忘記設定 public, 這程式可以全部重新設定
#
# 2010/12/26 by Darren Shen
#--------------------------------------------------------------------------------------------
database ds

define g_dbs like type_file2.chr20
define g_table like type_file2.chr40
define g_sql1 like type_file2.chr500
define g_ok like type_file2.chr1

main
  let g_dbs=UPSHIFT(arg_val(1))
  if ccl_null(g_dbs) then
    display 'Args: dbs'
    exit program
  end if

 database g_dbs

  declare c1 cursor with hold for select TABLE_NAME from all_tables
     where owner=g_dbs order by table_name
  foreach c1 into g_table
     let g_ok="Y"

     begin work
     let g_sql1='grant select on ',g_table clipped,' to public'
     #display  g_sql1
     prepare p_pre1 from g_sql1
     execute p_pre1
     if status then
        let g_ok="N"
     end if
     #display g_sql1
     let g_sql1='grant index on ',g_table clipped,' to public'
     prepare p_pre2 from g_sql1
     execute p_pre2
     if status then
        let g_ok="N"
     end if


     let g_sql1='grant update on ',g_table clipped,' to public'
     prepare p_pre3 from g_sql1
     execute p_pre3
     if status then
        let g_ok="N"
     end if


     let g_sql1='grant delete on ',g_table clipped,' to public'
     prepare p_pre4 from g_sql1
     execute p_pre4
     if status then
        let g_ok="N"
     end if


     let g_sql1='grant insert on ',g_table clipped,' to public'
     prepare p_pre5 from g_sql1
     execute p_pre5
     if status then
        let g_ok="N"
     end if

     if g_ok="Y" then
        commit work
        display g_dbs clipped ,' :',g_table
     else
        rollback work
        display g_dbs clipped ,' :',g_table clipped,' :',status
     end if
  end foreach


end main


function ccl_null(p_str)
define p_str string
define l_len integer
  let l_len=length(p_str.trim())
  if l_len = 0 then
     return true
  else
     return false
  end if

end function

沒有留言:

張貼留言