@echo off
setlocal

set "PLAYERS1_DB=%~1"
set "PLAYERS2_DB=%~2"
set "PLAYER_UID=%~3"

echo Checking if player exists in players1.db...
sqlite3 "%PLAYERS1_DB%" "SELECT COUNT(*) FROM Players WHERE UID = '%PLAYER_UID%';" > temp.txt
set /p COUNT=<temp.txt
del temp.txt

if "%COUNT%"=="0" (
    echo No player data found for UID: %PLAYER_UID%
    pause
    exit /b
)

echo Transferring player data from "%PLAYERS1_DB%" to "%PLAYERS2_DB%"...

echo ATTACH DATABASE '%PLAYERS1_DB%' AS db1; > temp.sql
echo CREATE TEMP TABLE IF NOT EXISTS tmp_players AS SELECT * FROM db1.Players WHERE UID = '%PLAYER_UID%'; >> temp.sql
echo INSERT OR REPLACE INTO Players (Id, Alive, UID, Data) SELECT Id, Alive, UID, Data FROM tmp_players; >> temp.sql
echo DETACH DATABASE db1; >> temp.sql

sqlite3 "%PLAYERS2_DB%" < temp.sql

del temp.sql

echo Data transfer complete.
pause
