Professional Documents
Culture Documents
14 - Gaddis Python - Lecture - PPT - ch14
14 - Gaddis Python - Lecture - PPT - ch14
Chapter 14
Database Programming
Data
import sqlite3
Row
Row
Row
Row
Row
Name Phone
Katie Allen 555-1234
This row contains data
Jill Ammons 555-5678
about one person:
Kevin Brown 555-9012
Name: Kevin Brown
Elisa Garcia 555-3456
Phone: 555-9012
Jeff Jenkins 555-7890
Leo Killian 555-1122
Marcia Potemkin 555-3344
Kelsey Rose 555-5566
cur.execute(SQLstring)
– Example:
CREATE TABLE Inventory (ItemName TEXT, Price REAL)
• Deleting a table:
DROP TABLE Inventory
– Example:
item_name = "Wrench"
price = 16.99
cur.execute('''INSERT INTO Inventory (ItemName, Price)
VALUES (?, ?)''',
(item_name, price))
conn = sqlite3.connect('chocolate.db')
cur = conn.cursor()
conn.close()
conn = sqlite3.connect('chocolate.db')
cur = conn.cursor()
cur.execute('SELECT Description, RetailPrice FROM Products')
row = cur.fetchone()
conn.close()
Operator Meaning
> Greater-Than
< Less-Than
>= Greater-Than or Equal-To
<= Less-Than or Equal-To
== Equal-To
= Equal-To
!= Not Equal-To
<> Not Equal-To