#!/usr/bin/env bash
# Führt ein SQL-Skript gegen die Frigosped DC-Datenbank aus.
#
# Verwendung:
#   ./sqlrun.sh "Scripts/DC_UTILS_PKG.sql"
#   ./sqlrun.sh "Scripts/DC_UTILS_PKG.sql" "Scripts/DC_BACKEND_PKG.sql"
#   ./sqlrun.sh         # ohne Argument: interaktive SQLcl-Session

set -euo pipefail

DB_USER="wksp_ai"
DB_PASS='s!)löyx209aasgtrasdasiudkash5235FDSXljLJ'
DB_HOST="10.75.10.171"
DB_PORT="32710"
DB_SID="freepdb1"
CONNECT="${DB_USER}/${DB_PASS}@${DB_HOST}:${DB_PORT}/${DB_SID}"

export NLS_LANG="GERMAN_GERMANY.AL32UTF8"

cd "$(dirname "$0")"

if [ $# -eq 0 ]; then
    echo "Interaktive SQLcl-Session (Strg+D zum Beenden)"
    exec sql "$CONNECT"
fi

for script in "$@"; do
    echo ">>> $script"
    sql "$CONNECT" @"$script"
    echo
done
