我編寫了一個存儲過程並希望在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