attributes colomun

Abou5 years ago

Hi
i use traccar 4.6 version
In positons table th field arributes has these values:

{"distance":13.22,"totalDistance":1045.36,"motion":true}

I would like to use each attribute alone to store it in another field of another tabl, when inserting a new position.
how i can separate them??

Anton Tananaev5 years ago

Modify SQL queries in the config to extract the data.

Abou5 years ago

Tananaev ,can you pleas help me

this my QUERY wich i want to extract distance and totalDistance from attributes colomun

    <entry key='database.insertPosition'>
        START TRANSACTION;

        INSERT INTO tc_positions (protocol, deviceid, servertime, devicetime, fixtime, valid, latitude, longitude, altitude, speed, course, address, attributes, accuracy, network)
        VALUES (:protocol, :deviceid, :servertime, :devicetime, :fixtime, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :attributes, :accuracy, :network);
        SELECT @accountID := accountID, @objectID := isAttached FROM tc_devices WHERE id = :deviceid;

        INSERT INTO eventdata (accountID, objectID, deviceID, timestamp, statusCode, latitude, longitude, speedKPH, heading, altitude, address, rawData, creationTime)

        VALUES (@accountID, @objectID, :deviceid, UNIX_TIMESTAMP(:devicetime), 0, :latitude, :longitude, :speed*1.852, :course, :altitude, :address, :attributes,  UNIX_TIMESTAMP(NOW()));

        UPDATE object SET lastDataID = LAST_INSERT_ID(), lastValidLatitude = :latitude, lastValidLongitude = :longitude, lastValidspeedKPH = :speed*1.852, lastValidHeading = :course, lastGPSTimestamp = UNIX_TIMESTAMP(:devicetime), lastAddress = :address, lastUpdateTime = UNIX_TIMESTAMP(NOW()) WHERE objectID = @objectID;
        COMMIT;
    </entry>
Anton Tananaev5 years ago

Read database engine documentation and see if there's a way to extract JSON values. Here's a MySQL function that might help:

https://stackoverflow.com/a/31127857/2548565

Abou5 years ago

Thanks!! i do it