From: Parragh Szabolcs Date: 2006-11-04T21:42:54+09:00 Subject: mod_ruby postgres --------------020107060103030207070902 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit Hello, I'm trying some code with mod_ruby where I make a postgresql connection. The following works fine: require 'postgres' def with_db db = PGconn.connect('localhost', 5432, '', '', 'template1', 'postgres', '') begin yield db ensure db.close end end with_db do |db| row = db.query('SELECT VERSION()') puts row end But when I alter the code extending the PGconn class to do the result set ceanup like this: require 'postgres' class PGconn alias :exec_no_block :exec def exec(sql) res = exec_no_block(sql) return res unless block_given? begin yield res ensure res.clear if res end end end def with_db db = PGconn.connect('localhost', 5432, '', '', 'template1', 'postgres', '') begin yield db ensure db.close end end with_db do |db| db.exec('SELECT VERSION()') do |res| puts res[0] end end The latter code works from command line, making the same output as the first one, however, with mode_ruby I get the following error in apache error.log: [Sat Nov 04 13:28:08 2006] [error] mod_ruby: error in ruby [Sat Nov 04 13:28:08 2006] [error] mod_ruby: /var/www/ruby/e1b.rb:20:in `with_db': undefined method `connect' for #::PGconn (NoMethodError) Could someone please help me out with this? It might be an obvious fault in my code, but I cannot figure it out. Thanks: Szab -- Parragh Szabolcs web: parszab.nir.hu --------------020107060103030207070902--