0

I would like to write a query like

delete from inventory_reservation where JSON_EXTRACT(metadata, '$.object_increment_id') = '<increment_id>'

So I created my expression in my code like

$expression = "JSON_EXTRACT(metadata,'$.object_increment_id') = ?";

And then I try to invoke a delete action like this

$this->resourceConnection->getConnection()->delete($table, [$expression, $order->getIncrementId()]);

However the resulting query is this one

DELETE FROM `inventory_reservation` WHERE (JSON_EXTRACT(metadata,'$.object_increment_id') = ?) AND (5000447466)`

It's not performing a replace on the parameterized query. What am I doing wrong here?

1 Answer 1

1

In case anyone else stumbles into this, I used the following code to prepare the condition to make sure it's properly sanitized.

$condition = $this->resourceConnection->getConnection()->prepareSqlCondition("JSON_EXTRACT(metadata,'$.object_increment_id')", ['eq' => $order->getIncrementId()]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.