test.db 放入 /sl4a/
test_sqlite.py 测试代码
# -*- coding: utf-8 -*-
import android
import sqlite3
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
droid = android.Android()
code = droid.dialogGetInput('6位数code:').result
if len(code)==6:
sh = code[0:2]
city = code[0:4]
else:
print 'input: code.length==6 '
sys.exit(4)
db = sqlite3.connect("test.db")
cur = db.cursor()
cur.execute("select code,cname from table where code=? ",(sh+'0000',))
for t in cur.fetchone():
print t,
print
cur.execute("select code,cname from table where code=? ",(city+'00',))
for t in cur.fetchone():
print t,
print
cur.execute("select code,cname from table where code=? ",(code,))
for t in cur.fetchone():
print t,
print
#
cur.close()
db.close()
本文介绍了一个使用Python和SQLite3模块进行数据库查询的例子。通过用户输入的六位数代码,程序将查询三个不同级别的数据,并展示如何连接到数据库、执行SQL语句及获取查询结果。
2397

被折叠的 条评论
为什么被折叠?



