I have a test harness script that requires module “mhiqErrorLogger”.
Within the test script, I’m attempting to call a method within a class
in the “mhiqErrorLogger” module and am getting a “undefined method”
error. Obviously, I’ve got something wrong here, but haven’t a clue as
to what. Can someone please point me in the right direction?
contents of test harness script:
require ‘dbi’
require ‘mhiqErrorLogger’
begin
dbh = DBI.connect(“dbi:ADO:Provider=sqloledb;Data
Source=(local);Initial Catalog=portal;User ID=xxxx;Password=xxxx”)
#-- intentionally throw a “divide by zero” error for testing
intError = 1/0
rows = dbh.select_all(“SELECT name FROM portal_contacts WHERE name IS
NOT NULL ORDER BY name”)
if !rows.empty?
puts " Results returned by query"
rows.each do |row|
puts " Name: " + row[“name”].to_s
end
else
puts “Query returned no results”
end
rescue Exception => ex
#-- “undefined method” error gets thrown on this line!
MHIQErrorLogger::ErrorLogger::PostError(ex, dbh)
ensure
if (!dbh.nil?)
dbh.disconnect
end
end
contents of mhiqErrorLogger.rb:
require ‘dbi’
module MHIQErrorLogger
class ErrorLogger
def PostError(ex,dbh)
errorMessage = ex.message
errorMessage = errorMessage.gsub(13.chr,"")
errorMessage = errorMessage.gsub(10.chr,"")
errorMessage = errorMessage.gsub(/'/,"`")
if (dbh.nil?)
#--
#-- TODO: write error information to an external text file
#--
puts 'No database connection present'
#-- database connection present
else
#-- retrieve name of the currently running script, translate all
#-- single quotes to backticks to prevent errors when INSERTed
scriptName = $0.gsub(/'/,"`")
begin
sth = dbh.prepare("INSERT INTO mhiqErrorLog (errormessage,
scriptname) VALUES (?, ?)")
sth.execute(errorMessage, scriptName)
row = dbh.select_one("SELECT ident_current('mhiqErrorLog') as
[newId]")
newId = row[“newId”].to_i
sth = dbh.prepare("INSERT INTO mhiqErrorStackTrace (errorID,
modulelinenumber) VALUES (?, ?)")
[email protected] {|ele| sth.execute(newId, ele.to_s)}
dbh.commit
rescue Exception => ex
dbh.rollback
puts ex.message
end
end
end ## def PostError
end ## class ErrorLogger
end ## module MHIQErrorLogger