jeudi 2 juillet 2015

Can't retrieve str from mySqlite3

Im trying to retrieve the latest versions of audit questions stored in table T3 of the hs_audit.sqlite. I have tried multiple versions of the cur.exectute line but keep getting a result = None. I'm new to sqlite so can anyone help me with the correct syntax. If I execute the cur.execute line as follows

cur.execute("SELECT hvq1 FROM T3 WHERE audit_ver = 1")

and remove

con.text_factory = str

it works so i think the problem must be the use of variables in the sqlite command.

max_audit_ver = 1
audit_questions = ["hvq1", "hvq2", "hvq3", "hvq4", "hvq5"]

        count = 0
        for quest in audit_questions:
            con = sqlite3.connect("hs_audit.sqlite")
            con.text_factory = str
            cur = con.cursor()
            cur.execute("SELECT '%s' FROM T3 WHERE audit_ver = '%s'" %  (quest, max_audit_version))
            result = cur.fetchone()
            con.close()
            print "Question =%s" % (quest)
            print "Audit Version =%s" % (max_audit_version)
            print "The Count Is =%s" % (count)
            print "The return from the DB is =%s" % (result)
            count += 1

Aucun commentaire:

Enregistrer un commentaire