간단하게 Sqlite3를 사용하는 법을 다음과 같이 공유한다. 우선 sqlite3를 설치하기 위해서 pip. 명령은 다음과 같다.
pip install pysqlite3
import sqlite3
dbCon = sqlite3.connect("config.db")
db = dbCon.cursor()
table_name = 'config'
cursor = db.execute("SELECT * FROM sqlite_master WHERE name = ?", (table_name,))
if cursor.fetchone():
print("database table exist")
else:
db.execute(
"CREATE TABLE config (idx INTEGER, txt TEXT)")
db.execute("INSERT INTO config (idx, txt) VALUES(?, ?)", (1, "First data",))
dbCon.commit()
cursor = db.execute("SELECT * FROM config WHERE idx = ?", (1,))
rows = db.fetchall()
print(rows)