# -*- coding:utf-8 -*- import sqlite3 conn = sqlite3.connect('filtersys.db') cursor = conn.cursor() # 创建表 cursor.execute('create table bad_behaviors (id INTEGER primary key AUTOINCREMENT, devid INTEGER, date NUMERIC)' ) # 插入数据 devid = 15 print "insert into bad_behaviors (devid, date) select " + str(devid) + ",date('now','localtime')" cursor.execute("insert into bad_behaviors (devid, date) select ?,datetime('now','localtime')", (devid, )) devid = 18 cursor.execute("insert into bad_behaviors (devid, date) select ?,datetime('now','localtime')", (devid, )) # 查询 cursor.execute("select * from bad_behaviors where devid=18") rs = cursor.fetchall() print rs cursor.close() conn.commit() conn.close()
|