#!/usr/bin/python
# -*- coding: utf-8 -*-



import cgi
import cgitb
import psycopg2
import sys
import os

cgitb.enable()

print "Content-type: text/html\n\n"

form=cgi.FieldStorage()


if "query" not in form:
    print "<h1>The text input box was empty.</h1>"
else:
    text=form["query"].value
    VAR_QUERY=cgi.escape(text)

con = None


try:

    con = psycopg2.connect(database='pollconfdb', user='vmuser')

    cur = con.cursor()

    cur.execute(VAR_QUERY)


    while True:

        row = cur.fetchone()

        if row == None:
            break

        print row[1], row[2], row[3], row[4], row[5], '<br>'
        

except psycopg2.DatabaseError, e:
    print 'Error %s' % e
    sys.exit(1)


finally:

    if con:
        con.close()


print '<br>'
print '<br>'
print '<a href="/index.html">Return to Homepage</a>'

