influxdb-php icon indicating copy to clipboard operation
influxdb-php copied to clipboard

Safely handle inserting object field values

Open JoshWillik opened this issue 8 years ago • 0 comments

Problem

Hi, I was trying to insert a uuid into a record, and it caused a 400 error because the finished record looked like this

event,foo=bar id=a605d377-47bd-4d9a-8b6e-c9ed66bed255

The error occurs because the uuid isn't quoted:

event,foo=bar id="a605d377-47bd-4d9a-8b6e-c9ed66bed255"

This is because the uuid was a Uuid object, not a string (which I didn't realize at the time).

Solution

This function should stringify objects before processing them.

if (is_object($field) {
    $field = $field->toString();
}

The object will eventually be stringified when inserted into the line record, so may as well do it early so it can be quoted if needed.

JoshWillik avatar Jul 28 '17 15:07 JoshWillik