简体   繁体   中英

Python isn't posting to Sqlite3 Db

I'm hoping someone can point a mistake I've made.... I can manually post to the db file through the terminal, but when I run the python script no data posts to the table.

def logDoors(door):
    conn =  sqlite3.connect('doorlog_db')
    c = conn.cursor()
    c.execute('CREATE TABLE IF NOT EXISTS history (date REAL, door TEXT)')
    date = format(datetime.datetime.now())
    c.execute("INSERT INTO history (date, door) VALUES (?, ?)",
            (date, door))
    conn.commit()
    conn.close()

Looks like you're connecting to a file with no extension. Did you try this?

conn =  sqlite3.connect('doorlog_db.sqlite')

Problem solved, it was actually an issue with the db reading program I was using. The two db's had been created with differential extensions. The db reader didn't recognize the file with the _db as a file it could open even though it could. Therefore I was opening the .db file which wasn't being wrote to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM