
from common.database.Database import database
import sys,time

# Simple function to do queries
def do_query(q):
    database.connect()
    c = database.cursor()
    c.execute(q)
    results = c.fetchall()
    c.close()
    # what will happen if we disconnect each time?
    database.disconnect()
    return results

# Do the query for the first time, will always work
query1 = 'SELECT * FROM TABLE(AWOPER.AW_UTIL.NEIGHBOURSTEST(4067390, 9, 9))'
data1 = do_query(query1)
print "data1: %i rows" % (len(data1))

# The RPC Timeout will occur after about half an hour
minutes = 35
for i in range(minutes):
        print "sleeping minute %i/%i" % (i,minutes)
        time.sleep(60)


# Try again, it will fail in query 2 and 3
query2 = 'SELECT * FROM TABLE(AWOPER.AW_UTIL.RADIUSTEST(15, 243.0, 27.0, 5.0/3600.0))'
data2 = do_query(query2)
print "data2: %i rows" % (len(data2))

# cx_Oracle.DatabaseError: ORA-28576: lost RPC connection to external procedure agent
