Class: Myreplicator::VerticaUtils
- Inherits:
-
Object
- Object
- Myreplicator::VerticaUtils
- Defined in:
- lib/loader/vertica/vertica_utils.rb
Class Method Summary collapse
-
.get_grants(*args) ⇒ Object
Example: get_grant(=> “bidw”, :schema => “king”, :table => “customer”).
- .load_grants_from_file(f) ⇒ Object
-
.save_grants_to_file(*args) ⇒ Object
Example: save_grants_to_file(=> [“GRANT ..”,“GRANT …”], :file=>“grants.txt”).
-
.set_grants(sqls) ⇒ Object
Example: set_grants sqls.
Class Method Details
.get_grants(*args) ⇒ Object
Example: get_grant(=> “bidw”, :schema => “king”, :table => “customer”)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/loader/vertica/vertica_utils.rb', line 5 def get_grants *args = args. db = [:db] schema = [:schema] table = [:table] sql = "SELECT * FROM grants WHERE object_schema = '#{schema}' AND object_name = '#{table}';" result = Myreplicator::DB.exec_sql("vertica",sql) sqls = [] result.entries.each do |priv| privilege = priv[:privileges_description] grantee = priv[:grantee] begin sql = "GRANT #{privilege} ON #{schema}.#{table} TO #{grantee};" sqls << sql puts sql rescue Exception => e puts e. end end return sqls end |
.load_grants_from_file(f) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/loader/vertica/vertica_utils.rb', line 51 def load_grants_from_file f file = Rails.root.join('tmp', f) file = File.open(filename, "r") sqls = file.readlines file.close() return sqls end |
.save_grants_to_file(*args) ⇒ Object
Example: save_grants_to_file(=> [“GRANT ..”,“GRANT …”], :file=>“grants.txt”)
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/loader/vertica/vertica_utils.rb', line 40 def save_grants_to_file *args = args. sqls = [:sqls] filename = Rails.root.join('tmp', [:file]) file = File.open(filename, "w+") sqls.each do |sql| file.puts sql.to_s end file.close() end |
.set_grants(sqls) ⇒ Object
Example: set_grants sqls
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/loader/vertica/vertica_utils.rb', line 28 def set_grants sqls sqls.each do |sql| begin puts sql Myreplicator::DB.exec_sql("vertica",sql) rescue Exception => e puts e. end end end |