Python Forum
Sqlite 3 Database is not updating after using commit()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sqlite 3 Database is not updating after using commit()
#5
There is something with your data. Otherwise your code works for me

import sqlite3

setup_sql = """BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "Encounters" (
	"name"	TEXT,
	"encounters"	INTEGER,
	"PreEnc"	INTEGER,
	"PostEnc"	INTEGER
);
INSERT INTO "Encounters" ("name","encounters","PreEnc","PostEnc") VALUES ('John Doe',0,20,0);
COMMIT;"""

sumlst = 12345
user = 'John Doe'

conn = sqlite3.connect('Encounters_new.db')
c = conn.cursor()
c.executescript(setup_sql)
for row in c.execute("SELECT * FROM Encounters WHERE name = ?", [user]):
  print(row)   
c.execute("UPDATE Encounters SET PostEnc=? WHERE name=?", (sumlst, user))
conn.commit()
for row in c.execute("SELECT PostEnc FROM Encounters WHERE name = ?", [user]):
  print(row)
for row in c.execute("SELECT PreEnc FROM Encounters WHERE name = ?", [user]):
  print(row)
for row in c.execute("SELECT * FROM Encounters WHERE name = ?", [user]):
  print(row)  
Output:
('John Doe', 0, 20, 0) (12345,) (20,) ('John Doe', 0, 20, 12345)
Gribouillis likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Sqlite 3 Database is not updating after using commit() - by buran - Oct-19-2020, 08:01 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020