时间:2021-07-01 10:21:17 帮助过:3人阅读
sqlite是个关系型的嵌入式数据库,简单易用,而且在大多数的操作系统上都默认安装了
二、基本命令
1、创建数据库
sqlite3 /data/tmp/wtv.db
2、查看数据库
sqlite> .databases seq name file --- --------------- ---------------------------------------------------------- 0 main /data/tmp/wtv.db
3、创建表
CREATE TABLE w02840(id integer primary key autoincrement, uuid char(50) not null unique, no int not null);
4、查看当前数据库下面的表
sqlite> .tables
w02840
三、导出和导入
# 导出
sqlite3 /data/tmp/wtv.db .dump > wtv.sql
# 导入
sqlite3 /data/tmp/wtv.db < wtv.sql
四、接口(Python)
# python已经内置了SQLite3驱动
#!/usr/bin/env python import json import sqlite3 import urllib2 TEMPLATES = [‘0951‘, ‘0152‘, ‘0553‘, ‘02538‘, ‘0284‘, ‘02861‘, ‘0285‘, ‘02862‘] URL = "http://127.0.0.1:8000/epg/getDetails.shtml?templateId=%s" def wuuid(c, template, url): try: response = urllib2.urlopen(url, timeout=1) except urllib2.URLError: print 0 # 接口Error则输出0 return 0 # 退出当前循环 else: data = json.load(response) if data == []: print "online %s empty" % template else: for item in data: sql = "insert into w%s (uuid, no) values (‘%s‘, %d)" % (template, item[‘uuid‘], item[‘no‘]) c.execute(sql) if __name__ == ‘__main__‘: conn = sqlite3.connect(‘/data/tmp/wtv.db‘) c = conn.cursor() for template in TEMPLATES: url = URL % template wuuid(c, template, url) conn.commit() print "Records created successfully"; conn.close()
SQLite
标签:temp 导入 comm 简单 nec load 驱动 font ted