1
0

reecriture fonction checkdb

This commit is contained in:
unfr 2025-08-09 09:26:35 +02:00
parent e38d98b1a1
commit 69aef9fb9f

View File

@ -5,19 +5,25 @@ source /home/$USER/autopost/common.sh
# ========== FONCTIONS SCRIPT ==========
checkdb() {
if [ "$dbtype" = "sqlite" ]; then
if [ ! -f "$DB_FILE" ]; then
echo "La base de données n'existe pas. Création..."
do_createdb
fi
else
# Vérifie si la table existe, sinon crée-la
exists=$(db_query "SHOW TABLES LIKE \`$MYSQL_TABLE\`;")
if [ -z "$exists" ]; then
echo "La table 'release' n'existe pas. Création..."
do_createdb
fi
if [ "$dbtype" = "sqlite" ]; then
if [ ! -f "$DB_FILE" ]; then
echo "La base de données SQLite n'existe pas. Création…"
do_createdb
fi
else
# Échapper _ et % pour LIKE
local pattern=${MYSQL_TABLE//_/\\_}
pattern=${pattern//%/\\%}
# Assure-toi que db_query utilise `mysql -N -B` pour ne pas avoir d'entêtes
local exists
exists=$(db_query "SHOW TABLES LIKE '${pattern}';" | tr -d '[:space:]')
if [ -z "$exists" ]; then
echo "La table '${MYSQL_TABLE}' n'existe pas. Création…"
do_createdb
fi
fi
}
do_start() {