import sqlite3
from contextlib import closing

with closing(sqlite3.connect("sample.db")) as connection:
    
    with closing(connection.cursor()) as cursor:
        query = """select CUST_CODE,CUST_NAME from Customer 
                where CUST_CODE in ('C00013','C00021','C00032')"""
        rows = cursor.execute(query).fetchall()
        for row in rows :
            print(row)

    print("*" * 60)
    
    with closing(connection.cursor()) as cursor:
        # list all the Sales Agents, and Order details for all Customers from India
        query = """select A.AGENT_NAME, A.PHONE_NO, 
             C.CUST_NAME, C.CUST_COUNTRY,
             O.ORD_NUM, O.ORD_AMOUNT
             from CUSTOMER C
             join ORDERS O
             on C.CUST_CODE = O.CUST_CODE
             join AGENTS A
             on O.AGENT_CODE = A.AGENT_CODE
             where C.CUST_COUNTRY = 'India'
             order by O.ORD_NUM
      """
        rows = cursor.execute(query).fetchall()
        for row in rows:
            output = """Agent -  Name: {}, Phone: {} 
             Customer - Name: {}, Country: {} 
             Order - Number: {}, Amount: ${:,.2f}
            """.format(row[0], row[1], row[2], row[3], row[4], row[5])
            print(output)
    


