sqlite/tests/basic/sqlite3-test.py
Troy Dawson 9ec1bf0701 RHEL 9.0.0 Alpha bootstrap
The content of this branch was automatically imported from Fedora ELN
with the following as its source:
https://src.fedoraproject.org/rpms/sqlite#f098d15dcf04f6ef5c6e5fa63db6368d51fb2c0f
2020-10-15 09:56:24 -07:00

38 lines
851 B
Python

#!/usr/bin/python
import sqlite3
import sys
conn = None
try:
conn = sqlite3.connect('test.db')
cur = conn.cursor()
cur.execute('SELECT SQLITE_VERSION()')
ver = cur.fetchone()
print("SQLite version: %s" % ver)
# Create a new table 'Writers'
cur.execute("CREATE TABLE Writers(Id INTEGER PRIMARY KEY AUTOINCREMENT, \
Name VARCHAR(25))")
cur.execute("INSERT INTO Writers(Name) VALUES('Jack London')")
cur.execute("INSERT INTO Writers(Name) VALUES('Honore de Balzac')")
cur.execute("INSERT INTO Writers(Name) VALUES('Lion Feuchtwanger')")
# Retrieve data
for row in cur.execute("SELECT * FROM Writers"):
print(row)
cur.execute("DROP TABLE Writers")
except (sqlite3.Error) as e:
print("Error %s:" % e.args[0])
sys.exit(1)
finally:
if conn:
conn.close()