<?php
require_once 'config/database.php';
$pdo = getDB();

$sql = file_get_contents('database/triggers/trg_after_exam_attempt_submit.sql');
echo "Executing trigger SQL...\n";

// Split by DELIMITER changes and execute each part
$parts = preg_split('/DELIMITER\s+\/\//', $sql);

foreach ($parts as $part) {
    $part = trim($part);
    if (empty($part)) continue;

    // Replace // with ; for standard SQL
    $part = str_replace('//', ';', $part);

    try {
        $pdo->exec($part);
        echo "✓ Executed part\n";
    } catch (Exception $e) {
        echo "Error: " . $e->getMessage() . "\n";
    }
}

echo "Trigger installation completed.\n";
?>