问题描述
当我从mysql控制台或MySQL Workbench更改Delimeter时,没有出现任何错误,但是当我将相同的代码嵌入在ruby的rails上时,我得到了错误
when I change Delimeter from mysql console or MySQL Workbench I do not get any error,but when I embed the same code in ruby on rails I get error
mysql> DELIMITER $$
mysql>
没有错误.
但是
ActiveRecord::Base.connection.execute(%Q{
DELIMITER $$
})
给予:
ActiveRecord::StatementInvalid: 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 'DELIMITER $$' at line 1:
推荐答案
DELIMITER
实际上是MySQL命令行设置,而不是SQL: http://dev.mysql.com/doc/refman/5.0/en/mysql-commands.html .这意味着您不能以这种方式设置定界符.
DELIMITER
is actually a MySQL command line setting, not SQL: http://dev.mysql.com/doc/refman/5.0/en/mysql-commands.html. That means that you can't set the delimiter in this way.
最重要的是,如果ActiveRecord::Base.connection.execute
只允许您一次执行一条语句,这将无济于事(请参阅 http://www.seanr.ca/tech/?p=75 ).
On top of that, it wouldn't help if you could as ActiveRecord::Base.connection.execute
only allows you to execute one statement at a time out of the box (see http://www.seanr.ca/tech/?p=75).
这篇关于"DELIMITER $$"附近出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!