Increment column in update query
MrPropre opened this issue · 2 comments
MrPropre commented
Hello, I want to add +1 to a column in a update prepared statement, but latitude put "column +1" in the params. Here is my code :
$query = $this->query
->update($this->table, [
'nombre_vues' => 'nombre_vues + 1'
])
->where(field('id')->eq($id))
->compile();
$requete = $this->bdd->prepare($query->sql());
$requete->execute($query->params());
Here is the params :
array (size=2) 0 => string 'nombre_vues + 1' (length=15) 1 => string '54' (length=2)
Can you help me ? Thank you ! 😊
shadowhand commented
You'll want to use the helpers to create an expression. See the function docs. If you can't find the answer there, I can provide an example later. (Answering from my phone.)
MrPropre commented
Thank you and sorry for the inconvenience ! Here is my updated code for anyone who would needs it.
$query = $this->query
->update($this->table, [
'nombre_vues' => express('%s + 1', identify('nombre_vues'))
])
->where(field('id')->eq($id))
->compile();
$requete = $this->bdd->prepare($query->sql());
$requete->execute($query->params());