Ruby.dbi

Thanks everyone for the help. Here's what finally worked -- and it's a LOT more "Ruby-ish" than any prior attempts.

Am I "getting it", or what? <g> The query initialization puts the Ruby file name and line number, plus the SQL file's name and size as a comment to PgSQL.

      1 #!/usr/bin/env ruby
      2 require 'dbi'
      3 begin
      4 DBI.connect('DBI:pg:DeMolay','ted','yupFan') {|dbh|
      5 ARGV.each{|file|
      6 query = '/* '+$0+':'+__LINE__.to_s+'('+file+
      7 '['+File.size(file).to_s+"]) */\n"
      8 File.open(file) {|f| query << f.readlines.to_s}
      9 puts query
     10 dbh.select_all(query) {|row|
     11 row.each {|col| print "\t"+col.to_s}
     12 puts
     13 }
     14 }
     15 }
     16 rescue => errmsg
     17 puts errmsg.to_s
     18 puts errmsg.backtrace
     19 end

Thanks everyone for the help. Here’s what finally worked – and it’s a
LOT more “Ruby-ish” than any prior attempts.

We’ll get you there. :slight_smile:

Am I “getting it”, or what? The query initialization puts the Ruby
file name and line number, plus the SQL file’s name and size as a
comment to PgSQL.

  1 #!/usr/bin/env ruby
  2 require 'dbi'
  3 begin
  4     DBI.connect('DBI:pg:DeMolay','ted','yupFan') {|dbh|
  5         ARGV.each{|file|
  6             query = '/* '+$0+':'+__LINE__.to_s+'('+file+
  7                     '['+File.size(file).to_s+"]) */\n"

#this seems cleaner to me
6 query = “/#$0:#{LINE}(#{file}[#{File.size(file)}])/\n”

  8             File.open(file) {|f| query << f.readlines.to_s}
  9             puts query
 10             dbh.select_all(query) {|row|
 11                 row.each {|col| print "\t"+col.to_s}

11 puts row.join(“\t”)

 12                 puts
 13             }
 14         }
 15     }
 16 rescue => errmsg
 17     puts errmsg.to_s
 18     puts errmsg.backtrace
 19 end

HTH.

-michael

p.s. KMail is one of many GNU/Linux email clients that can do PGP-signing.
Others I’ve seen include Sylpheed, Evolution, and Mutt.

···

On Monday 18 November 2002 17:08, Ted wrote: