Sat Jul 28, 2012 12:04 am
import sqlite3 as sdb
myConnection = sdb.connect('/tmp/test.db')
cursorObj = myConnection.cursor()
cursorObj.execute('SELECT SQLITE_VERSION()')
## printing the version value
Vdata = cursorObj.fetchone()
print "SQLite version: %s" % Vdata
## create a user table
cursorObj.execute('CREATE TABLE IF NOT EXISTS user( firstname VARCHAR(43), age INTEGER)')
## add data to table user
cursorObj.execute('insert into user values (?,?)', ('sam',43) )
## get tables' info from sqlite_master
my_data = (
('Jim','Sead'),
('Tom','Fadi'),
('Kely','Noras'),
('Eid','Esa')
)
cursorObj.executemany('INSERT INTO user(firstname,lastname) VALUES(?,?)',my_data)
myConnection .commit()
cursorObj.execute("SELECT * FROM user")
FetchedData = cursorObj.fetchall()
for record in FetchedData:
print "%-2s %-10s " % (record ["firstname"], record ["lastname"])
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.