Reputation: 359
Using Doctrine 1.2.4, i cant't resolve using "IF" MySQL instruction under Doctrine.
I want generate this SQL code :
UPDATE mytable SET mytable.state = IF(mytable.state=0, 128, mytable.state)
But using :
$stmt_update = Doctrine_Query::create()
->update('Mytable mytable')
->set('mytable.state', 'IF(mytable.state=0, 128, mytable.state)')
->execute();
Result under mysql server is : mytable.state = IF(mytable.state)
$stmt_update>getDql(); // 'UPDATE Mytable mytable SET mytable.state = IF(mytable.state=0, 128, mytable.state )'
$stmt_update->getSqlQuery(); // 'UPDATE mytable SET mytable.state = IF(mytable.state)'
getSqlQuery() method is used to call Mysql, but with incorrect statement SQL.
Is a way to using IF with Doctrine 1.x ?
http://groups.google.com/group/doctrine-user/browse_thread/thread/3faa518645e32eda%23&usg=AFQjCNEuqznC25z1EAzF4NIcfln8VG_Brg This is not supported by DQL currently.
Is a an extension available for IF with Doctrine 1 ? (like DoctrineExtensions / lib / DoctrineExtensions / Query / Mysql / IfElse.php ) https://github.com/beberlei/DoctrineExtensions/blob/master/lib/DoctrineExtensions/Query/Mysql/IfElse.php
Conditional IF statement in a PHP Doctrine 1.2 SET statement is not usable.
Upvotes: 2
Views: 1544
Reputation: 8830
Just put space between IF
and (
my version is 1.2.3 :
$stmt_update = Doctrine_Query::create()
->update('Mytable mytable')
->set('mytable.state', 'IF (mytable.state=0, 128, mytable.state)');
echo $stmt_update->getSqlQuery();
I'm getting:
UPDATE Mytable SET mytable.state = IF (mytable.state=0, 128, mytable.state)
Upvotes: 2