From: Ted Date: 2002-11-17T16:13:53+09:00 Subject: Re: Read a file... Thanks so much for the solution. It worked, first time. But... as a procedural guy trying to "get" this here new-fangled OO stuff: File.open: why no close (but only when there's a good open)? Where's the error processing? I wound up trying an explicit open with begin, rescue, end; then trying to read the file in one fell swoop (is that right?), and closing it; then issuing the SQL statement (with its own begin, rescue, end)... I'm sure there's a shorter, necessary-and-sufficient way. > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Saturday 16 November 2002 20:00, Ted wrote: > > It seems so simple, but eludes me. > > I'd like to read a small file containing an SQL query into a String > > variabl, then use the String variable in a PostgreSQL query. > > I have the query working with a an assignment statement; but reading > > in the SQL hasn't worked -- at least for the last 3 hours... > > I'd like to do it as one read, if possible. > > Have you tried: > > query = '' > File.open("filename.sql"){|f| query << f.readlines.to_s} > > -michael > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.0.7 (GNU/Linux) > > iD8DBQE91weL4ClW9KMwqnMRAtvBAJ94XSZxzqo7m2ETBHo+Be0LCsLD1wCbBtL3 > SEye/qpvPsal0jJZJL6bdVU= > =9jvv > -----END PGP SIGNATURE----- > >