Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite3.OperationalError: near "SELECT": syntax error #5

Closed
virtualdj opened this issue Jul 6, 2023 · 1 comment
Closed

sqlite3.OperationalError: near "SELECT": syntax error #5

virtualdj opened this issue Jul 6, 2023 · 1 comment

Comments

@virtualdj
Copy link

Hi, I'm trying to use the script to recover a hole of missing data in InfluxDB.
As I was using the SQLite DB created by HA 2022.8.1, I thought I should install the dependencies like so:

git clone https://github.com/Maaxion/homeassistant2influxdb migrate2influxdb
cd migrate2influxdb/
git clone --depth 1 --branch 2022.8.1 https://github.com/home-assistant/core.git home-assistant-core
python3 -m venv .venv
. .venv/bin/activate
pip install -r home-assistant-core/requirements.txt
pip install -r requirements.txt
python homeassistant2influxdb.py --type SQLite --database /mnt/hgfs/influxdb/image/home-assistant_v2.db --dry-run

When typing the last command I get this error:

(.venv) user@debian:~/mig/migrate2influxdb$ python homeassistant2influxdb.py --type SQLite --database /mnt/hgfs/influxdb/image/home-assistant_v2.db --dry-run

option --dry-run was given, nothing will be writen on InfluxDB
Migrating home assistant database statistics, states to Influx database /mnt/hgfs/influxdb/image/home-assistant_v2.db and bucket homeassistant_missing
Traceback (most recent call last):
  File "/home/user/mig/migrate2influxdb/homeassistant2influxdb.py", line 358, in <module>
    main()
  File "/home/user/mig/migrate2influxdb/homeassistant2influxdb.py", line 151, in main
    cursor.execute(tmp_table_query)
sqlite3.OperationalError: near "SELECT": syntax error

Can you please suggest what I'm doing wrong?
I also tried downloading the same HA version listed in the README, but I get the same error.

Looking at the sources, it seems to fail on:

return """CREATE TEMPORARY TABLE IF NOT EXISTS state_tmp
SELECT max(states.attributes_id) as attributes_id, states.entity_id
FROM states
WHERE states.attributes_id IS NOT NULL
GROUP BY states.entity_id;
"""

but if I run the SELECT statement using SQLite on the same database, it seems to be working...

(.venv) user@debian:~/mig/migrate2influxdb$ sqlite3 /mnt/hgfs/influxdb/image/home-assistant_v2.db \
"SELECT max(states.attributes_id) as attributes_id, states.entity_id \
FROM states \
WHERE states.attributes_id IS NOT NULL \
GROUP BY states.entity_id;"

8984|switch.presa_mss310h_main_channel_2
66891|update.fritz1_fritz_os
66880|update.fritz2_fritz_os
66089|var.total_car_fuel_liters
181|var.zero_emissions_km
... CUT ...
71732|weather.casa
66854|zone.home
@virtualdj virtualdj mentioned this issue Jul 6, 2023
@virtualdj
Copy link
Author

virtualdj commented Jul 8, 2023

Fixed by applying pull request #3 and running with these commands:

sudo apt-get update
sudo apt-get install gcc libmariadb-dev
git clone --branch fix-sqlite-migration https://github.com/fabm3n/homeassistant2influxdb.git
cd homeassistant2influxdb/
git clone --depth 1 --branch 2022.8.1 https://github.com/home-assistant/core.git home-assistant-core
python3 -m venv .venv
. .venv/bin/activate
pip install -r home-assistant-core/requirements.txt
pip install -r requirements.txt
cat influxdb.yaml
python homeassistant2influxdb.py --type SQLite --database /mnt/hgfs/influxdb/image/home-assistant_v2.db --dry-run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant