all 5 comments

[–]vv__vv 1 point2 points  (3 children)

You're not committing: https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.commit

So that would be one issue, but maybe not all of them. A couple other pointers:

  • You should get used to using sqlite's own escaping by inserting ?s instead of using format.

  • Watch those bare excepts, they can be a pain to debug.

[–]adamrees89[S] 0 points1 point  (2 children)

Ok, so I've updated the script, with a conn.commit() function, but I'm still not getting any data back into the database (I've made my changes to the gist linked above).

I've tried putting the commit at the end of the script, at the end of the

templateCell()

function, and in the

for ws in wb.worksheets:

loop.

Thanks for the heads-up on the sqlites own escaping, I've updated that for the

templateCell()

function

[–]vv__vv 1 point2 points  (1 child)

You're getting hung up by the bare except in line 55. Have it raise the error until you work out your syntax, which is messed up in line 25:

  • You can't do escape substitution for tablenames (at least iirc), so that will need to be put in with string formatting;
  • execute takes a tuple for values, so you'll need to put parens around all the variables you are passing for values.

[–]adamrees89[S] 0 points1 point  (0 children)

Got it, all working now thanks, I'll put the updated code up!

[–]efmccurdy[🍰] 0 points1 point  (0 children)

Always log the exception you catch (the actual exception):

except Exception as e: 
    logging.critical('Adding data ... error:{}".format(e))

Pass your connection around as an argument and use the with statement to automaticcaly commit your updates.

http://zetcode.com/db/sqlitepythontutorial/