Brian Corrigan
2006-Apr-04 16:40 UTC
[Rails] Parsing a SQL file directly into activerecord::execute method
Hello folks, I''m trying to do something like: 1. db = ActiveRecord::Base.establish_connection(:adapter => "mysql", :database => "app_development", :username => "root") 2. Cmd = File.read(''commands.sql'') <--- Command.sql contains multiple valid SQL statement. I''ve tested this directly by piping it into MySQL from the command line 3. ActiveRecord::Base.connection.execute(cmd) This seems to not work as I would expect. My guess is that there is some problem with the File.read parser. Any ideas? The SQL file is pretty large. I bet the parser is doing something to some of the input characters. Best, B PS: Before anyone starts beating on the, do it the Rails way drum, the file is big. Processes relatively large (up to several hundred million records) tables, and works much faster when doing it in SQL directly. I promise. --------------------------- Brian Corrigan ---------------------------
Nick Stuart
2006-Apr-04 19:28 UTC
[Rails] Parsing a SQL file directly into activerecord::execute method
Try this: ActiveRecord::Base.connection.execute(IO.read("#{RAILS_ROOT}/command.sql")) Should do it for ya. If not, make sure your connection is working proberly (can type in a command and executes). Let us know! Also, where are you executing this from? The console? And migration? And where is the SQL file in relation to your app directory? -Nick On 4/4/06, Brian Corrigan <brian.corrigan@mm-games.com> wrote:> Hello folks, > > I''m trying to do something like: > > 1. db = ActiveRecord::Base.establish_connection(:adapter => "mysql", > :database => "app_development", :username => "root") > 2. Cmd = File.read(''commands.sql'') <--- Command.sql contains multiple > valid SQL statement. I''ve tested this directly by piping it into MySQL > from the command line > 3. ActiveRecord::Base.connection.execute(cmd) > > This seems to not work as I would expect. My guess is that there is > some problem with the File.read parser. > > Any ideas? The SQL file is pretty large. I bet the parser is doing > something to some of the input characters. > > Best, > B > > PS: Before anyone starts beating on the, do it the Rails way drum, the > file is big. Processes relatively large (up to several hundred million > records) tables, and works much faster when doing it in SQL directly. I > promise. > > > --------------------------- > Brian Corrigan > --------------------------- > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Possibly Parallel Threads
- Parsing a SQL file directly into activerecord::executemethod - Not a vamp I swear
- Parsing a SQL file directly intoactiverecord::executemethod - Not a vamp I swear
- Efficiently convert this SQL statement to ActiveRecord loop
- Problem with dropping the column_id column...
- Re: Rails SQL Server adapter