From: "Michael C. Libby" Date: 2002-11-19T09:30:42+09:00 Subject: Re: ruby.dbi -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Monday 18 November 2002 17:08, Ted wrote: > 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. :) > 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. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE92YXX4ClW9KMwqnMRAk0jAKCQHRTP+71WPAniC6bcON27klFeoACeLw4y ZUloxJLq0UKDPI2ncTAb3kI= =5Qk0 -----END PGP SIGNATURE-----