mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-30 03:06:06 +02:00
Correct sqlite for //
https://github.com/alexbelgium/hassio-addons/issues/1729#issuecomment-2600850220
This commit is contained in:
@@ -85,9 +85,8 @@ if [[ "${CURRENT_BIRDSONGS_FOLDER%/}" != "${BIRDSONGS_FOLDER%/}" ]]; then
|
|||||||
|
|
||||||
# Execute the query using sqlite3
|
# Execute the query using sqlite3
|
||||||
SQL_QUERY="UPDATE notes SET clip_name = '${BIRDSONGS_FOLDER%/}/' || substr(clip_name, length('${CURRENT_BIRDSONGS_FOLDER%/}/') + 1) WHERE clip_name LIKE '${CURRENT_BIRDSONGS_FOLDER%/}/%';"
|
SQL_QUERY="UPDATE notes SET clip_name = '${BIRDSONGS_FOLDER%/}/' || substr(clip_name, length('${CURRENT_BIRDSONGS_FOLDER%/}/') + 1) WHERE clip_name LIKE '${CURRENT_BIRDSONGS_FOLDER%/}/%';"
|
||||||
|
|
||||||
if ! sqlite3 /config/birdnet.db "$SQL_QUERY"; then
|
if ! sqlite3 /config/birdnet.db "$SQL_QUERY"; then
|
||||||
echo "Paths have been successfully updated."
|
|
||||||
else
|
|
||||||
bashio::log.warning "An error occurred while updating the paths. The database backup will be restored."
|
bashio::log.warning "An error occurred while updating the paths. The database backup will be restored."
|
||||||
BACKUP_FILE="/config/birdnet.db_$(date +%Y%m%d_%H%M%S)" # Make sure this matches the earlier backup filename
|
BACKUP_FILE="/config/birdnet.db_$(date +%Y%m%d_%H%M%S)" # Make sure this matches the earlier backup filename
|
||||||
if [ -f "$BACKUP_FILE" ]; then
|
if [ -f "$BACKUP_FILE" ]; then
|
||||||
@@ -96,10 +95,28 @@ if [[ "${CURRENT_BIRDSONGS_FOLDER%/}" != "${BIRDSONGS_FOLDER%/}" ]]; then
|
|||||||
else
|
else
|
||||||
bashio::log.error "Backup file not found! Manual intervention required."
|
bashio::log.error "Backup file not found! Manual intervention required."
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo "Paths have been successfully updated."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
##################
|
||||||
|
# Correct sqlite #
|
||||||
|
##################
|
||||||
|
if [ -f /config/birdnet.db ]; then
|
||||||
|
CHECK_QUERY="SELECT COUNT(*) FROM notes WHERE clip_name LIKE '%//%';"
|
||||||
|
UPDATE_QUERY="UPDATE notes SET clip_name = REPLACE(clip_name, '//', '/') WHERE clip_name LIKE '%//%';"
|
||||||
|
# Check for occurrences of '//' in clip_name
|
||||||
|
COUNT=$(sqlite3 "$DB_FILE" "$CHECK_QUERY")
|
||||||
|
|
||||||
|
if [ "$COUNT" -gt 0 ]; then
|
||||||
|
echo "Found $COUNT rows with '//' in clip_name. Running the update query..."
|
||||||
|
sqlite3 "$DB_FILE" "$UPDATE_QUERY"
|
||||||
|
echo "Update completed"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Correct Defaults
|
# Correct Defaults
|
||||||
####################
|
####################
|
||||||
|
|||||||
Reference in New Issue
Block a user