import psycopg2
import sys

try:
    # Try connecting with psycopg2 directly
    conn = psycopg2.connect(
        dbname='artdb',
        user='postgres',
        password='Figur@tive94!',
        host='localhost',
        port='5432',
        options='-c client_encoding=WIN1252'
    )
    print("Connection successful!")
    
    # Test creating a table
    with conn.cursor() as cur:
        cur.execute("""
            CREATE TABLE IF NOT EXISTS test_table (
                id SERIAL PRIMARY KEY,
                name VARCHAR(100)
            )
        """)
    conn.commit()
    print("Test table created successfully!")
    
    conn.close()
    
except Exception as e:
    print(f"Error: {str(e)}", file=sys.stderr)
    sys.exit(1)
