import sqlite as dbi
#import MySQLdb as dbi
import time, sys

def executeSQLCommand(cursor, command,*args):
    rowSet = []
    command = command.strip()
    if len(command):
        try:
            cursor.execute(command,*args) # Ejecuta el comando
            if command.lower().startswith('select'): # si es una select ...
                lines = cursor.fetchall() # recuperar todos los resultados
                for line in lines:
                    row = []
                    for column in line:
                        row.append(column)
                    rowSet.append(row)
        except dbi.ProgrammingError, e:
            print e
            sys.exit()                  

    return rowSet

if __name__ == '__main__':
    if len(sys.argv) != 2:
	    print >> sys.stderr, "Usage: python %s LOCALIZACION" % sys.argv[0]
	    sys.exit(1)
    db=dbi.connect(host="localhost",user="deusto",passwd="deusto",db="deusto") #deusto es el nombre del fichero
    cursor = db.cursor()

    executeSQLCommand(cursor, "update EVENTOS set fecha=" + str(time.time()*1000))
    rowSet = executeSQLCommand(cursor, "select * from EVENTOS where LOCALIZACION = %s",sys.argv[1])
    for row in rowSet:
        print row
    del cursor
