一个小例子,

# -*- 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+sqlite3的更多相关文章

  1. python sqlite3使用

    python sqlite3文档地址:http://docs.python.org/2/library/sqlite3.html The sqlite3 module was written by G ...

  2. python sqlite3 数据库操作

    python sqlite3 数据库操作 SQLite3是python的内置模块,是一款非常小巧的嵌入式开源数据库软件. 1. 导入Python SQLite数据库模块 import sqlite3 ...

  3. python sqlite3 入门 (视频讲座)

    python sqlite3 入门 (视频讲座) an SQLite mini-series! - Simple Databases with Python 播放列表: YouTube https:/ ...

  4. python sqlite3简单操作

    python sqlite3简单操作(原创)import sqlite3class CsqliteTable: def __init__(self): pass def linkSqlite3(sel ...

  5. [Python]sqlite3二进制文件存储问题(BLOB)(You must not use 8-bit bytestrings unless you use a text_factory...)

    事情是这种: 博主尝试用Python的sqlite3数据库存放加密后的usernamepassword信息,表是这种 CREATE TABLE IF NOT EXISTS user ( userID ...

  6. xls===>csv tables===via python ===> sqlite3.db

    I've got some files which can help a little bit to figure out where people are from based on their I ...

  7. Python sqlite3操作笔记

    创建数据库 def create_tables(dbname): conn = sqlite3.connect(dbname) print "Opened database successf ...

  8. python sqlite3 MySQLdb

    SQLite是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成. Python就 ...

  9. python sqlite3操作类扩展,包含数据库分页

     一.原因 最近在使用python3和sqlite3编辑一些小程序,由于要使用数据库,就离不开增.删.改.查,sqlite3的操作同java里的jdbc很像,于是就想找现成的操作类,找来找去,发现一个 ...

随机推荐

  1. 利用 SerialPort 控件实现 PC 串口通信

    整理参考自<Visual C#.NET 串口通信及测控应用典型实例>1.3 节 以及 一篇博文:C# 串口操作系列(1) -- 入门篇,一个标准的,简陋的串口例子. 硬件部分 如果是两个串 ...

  2. 【Java基础】增强for循环要注意陷阱

    什么是增强for循环 增强for循环是一种简单模式的for循环,为了方便数组和集合的遍历而存在. int[] arr = new int[]{1, 2, 3, 4, 5, 6}; for (int a ...

  3. 解读(GoogLeNet)Going deeper with convolutions

    (GoogLeNet)Going deeper with convolutions Inception结构 目前最直接提升DNN效果的方法是increasing their size,这里的size包 ...

  4. 前端javascript规范文档 (http://www.xuanfengge.com/category/web)

    说明:本文档为前端JS规范 一.规范目的 为提高团队协作效率,便于前端后期优化维护,输出高质量的文档. 二.基本准则 符合web标准,结构表现行为分离,兼容性优良.页面性能方面,代码要求简洁明了有序, ...

  5. JBoss 目录结构

    安装JBoss 会创建下列目录结构: 目录 描述  bin 启动和关闭JBoss 的脚本  client 客户端与JBoss 通信所需的Java 库(JARs)  docs 配置的样本文件(数据库配置 ...

  6. 系统调用表 linux 2.6.32

    [root@localhost log]# find / |grep syscall_table /usr/src/kernels/linux-/arch/x86/kernel/syscall_tab ...

  7. careercup-递归和动态规划 9.5

    9.5 编写一个方法,确定某字符串的所有排列组合. 类似leetcode:Permutations 解法: 跟许多递归问题一样,简单构造法非常管用.假设有个字符串S,以字符序列a1a2a...an表示 ...

  8. java中最简单的方式新起一个线程

    启动一个线程在一个方法中启动一个线程,有两种方法第一种是让类实现Runable接口,这样的话编译器就会提示你实现里面的未实现的方法(就是run方法)第二种是,现在方法中new一个线程,然后直接调用他的 ...

  9. Linux下history命令详解---转载

    Linux下History命令主要用于显示历史指令记录内容, 下达历史纪录中的指令 . >History命令语法:[www.linuxidc.com@linux]# history [n][ww ...

  10. Linux--------------安装tomcat8

    系统:     CentOS 7.2x64最小化安装 IP:      192.168.0.171 二.安装JDK环境 JDK(Java Development Kit) 是 Java 语言的软件开发 ...