Created
December 8, 2013 13:08
-
-
Save hideshi/7857180 to your computer and use it in GitHub Desktop.
How to use SQLite3 in Python3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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