I'm trying to insert the results of a query into a table, but add a variable to the result set . I've looked at some similar questions and I think I am representing the query variables correctly but I am getting a "global variable not defined" error. Can you point me in the right direction? I'm guessing it has to do with the fact that I am trying to represent a SELECT statement with a variable, but I'm not sure how the syntax should look.
def main():
datadump()
d = datetime.date.today()
queryCurs.execute('SELECT * FROM data ORDER BY ac')
sqlresults = queryCurs.fetchall()
x,y,z = sqlresults
queryCurs.execute('INSERT INTO history VALUES (?,?,?,?)',
(d, x, y, z))
createDb.commit
Thanks!
(d, a, ac, am)but I don't see any of those (other thand) defined anywhere inmain(). That seems like a good place to start.