我编写了一个存储过程并希望在Rake任务中执行它。无法使用ActiveRecord从Rake任务执行MySQL sql“source”命令
调用存储过程(通过“呼叫”的声明),我应该与失败,因为以下错误的来源命令创建过程之前:
Mysql2::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 'source import_legacy_database.sql' at line 1: source import_legacy_database.sql
执行下面的线时发生此错误:
ActiveRecord::Base.connection.execute "source import_legacy_database.sql"
同样的命令“源import_legacy_database.sql”运行正常时,在控制台上,而不是在Rake任务。
如果我不叫这个命令然后
ActiveRecord::Base.connection.execute "call import_legacy_database()"
,因为数据库没有找到程序,因为它不存在失败。
谢谢先进。
如果您的应用程序服务器和数据库服务器位于同一台计算机上,那么这非常棒,但在大多数生产环境中,当它们不在时,此方法将不起作用。 – jwg2s 2012-11-05 15:36:04