Skip to content

Commit

Permalink
Correct sqlite for //
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbelgium authored Jan 19, 2025
1 parent d92a48e commit c8611fe
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions birdnet-go/rootfs/etc/cont-init.d/01-structure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ if [[ "${CURRENT_BIRDSONGS_FOLDER%/}" != "${BIRDSONGS_FOLDER%/}" ]]; then

# 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%/}/%';"

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."
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
Expand All @@ -96,10 +95,28 @@ if [[ "${CURRENT_BIRDSONGS_FOLDER%/}" != "${BIRDSONGS_FOLDER%/}" ]]; then
else
bashio::log.error "Backup file not found! Manual intervention required."
fi
else
echo "Paths have been successfully updated."
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
####################
Expand Down

0 comments on commit c8611fe

Please sign in to comment.