fr-ser / grafana-sqlite-datasource

Grafana Plugin to enable SQLite as a Datasource
Apache License 2.0
123 stars 17 forks source link

Getting unsigned int result for signed int #137

Closed FroggyCorp closed 3 months ago

FroggyCorp commented 3 months ago

Hi,

I use the 3.5.0 sqlite plugin with grafana enterprise rpi 9.3.6 I have some temperature time series. I use the following query :

SELECT (timestamp * 1000) as datetime, cast(value as INT) as temperature FROM sensors WHERE timestamp >= $from / 1000 and timestamp < $to / 1000 and source_id = 20 and sensor_id = 1 and type = 101 ORDER BY timestamp ASC

12.34°C is stored as 1234 so value = temperature * 100

What i get, is unsigned result as for negative value i have :

2024-01-14 09:39:17 65443 2024-01-14 09:49:19 65486 2024-01-14 10:01:10 31 2024-01-14 10:12:52 11

On the query inspector, i get the same result, but with a SQLite browser, i have negative value from the SQLite.file, as SQLite store integer as signed by default. I tryed some "cast" but with no effect. I come here with that problem, but in fact i don't really know if its coming from sqlite plugin or grafana which should convert unsigned to signed on query.

If it's not plugin releavant, i apologize

thx in advance for any help.


Did not mention it, but i already tryed with : SELECT (timestamp * 1000) as datetime, value as temperature FROM sensors WHERE timestamp >= $from / 1000 and timestamp < $to / 1000 and source_id = 20 and sensor_id = 1 and type = 101 ORDER BY timestamp ASC

fr-ser commented 3 months ago

Could you provide a CTE that does not work? Something in the shape of this

with data(time, text, city) AS (VALUES
    (724125600, 'annotation London', 'London'),
    (724161600, 'annotation New York', 'New York'),
    (724197600, 'annotation Washington', 'Washington')
) SELECT * from data
FroggyCorp commented 3 months ago

Hi, After getting more into it, it was my mistake. In fact it was TEXT and not INTEGER for "value" row and i get a bug when i save value. For reason i dont get, sometimes i got negative value and sometimes not, it why i thought it was lib problem, but it was only my code. I apologize