From: Darin Ginther Date: 2008-12-31T00:55:07+09:00 Subject: Re: Creating a class for returing DB results OK, A little more help... I'm getting an "uninitialized constant Dbutil" error, which seems to have something to do with the way I'm defining the class or naming the file (currently dbutil.rb). Also - what's the best way to include this class in an outside file? Say I'm exercising it from webtest.rb?.. I'm somewhat familiar with the comcept of classpath in JAVA. #-------------------------------------------------------------# # DB utility class. # # 12/30/08. # Purpose: Make connecting to the db and validating # data a little easier. # Ref: http://www.ruby-forum.com/topic/174431#764368 #-------------------------------------------------------------# # the Watir controller Class Dbutil attr_accessor :mydb, :dbuser, :dbpw, :table, :lead_type_code require 'DBI' def initialize(mydb, dbuser, dbpw, table, lead_type_code) @mydb = mydb @dbuser = dbuser @dbpw = dbpw @table = table @lead_type_code = lead_type_code end def counttable dbh= DBI.connect(@mydb, @dbuser, @dbpw, @table, @lead_type_code) sth = dbh.execute("SELECT count(*) FROM @table where code = @lead_type_code") row = sth.fetch yield row[0] sth.finish dbh.disconnect end -- Posted via http://www.ruby-forum.com/.