package de.roko.genalogy.downloader.database;

import java.sql.*;

public class DatenbankDebugger {

    private static final String DB = "archion.db";


    public DatenbankDebugger() {

    }

    public void printTable(String tableName) throws Exception {
        System.out.println("\n📋 Inhalt der Tabelle: " + tableName);

        try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + DB);
             Statement stmt = conn.createStatement();
             ResultSet rs = stmt.executeQuery("SELECT * FROM " + tableName)) {

            ResultSetMetaData meta = rs.getMetaData();
            int columnCount = meta.getColumnCount();

            // Spaltenüberschriften ausgeben
            for (int i = 1; i <= columnCount; i++) {
                System.out.print(meta.getColumnName(i) + "\t");
            }
            System.out.println("\n" + "-".repeat(60));

            // Zeilen ausgeben
            while (rs.next()) {
                for (int i = 1; i <= columnCount; i++) {
                    Object val = rs.getObject(i);
                    System.out.print((val != null ? val.toString() : "NULL") + "\t");
                }
                System.out.println();
            }

        } catch (SQLException e) {
            System.err.println("⚠️ Fehler beim Zugriff auf Tabelle '" + tableName + "': " + e.getMessage());
        }
    }
}
