Error in Using IF Statement in key="database.insertPosition"

rizwan9 years ago

If am facing syntax error when I use If statement mentioned in following thread to skip some records
https://sourceforge.net/p/traccar/discussion/1100416/thread/290ab3eb/

    <entry key="database.insertPosition">
        START TRANSACTION;
            UPDATE Device SET lastValidLatitude = :latitude, lastValidLongitude = :longitude, lastGPSTimestamp = UNIX_TIMESTAMP(:time), lastUpdateTime = UNIX_TIMESTAMP(NOW()) WHERE imeiNumber = :device_id;
            SELECT @accountID := accountID, @deviceID := deviceID FROM Device WHERE imeiNumber = :device_id;
            SELECT @lastSpeed := speedKPH FROM EventData WHERE accountID = @accountID AND deviceID = @deviceID ORDER BY timestamp DESC LIMIT 1
            IF (:speed <> 0) OR (@lastSpeed <> 0) THEN
                INSERT INTO EventData VALUES (@accountID, @deviceID, UNIX_TIMESTAMP(:time), 0, :latitude, :longitude, 0, :speed, :course, 0, '', 0, '', '', '', 0, 0, 0, '0000000001', UNIX_TIMESTAMP(NOW()));
            END IF
        COMMIT;
    </entry>

I have also tried


IF (:speed & lt ; & gt ; 0) OR (@lastSpeed & lt ; & gt ; 0) THEN

By using first one server does not starts but by using second one (spaces in "& lt ;" are placed here intentionally to display it purposefully in forum) if statement it starts but gives syntax error in log on IF statement

BR//

Anton Tananaev9 years ago

That's a very old thread you found. You can try to use INSERT SELECT statement with WHERE clause instead of IF.