Read a file

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

···

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.

or simply:
query = File::open(‘filename.sql’){ |f| f.read }

···

On Saturday 16 November 2002 10:07 pm, Michael C. Libby wrote:

query = ‘’
File.open(“filename.sql”){|f| query << f.readlines.to_s}


Bruce R. Williams :: http://www.codedbliss.com

‘It does not require a majority to prevail, but rather an irate,
tireless minority keen to set brush fires in people’s minds.’
– Samuel Adams

Hi,

···

In message “Re: Read a file…” on 02/11/19, Bruce Williams bruce@codedbliss.com writes:

File.open(“filename.sql”){|f| query << f.readlines.to_s}

or simply:
query = File::open(‘filename.sql’){ |f| f.read }

Or simply

query = File.read(‘filename.sql’)

on 1.7.3

						matz.

Sweet. Using 1.7.3 is like opening a big present, a bit at a time. :wink:

···

On Tuesday 19 November 2002 12:58 am, Yukihiro Matsumoto wrote:

query = File.read(‘filename.sql’)

on 1.7.3

  					matz.


Bruce R. Williams :: [iusris/#ruby-lang] :: http://www.codedbliss.com

‘It does not require a majority to prevail, but rather an irate,
tireless minority keen to set brush fires in people’s minds.’
– Samuel Adams

Hello Yukihiro,

Tuesday, November 19, 2002, 8:58:35 AM, you wrote:

File.open(“filename.sql”){|f| query << f.readlines.to_s} | |or
simply: | query = File::open(‘filename.sql’){ |f| f.read }

Or simply

query = File.read(‘filename.sql’)

on 1.7.3

or simply

query = cat filename.sql

:slight_smile:

···


Best regards,
Bulat mailto:bulatz@integ.ru