首页 技术 正文
技术 2022年11月16日
0 收藏 611 点赞 4,163 浏览 1138 个字

一个小例子,

# -*- coding:utf-8 -*-
'''
Created on 2015年10月8日
(1.1)Python 2.7 Tutorial Pt 12 SQLite -
https://www.youtube.com/watch?v=Ll_ufNL5rDA
(1.2) sqlite3.connect(":memory:") 这个是亮点.
(1.3)
[Python] 74 Creating a database with SQLite 3 -
https://www.youtube.com/watch?v=n-Rtfd1Vv_M
db.row_factory = sqlite3.Row
在我电脑上,是否加上上面这句没什么影响.(2.1)存储中文时,同样的必须加 u . 但是直接打印出来的是 \uxxxx 格式的内容
(2.2)如果不加 u ,报错如下:
sqlite3.ProgrammingError:
You must not use 8-bit bytestrings unless you use a text_factory
that can interpret 8-bit bytestrings (like text_factory = str).
It is highly recommended that you instead just switch your application to Unicode strings.
'''
import sqlite3# con = sqlite3.connect("sample.db")
# con = sqlite3.connect(":memory:")def main():
db = sqlite3.connect(":memory:")
db.row_factory = sqlite3.Row
db.execute("drop table if exists test")
db.execute("create table test (t1 text, i1 int)")
db.execute('insert into test (t1, i1) values(?,?)', (u'一', 1))
db.execute('insert into test (t1, i1) values(?,?)', ('two', 2))
db.execute('insert into test (t1, i1) values(?,?)', ('three', 3))
db.execute('insert into test (t1, i1) values(?,?)', ('four', 4))
db.commit()
cursor = db.execute('select i1, t1 from test order by i1')
for row in cursor:
print(row) db.close()
if __name__ == "__main__": main()

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,405
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898