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

@ -7,14 +7,20 @@ source /home/$USER/autopost/common.sh
checkdb() { checkdb() {
if [ "$dbtype" = "sqlite" ]; then if [ "$dbtype" = "sqlite" ]; then
if [ ! -f "$DB_FILE" ]; then if [ ! -f "$DB_FILE" ]; then
echo "La base de données n'existe pas. Création..." echo "La base de données SQLite n'existe pas. Création…"
do_createdb do_createdb
fi fi
else else
# Vérifie si la table existe, sinon crée-la # Échapper _ et % pour LIKE
exists=$(db_query "SHOW TABLES LIKE \`$MYSQL_TABLE\`;") 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 if [ -z "$exists" ]; then
echo "La table 'release' n'existe pas. Création..." echo "La table '${MYSQL_TABLE}' n'existe pas. Création…"
do_createdb do_createdb
fi fi
fi fi