import sqlite3
conn = sqlite3.connect('arhipT999.db')
cur = conn.cursor()
id = 0
inf = ['rian_ru']
try:
info = cur.execute('SELECT * FROM pr WHERE ch_id=?', (id, ))
if info.fetchone() is None:
cur.execute("""CREATE TABLE IF NOT EXISTS pr(
ch_id INTEGER,
sp TEXT);
""")
conn.commit()
cur.execute('insert into pr values (?, ?)', (id, inf))
conn.commit()
except sqlite3.OperationalError:
cur.execute("""CREATE TABLE IF NOT EXISTS pr(
ch_id INTEGER,
sp TEXT);
""")
conn.commit()
cur.execute('insert into pr values (?, ?)', (id, inf))
print(*cur.execute("SELECT * FROM pr;"))
b = dict(cur.execute("SELECT * FROM pr;"))
print(b)
conn.close()
Output:
(0, "['rian_ru']")
{0: "['rian_ru']"}