Sha256: d3b501f514e60a07b450546e248d0e5d9923cad849eb5a5d6d63f5e86b4dadf4

Contents?: true

Size: 1.24 KB

Versions: 73

Compression:

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

  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

end

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
imperituroard-0.3.0 lib/imperituroard/phpipamdb.rb
imperituroard-0.2.9 lib/imperituroard/phpipamdb.rb
imperituroard-0.2.8 lib/imperituroard/phpipamdb.rb
imperituroard-0.2.7 lib/imperituroard/phpipamdb.rb
imperituroard-0.2.5 lib/imperituroard/phpipamdb.rb
imperituroard-0.2.4 lib/imperituroard/phpipamdb.rb
imperituroard-0.2.3 lib/imperituroard/phpipamdb.rb
imperituroard-0.2.2 lib/imperituroard/phpipamdb.rb
imperituroard-0.2.1 lib/imperituroard/phpipamdb.rb
imperituroard-0.2.0 lib/imperituroard/phpipamdb.rb
imperituroard-0.1.9 lib/imperituroard/phpipamdb.rb
imperituroard-0.1.8 lib/imperituroard/phpipamdb.rb
imperituroard-0.1.7 lib/imperituroard/phpipamdb.rb