Eric
Eric

Reputation: 295

sqlite update column with date in python

Hi I have a table in sqlite to which I add a column called "Date"

add_sql = 'ALTER table ' + table_name +' ADD MyDate text;'

I then want to update this column to contain a specific date.

update_sql = "update " + table_name + " SET MyDate = '2013-03-12';"
con.execute(add_sql)
con.execute(update_sql)

these commands work fine from command line, but not when I execute from my python script. I get the Date column, but all cells are blank.

Upvotes: 1

Views: 174

Answers (1)

CL.
CL.

Reputation: 180270

Python's sqlite3 module tries to be clever and commit automatically before some commands, but not before others.

You should call commit() whenever needed, or set isolation_level to None.

Upvotes: 1

Related Questions