I've been trying to put a stored procedure creation step into my SQL upgrade script in Magento. like
$this->startSetup();
$sql = <<< __SQLPRC
CREATE PROCEDURE my_proc(
IN length int
,IN column_used开发者_如何学运维_for varchar(50)
,OUT return_id bigint
)
BEGIN
DECLARE count_unused INT;
SET count_unused = 0;
select
id into return_id
from
my_table
where
used_status=0
limit 1;
if length(return_id) = length
then
update my_table
set
used_status=1
where
id = return_id;
else
set return_id = 0;
end if;
END;
__SQLPRC;
try {
$this->run($sql);
}
catch(Exception $e)
{ echo "<pre>" . $e->getTraceAsString(); }
$this->endSetup();
What I've concluded from my debugging is that Magento just grabs the SQL till first semi-colon ";
"
Can somebody help me with this?
You have put the Stored Procedure code as:-
$this->startSetup();
$sql = <<< __SQLPRC
...
This needs to be as:-
$this->startSetup();
$sql = <<<__SQLPRC
...
This should work now, as there shouldn't be any space after the "<<<
" according to the Heredoc Syntax of PHP String Delimiting.
Hope it helps.
Updated Answer:-
Can you try using this code:-
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->exec($sql);
instead of:-
$this->run($sql);
I have seen some issues earlier regarding this on Magento.
精彩评论