Help needed with adding additional data to devices table via Config database.updateLatestPosition

jaimzj4 years ago

I have added the database columns, and the following configuration to config file, this is the error that is returned. Any help would be appreciated.

2020-05-18 18:56:00 WARN: Failed to update device - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE jc_devices SET lastValidLatitude = 23.8945172, lastValidLongitude = -79.2' at line 3 - SQLSyntaxErrorException (... < QueryBuilder:480 < DataManager:354 < DeviceManager:296 < ...)

The config is below.

<entry key='database.updateLatestPosition'>
UPDATE tc_devices SET positionId = :id WHERE id = :deviceId
UPDATE jc_devices SET lastValidLatitude = :latitude, lastValidLongitude = :longitude, lastGPSTimestamp = UNIX_TIMESTAMP(:fixTime), lastUpdateTime = UNIX_TIMESTAMP(NOW()), lastBatteryLevel = CAST(EXTRACTVALUE( :attributes , '/info/batteryLevel' ) AS DOUBLE) WHERE id = :deviceId;
</entry>
Anton Tananaev4 years ago

I think you forgot to provide your schema.

jaimzj4 years ago

Sorry about that.

CREATE TABLE `jc_devices` (
  `id` int(11) NOT NULL,
  `lastValidLatitude` varchar(128) DEFAULT NULL,
  `lastValidLongitude` varchar(128) DEFAULT NULL,
  `lastGPSTimestamp` varchar(128) DEFAULT NULL,
  `lastUpdateTime` varchar(128) DEFAULT NULL,
  `lastBatteryLevel` varchar(128) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Anton Tananaev4 years ago

Why is everything varchar?

jaimzj4 years ago

I had it configured as per the type (based on positions table) in this case, there is still same error as following

WARN: Failed to update device - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE jc_devices SET lastValidLatitude = 43.8945218, lastValidLongitude = -79.2' at line 3 - SQLSyntaxErrorException (... < QueryBuilder:480 < DataManager:354 < DeviceManager:296 < ...)

schema below

CREATE TABLE `jc_devices` (
  `id` int(11) NOT NULL,
  `lastValidLatitude` double DEFAULT NULL,
  `lastValidLongitude` double DEFAULT NULL,
  `lastGPSTimestamp` timestamp NULL DEFAULT NULL,
  `lastUpdateTime` timestamp NULL DEFAULT NULL,
  `lastBatteryLevel` varchar(256) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Anton Tananaev4 years ago

I think I know what the problem is. You haven't separated your SQL queries with a semi-colon.