import os
import sqlite3
db_filename = 'whatever.db'
schema = '''
CREATE TABLE users(
id INTEGER PRIMARY KEY autoincrement not null,
cid INTEGER,
lang INEGER default 1)
'''
cid = 12
db_is_new = not os.path.exists(db_filename)
with sqlite3.connect(db_filename) as conn:
if db_is_new:
conn.executescript(schema)
conn.execute("""
INSERT INTO users (cid, lang) VALUES (?, ?) """ ,
(cid, 0)
)
cursor = conn.cursor()
cursor.execute('select id, cid, lang from users')
for row in cursor.fetchall():
print(row)
print('update')
cursor.execute ("UPDATE users SET lang = 22 WHERE cid=?", (cid,))
print('after update')
cursor.execute('select id, cid, lang from users')
for row in cursor.fetchall():
print(row)