Brian Corrigan
2006-Apr-04 18:11 UTC
[Rails] Parsing a SQL file directly into activerecord::executemethod - Not a vamp I swear
In an effort to not be a vamp. (Thanks Amy) Here is the error message
I''m getting.
Mysql::Error: #42000You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
''=A1=C9=A8[=A9=B4#Globals (ActiveRecord::StatementInvalid) SET
@rightnow =3D current_timestamp;
It appears that Active Record is parsing each statement for validity and does
not like comments. (And maybe something else here..) =20
Is there a way to force it to simply issue the command and quit worrying about
sytax?
I''ve looked through the Rails source a bit.. Can''t seem to
really find where it is actually doing a syntax check. Maybe the error is
actually from MYSQL?
B
---------------------------
Brian Corrigan
---------------------------
-----Original Message-----
From: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Brian Corrigan
Sent: Tuesday, April 04, 2006 12:41 PM
To: rails@lists.rubyonrails.org
Subject: [Rails] Parsing a SQL file directly into activerecord::executemethod=20
Hello folks,
I''m trying to do something like:
1. db =3D ActiveRecord::Base.establish_connection(:adapter =3D>
"mysql",
:database =3D> "app_development", :username =3D>
"root")
2. Cmd =3D 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
Maybe Matching Threads
- Parsing a SQL file directly intoactiverecord::executemethod - Not a vamp I swear
- Parsing a SQL file directly into activerecord::execute method
- Problem with dropping the column_id column...
- Efficiently convert this SQL statement to ActiveRecord loop
- Re: Rails SQL Server adapter
