0
 f = File.open("alice.sql").readlines

but I think I need some kind of SQL-Library and RubyGem to be able to work and manipulate the file.

Any libraries that would do the job?

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
tabaluga
  • 1,377
  • 4
  • 20
  • 27
  • 3
    What is it that you intend to do with the SQL file? Manipulate the statements in it? Execute it? – Michael Berkowski May 13 '12 at 18:18
  • Do you need to manipulate the sql-file, or do you want to execute it on your DB? – knut May 13 '12 at 18:24
  • I want to search for some strings e.g. '[bdo]' and want to replace them with ['bdo_dc'] I think this could be done very easily in ruby, if I could treat it as a .txt file – tabaluga May 13 '12 at 18:29
  • 2
    An *.sql file **is** a text file. You could not even mention SQL in this question. – Samy Dindane May 13 '12 at 18:36
  • but how do I deal with the encoding? It is not a plain text file. Ruby thinks it is UTF-8 f.external_encoding.name but it is a format like ["\377\376i\000f\000 \000e\000x\000i and there is no way to know, which character encoding that is – tabaluga May 13 '12 at 18:46
  • Can't you set the encoding to UTF-8 before you save the file? – Samy Dindane May 13 '12 at 18:48
  • What's the difference to your question http://stackoverflow.com/questions/10573718/how-do-i-modify-sql-files-with-ruby ? – knut May 13 '12 at 18:51

1 Answers1

0

If you want to execute it, you can use ActiveRecord or DataMapper for example.

Samy Dindane
  • 17,900
  • 3
  • 40
  • 50
  • thanx, but I do not want to execute it. I just want to treat it as a text file, which I can alter and then I want to create a new .sql file – tabaluga May 13 '12 at 18:36