#!/usr/bin/env ruby # This file is part of LCR-AGI. # # LCR-AGI is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # LCR-AGI is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with LCR-AGI. If not, see . # # Copyright (C) 2009 Alkaloid Networks LLC # Author: Ben Klang # Alkaloid Networks LLC - http://projects.alkaloid.net # $Id$ require 'config' require 'dbi' uri = ['DBI', 'Mysql', $database[:dbname], $database[:host]].join(':') dbh = DBI.connect(uri, $database[:user], $database[:pass]) $logger = Logger.new($logfile) $logger.level = $loglevel $logger.formatter = Logger::Formatter.new dbh['AutoCommit'] = false begin sth = dbh.prepare("INSERT INTO phoneroutes (callsource, destination, cost, carrier) VALUES (?, ?, ?, ?)") $carriers.each{|carrier| $logger.info("Starting load of rate information for #{carrier}.") require "routes/#{carrier}" dbh.do("DELETE FROM phoneroutes WHERE carrier = ?", carrier) Kernel.const_get(carrier).getrates{|row| # The next line is a performance hit. Uncomment it if you need # debug information on the data being sent to the database. #$logger.debug("#{row[0]} #{row[1]} #{row[2]} #{carrier}") sth.execute(row[0], row[1], row[2], carrier) } # Commit each carrier in turn dbh.commit } rescue Exception => e dbh.rollback raise e end #dbh.transaction{|db| # carriername = Kernel.const_get(classname)::CARRIERNAME # db.do("DELETE FROM phoneroutes WHERE carrier = ?", carriername) # sth = db.prepare("INSERT INTO phoneroutes (callsource, destination, cost, carrier) VALUES (?, ?, ?, ?)") # Kernel.const_get(classname).getrates(filename){|row| # sth.execute(row[0], row[1], row[2], row[3]) # } #} dbh['AutoCommit'] = true