yii - incrementing value of column value with updateAll() -



yii - incrementing value of column value with updateAll() -

this works well:

$test = self::updateall( array( 'left_nr' => '3', 'right_nr' => '3', ), 'left_nr>=:left_nr , right_nr>=:right_nr', array( ':left_nr' => $parent->left_nr, ':right_nr' => $parent->right_nr, //':new_left_nr' => 'left_nr + 2', //':new_right_nr' => 'right_nr + 2' ) );

but want is:

$test = self::updateall( array( 'left_nr' => ':new_left_nr', 'right_nr' => ':new_right_nr', ), 'left_nr>=:left_nr , right_nr>=:right_nr', array( ':left_nr' => $parent->left_nr, ':right_nr' => $parent->right_nr, ':new_left_nr' => 'left_nr + 2', ':new_right_nr' => 'right_nr + 2' ) );

when seek code, next error:

cdbcommand failed execute sql statement: sqlstate[hy093]: invalid parameter number: number of bound variables not match number of tokens. sql statement executed was: update test_nested_set set left_nr=:yp0, right_nr=:yp1 left_nr>=:left_nr , right_nr>=:right_nr

how can accomplish it?

your code wrong, can accomplish goal updatecounters() below:

$test = self::model()->updatecounters( array( 'left_nr'=>2, //this equal => left_nr = left_nr+2 'right_nr'=>2 ), 'left_nr>=:left_nr , right_nr>=:right_nr',array( ":left_nr"=>$parent->left_nr, ":right_nr"=>$parent->right_nr, ) );

yii defines updatecounters() :

updates 1 or several counter columns. note, updates rows of info unless status or criteria specified.

yii yii2 yii-cactiverecord cactiverecord

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -