On Apr 21, 2010, at 2:35 PM, Fearless Fool wrote:

Does ActiveRecord.connection.execute(string) perform any modifications
on the given string?  If so, what quoting do I need to add?

Here's why: I'm trying to use execute(string) to load a stored
procedure.  I can hand-load the procedure without error (i.e. via
dbconsole), but when I call the function below, it throws the error:
====
ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'DELIMITER $$
====
FWIW, I've pawed over the sources and see that mysql_adapter's execute() calls @connection(query), but I lose the thread after that. Here's the
function (some lines elided for brevity):
====

Can you do it in two steps?

# -- COVERAGE(astart, aend, bstart, bend)

  sql_drop = <<SQL
DROP FUNCTION IF EXISTS `coverage`
SQL

  sql_create = <<SQL
CREATE FUNCTION `coverage`(abeg DATETIME, aend DATETIME, bbeg DATETIME, bend DATETIME)
 RETURNS FLOAT DETERMINISTIC
BEGIN
 <snip>
END;
SQL

  ActiveRecord::Base.establish_connection
  ActiveRecord::Base.connection.execute(sql_drop)
  ActiveRecord::Base.connection.execute(sql_create)

You could also split your single sql on a '$$' boundary and iterate over each fragment.

-Rob

Rob Biedenharn          http://agileconsultingllc.com
[email protected]



--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to