python使用sqlite3的简单代码
2018-07-20 来源:open-open
#Filename: DBcon.py
import sqlite3
import time
conn=sqlite3.connect(r'D:\Exercise\Python\DB\example.db')
c=conn.cursor()
c.execute("Create table if not exists stocks (date text, trans text, symbol text, qty real, price real)")
flag=raw_input("Do you wanna clean the table?(y/n):")
if flag=='y':
c.execute("delete from stocks")
c.execute("Insert into stocks values('"+time.strftime('%Y-%m-%d %H:%m:%S')+"', 'Buy','Rhatd',1000,23.14)")
conn.commit()
c.execute('select * from stocks')
res=c.fetchall()
count=0
print res
print '-'*60
for line in res:
for f in line:
count=count+1
print count,f,
print
print '-'*60
print '-'*60
print 'There are %d records!' %count
c.close()
conn.close()
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐