Python SQLite Sample
感觉注释什么的都是多余的吧 :) 一个程序精简出来的东西,应该很简单。关键是我对数据库的一些东西并不是特别熟悉,算是一个例子。
import time,sqlite3,os dbfile = os.path.dirname(__file__)+"/ZeroDayDisclosure.db" print "Perparing Database...", if os.path.exists(dbfile): os.remove(dbfile) conn = sqlite3.connect(dbfile) c = conn.cursor() c.execute('''CREATE TABLE ZeroDay(InsertDate TEXT, ZeroDayName TEXT, comments TEXT, level INT, IsFixed INT)''') conn.commit() c.close() print "Done" c = conn.cursor() date = "2011-11-11" name = "hshs" comments ="hshs123" level = 5 IsFixed = 0 c.execute('''insert into ZeroDay values(\''''+date+'''\',\''''+name+'''\',\''''+comments+'''\','''+str(level)+''','''+str(IsFixed)+''')''') conn.commit() c.close() c = conn.cursor() name = 'hshs' c.execute('''select count (*) from ZeroDay where ZeroDayName = \''''+name+"\'") data = c.fetchall() print data[0][0] c.close() conn.close() print "Done all"
输出的结果为:
D:\Users\cmd4shell\Desktop>"0dayMonitor_sample.py"
|
------------------------------
文章的授權使用CC BY-ND2.5協議。凡是標示“轉載”的文章,均來源於網絡並儘可能標註作者。如果有侵犯您的權益,請及時聯繫刪除或者署名、授權。
Gtalk/Email: cmd4shell [at] gmail.com