Sha256: ed7e8becaffba10c5307f1f5c180d9ee1f2ddf3b81f1d853087c22157564af37

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

require 'mysql2'



class Pdb

  attr_accessor :database, :username, :password, :table, :ip, :port, :client
  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

  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]
    p res
      return res
      #return number of existed ip addresses in database
    end
  end

  def update_database_rewrite_msisdn(msisdn_old, msisdn_new)
    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"
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
imperituroard-0.1.5 lib/imperituroard/phpipamdb.rb
imperituroard-0.1.4 lib/imperituroard/phpipamdb.rb