2011-07-03 58 views
0

以前我用插入延遲和預防SQL注入的

Model.create() 

插入行,現在,我想在MySQL中使用DELAYED選項。

但是,如果我寫

ActiveRecord::Base.connection.execute("INSERT DELAYED INTO `TABLE` (`row`) VALUES (#{params[:id]})") 

,所以我得到的SQL注入。如何預防它?

回答

2

使用connection.quote

id = ActiveRecord::Base.connection.quote(params[:id]) 
ActiveRecord::Base.connection.execute("INSERT DELAYED INTO `TABLE` (`row`) VALUES (#{id})")