Class: Pdb
- Inherits:
-
Object
- Object
- Pdb
- Defined in:
- lib/imperituroard/projects/wttx/phpipamdb.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#database ⇒ Object
Returns the value of attribute database.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#table ⇒ Object
Returns the value of attribute table.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #check_if_msisdn_exists(msisdn, table) ⇒ Object
-
#initialize(database, username, password, ip, port) ⇒ Pdb
constructor
A new instance of Pdb.
- #update_database_rewrite_msisdn(msisdn_old, msisdn_new) ⇒ Object
Constructor Details
#initialize(database, username, password, ip, port) ⇒ Pdb
Returns a new instance of Pdb.
8 9 10 11 12 13 14 15 |
# File 'lib/imperituroard/projects/wttx/phpipamdb.rb', line 8 def initialize(database, username, password, ip, port) @database = database @username = username @password = password @ip = ip @port = port @client = Mysql2::Client.new(:host => ip, :username => username, :password => password) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
7 8 9 |
# File 'lib/imperituroard/projects/wttx/phpipamdb.rb', line 7 def client @client end |
#database ⇒ Object
Returns the value of attribute database.
7 8 9 |
# File 'lib/imperituroard/projects/wttx/phpipamdb.rb', line 7 def database @database end |
#ip ⇒ Object
Returns the value of attribute ip.
7 8 9 |
# File 'lib/imperituroard/projects/wttx/phpipamdb.rb', line 7 def ip @ip end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/imperituroard/projects/wttx/phpipamdb.rb', line 7 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/imperituroard/projects/wttx/phpipamdb.rb', line 7 def port @port end |
#table ⇒ Object
Returns the value of attribute table.
7 8 9 |
# File 'lib/imperituroard/projects/wttx/phpipamdb.rb', line 7 def table @table end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/imperituroard/projects/wttx/phpipamdb.rb', line 7 def username @username end |
Instance Method Details
#check_if_msisdn_exists(msisdn, table) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/imperituroard/projects/wttx/phpipamdb.rb', line 17 def check_if_msisdn_exists(msisdn, table) req1 = "use " + database req2 = "SELECT count(*) FROM " + table + " where hostname='#{msisdn}' or dns_name='#{msisdn}'" client.query(req1, :cast => false) client.query(req2, :as => :array).each do |row| #client.close res = row [0] return res #return number of existed ip addresses in database end end |
#update_database_rewrite_msisdn(msisdn_old, msisdn_new) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/imperituroard/projects/wttx/phpipamdb.rb', line 30 def update_database_rewrite_msisdn(msisdn_old, msisdn_new) begin req1 = "use " + database req2 = "UPDATE ipaddresses set hostname='#{msisdn_new}', dns_name='#{msisdn_new}' where hostname='#{msisdn_old}' or dns_name='#{msisdn_old}'" req3 = "UPDATE subnets set hostname='#{msisdn_new}' where hostname='#{msisdn_old}'" client.query(req1, :cast => false) client.query(req2, :cast => false) client.query(req3, :cast => false) "success" rescue "dbfailed" end end |