http://www.runoob.com/sqlite/sqlite-data-types.html
python和SQLlite ,SQLite是内嵌数据库
import sqlite3
cx=sqlite3.connect("D:/database.db")
cur=cx.cursor()
#cur.execute('create table users(login varchar(8),uid integer)')
cur.execute('insert into users values("join",100)')
cur.execute('select * from users')
for eachuser in cur.fetchall():
print eachuser
cur.close()
cx.commit()
cx.close()
数据库的几种数据类型
Date 时间格式 varchar(n) n字符格式 int 整型数据
try:
cur.execute('insert into users values("join",100)')
except:
cur.execute('create table users(login varchar(8),uid integer)')
用try来测试没有创建的表格
其实还会有其他错误,用error的属性来判断就可以了。其他更好的方法我也不知道
搜索语句
select bname from business where bname like '%Pizza%'
加上排序
select bname,bcount from business where bname like '%Pizza%' order by bcount desc
选取前10个
select bname,bcount from business where bname like '%Pizza%' order by bcount desc limit 10
测试某个表是否存在
"select count(*) from sqlite_master where type='table' and name='SavedData'"
返回的数据格式,你要取[0][0]
两个表之间
select id, sentence from Reviews where id in (select id from SavedData where data = '1000')
cur.fetchall()
分组统计
SELECT stars,count(stars) from reviews WHERE business_id = "eT5Ck7Gg1dBJobca9VFovw" GROUP BY stars
数据库出错,一个是语法问题,第二个问题是有时候数据本身有一些特殊字符,需要转义一下?? 比如双引号就不行,还有-也是不行的。
关于SQLite
官方网站:
http://www.sqlite.org/about.html 这个吧
中文的图书,有一本《SQLite权威指南》 好像已经买不到新书了
有一个可视化管理数据库的软件
http://www.cr173.com/soft/36343.html
上面那个数据量有点大的时候,后面死活打不开了
一个很简单的数据库管理软件,后来电脑下了几个dll
http://sqlitebrowser.org/
回Py的主要函数
http://blog.csdn.net/artemisrj/article/details/39254741
select id, sentence from Reviews where id in (select id from SavedData where data = '1000')