Skip to content

Instantly share code, notes, and snippets.

@hideshi
Created December 8, 2013 13:08
Show Gist options
  • Save hideshi/7857180 to your computer and use it in GitHub Desktop.
Save hideshi/7857180 to your computer and use it in GitHub Desktop.
How to use SQLite3 in Python3.
import sqlite3
conn = sqlite3.connect("sqlite3.db")
sql = "drop table test"
conn.execute(sql)
sql = """create table test (
key int,
value varchar(20)
)"""
conn.execute(sql)
sql = "insert into test values (1, 'aaa')"
conn.execute(sql)
sql = "insert into test values (2, 'bbb')"
conn.execute(sql)
sql = "insert into test values (3, 'ccc')"
conn.execute(sql)
conn.commit()
cursor = conn.cursor()
sql = "select key, value from test"
cursor.execute(sql)
rows = cursor.fetchall()
for row in rows:
key, value = row
print(str(key) + ':' + value)
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment