I'm changing code that writes data to a DB, so I have a dump (a text file) of an earlier run to compare against, to ensure that my changes don't screw things up. Here goes:
def dbcheck(cursor): dbresult = list() cursor.execute("SELECT COLUMN FROM TABLE") for item in cursor.fetchall(): line = item + "\n" dbresult.append(line) with open(dbdump) as f: for n, line in enumerate(f): if line != dbresult[n]: print("DB content does not match original data!")
This code runs fine, but I'm worried that
dbresult can grow really large, so am looking for a less risky way of doing this. I'm also curious of what else can be improved.
[sidenote] I left out exception handling for the sake of simplicity/clarity.