In [10]:
import sqlite3

In [11]:
db = "./mydb.db"
conn = sqlite3.connect(db)
c = conn.cursor()

In [ ]:
cmd = "CREATE TABLE my_table (Name TEXT NOT NULL,\
                               Age INTEGER NOT NULL)"

c.execute(cmd)

In [13]:
conn.commit()

In [15]:
cmd = "ALTER TABLE my_table ADD COLUMN Salary INTEGER NOT NULL DEFAULT 0"
c.execute(cmd)
conn.commit()

In [20]:
cmd = "INSERT INTO my_table VALUES ('Joe', 32, 5000)"
c.execute(cmd)
conn.commit()

In [23]:
cmd = "INSERT INTO my_table VALUES ('{}', {}, {})".format('Kat', 50, 7000)
print cmd
c.execute(cmd)
conn.commit()


INSERT INTO my_table VALUES ('Kat', 50, 7000)

In [28]:
names = [ \
         ('James', 26, 2000),
         ('Lot', 66, 9000),
         ('Ian', 36, 4000),
]

c.executemany("INSERT INTO my_table VALUES (?,?,?)",names)
conn.commit()

In [29]:
conn.close()

In [30]:
db = "./mydb.db"
conn = sqlite3.connect(db)
c = conn.cursor()

In [31]:
c.execute("SELECT * from my_table where Name='Joe'")
result = c.fetchall()
print result


[(u'Joe', 32, 5000)]

In [33]:
c.execute("SELECT * from my_table where Age > 30")
result = c.fetchall()
print result
print result[2]


[(u'Joe', 32, 5000), (u'Kat', 50, 7000), (u'Lot', 66, 9000), (u'Ian', 36, 4000)]
(u'Lot', 66, 9000)

In [34]:
conn.close()

In [ ]: