姜丝儿的祖屋

存档 -- 7月, 2006

用python访问sqlite-转

admin 发表于: 7月 27th, 2006 | 阅读: | 评论数: (0)

用python访问sqlite
1.首先去www.sqlite.org下载一个sqlite,它是一个嵌入式数据库,没有服务器的概念,windows版的就是一个exe,自己把它放到一个合适的目录里,然后把这个目录加入系统的path变量.
2.然后去找个pysqlite,这是python访问sqlite的接口,地址在这里 : http://initd.org/tracker/pysqlite
目前针对不同的python版本,pysqlite有两个版本:2.3和2.4,请根据自己的python版本选用.
3.然后就可以打开自己喜欢的编辑器,写一段测试代码了.
4.中文处理要注意的是sqlite默认以utf-8编码存储.
5.另外要注意sqlite仅支持文件锁,换句话说,它对并发的处理并不好,不推荐在网络环境使用,适合单机环境.

[CODE]
import pysqlite2.dbapi2 as sqlite

def runTest():
cx = sqlite.connect(‘test.db’)
cu = cx.cursor()

#create
cu.execute(”’create table catalog(
id integer primary key,
pid integer,
name varchar(10) unique
)”’)

#insert
cu.execute(‘insert into catalog values(0,0,”张小山”)’)
cu.execute(‘insert into catalog values(1,0,”hello”)’)
cx.commit()

#select
cu.execute(‘select * from catalog’)
print ’1:’,
print cu.rowcount
rs = cu.fetchmany(1)
print ’2:’,
print rs
rs = cu.fetchall()
print ’3:’,
print rs

#delete
cu.execute(‘delete from catalog where id = 1 ‘)
cx.commit()

cu.execute(‘select * from catalog’)
rs = cu.fetchall()
print ’4:’,
print rs

#select count
cu.execute(“select count(*) from catalog”)
rs = cu.fetchone()
print ’5:’,
print rs

cu.execute(“select * from catalog”)
cu.execute(‘drop table catalog’)

if __name__ == ‘__main__’:
runTest()
[/CODE]

北京地震了?看互联网反应速度

admin 发表于: 7月 4th, 2006 | 阅读: | 评论数: (0)

刚北京很多兄弟姐妹都说发生了地震,震感明显,立刻在网络上搜新闻,到现在为止,各门户都没有更新。

网络上有朋友说,河北文安发生5.1级地震,但也没有说出处。

看看各门户到底在什么时候能更新这个吧.呵呵

==

补充

新华网
2006年07月04日 12:16:23

http://news.xinhuanet.com/newscenter/2006-07/04/content_4792504.htm

新浪新闻
2006年07月04日12:16 来源新华网

http://news.sina.com.cn/c/2006-07-04/121610329013.shtml

cctv.com
2006年07月04日 12:18

http://news.cctv.com/china/20060704/102587.shtml

网易
2006-07-04 12:22:52 来源cctv

http://news.163.com/06/0704/12/2L6GOQDO0001124J.html

==

百度新闻搜索也出来了
• 快讯:河北文安发生5.1级地震 北京地区有震感 TOM 2006-7-4 12:31
• 快讯:河北文安发生5.1级地震 北京地区有震感 新华网 2006-7-4 12:16
• 河北文安发生5.1级地震 北京地区有强烈震感 QQ 2006-7-4 12:16
• 河北文安发生5.1级地震北京地区有震感 新浪 2006-7-4 12:16
• 快讯:河北文安发生5.1级地震 北京地区有震感 搜狐 2006-7-4 12:16
• 快讯:河北文安发生5.1级地震 北京地区有震感 网易 2006-7-4 12:16
---

有一条比较有意思

连线中国地震局地质研究所副所长徐锡伟http://news.QQ.com   2006年07月04日12:23

存档 -- 7月, 2006