python+sqlite3
一个小例子,
# -*- 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的更多相关文章
- python sqlite3使用
python sqlite3文档地址:http://docs.python.org/2/library/sqlite3.html The sqlite3 module was written by G ...
- python sqlite3 数据库操作
python sqlite3 数据库操作 SQLite3是python的内置模块,是一款非常小巧的嵌入式开源数据库软件. 1. 导入Python SQLite数据库模块 import sqlite3 ...
- python sqlite3 入门 (视频讲座)
python sqlite3 入门 (视频讲座) an SQLite mini-series! - Simple Databases with Python 播放列表: YouTube https:/ ...
- python sqlite3简单操作
python sqlite3简单操作(原创)import sqlite3class CsqliteTable: def __init__(self): pass def linkSqlite3(sel ...
- [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 ...
- 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 ...
- Python sqlite3操作笔记
创建数据库 def create_tables(dbname): conn = sqlite3.connect(dbname) print "Opened database successf ...
- python sqlite3 MySQLdb
SQLite是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成. Python就 ...
- python sqlite3操作类扩展,包含数据库分页
一.原因 最近在使用python3和sqlite3编辑一些小程序,由于要使用数据库,就离不开增.删.改.查,sqlite3的操作同java里的jdbc很像,于是就想找现成的操作类,找来找去,发现一个 ...
随机推荐
- HUD-4602 Partition 排列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4602 把n等效为排成一列的n个点,然后就是取出其中连续的k个点.分两种情况,一种是不包含两端,2^( ...
- POJ-3468 A Simple Problem with Integers Splay Tree区间练习
题目链接:http://poj.org/problem?id=3468 以前用线段树做过,现在用Splay Tree A了,向HH.kuangbin.cxlove大牛学习了各种Splay各种操作,,, ...
- mac使用初级
imac使用的是login shell,所有开启一个terminal的时候,不会运行.bashrc文件,而是运行.bash_profile文件,因此只需要中home目录新建一个.bash_profil ...
- linux定时运行命令脚本——crontab
cron和crontab定时任务: http://blog.csdn.net/ithomer/article/details/6817019 http://blog.sina.com.cn/s/blo ...
- tomcat运行问题解决方法
早上过来遇到一个非常奇怪的问题,运行一个新的项目,运行环境都没问题,可是在调试的时候,总是出错. 错误代码: log4j:WARN No appenders could be found for lo ...
- APNs消息推送完整讲解
在项目的AppDelegate中的didFinishLaunchingWithOptions方法中加入下面的代码: [[UIApplication sharedApplication] registe ...
- linux中vi/vim显示行号设置
vim打开文件是,默认不提示行号. 至于显示行号的用途,因人而异 临时修改只需要在编辑文件时输入 :set number 即可 linux下一个主机可能有N个账户.对于配置分为两种:仅配置当前账户,配 ...
- [SCOI2005]互不侵犯King
题目描述 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. ——by洛谷 https://www. ...
- freemarker 数字,字符的操作
1. 数据类型转换: ${xx?string} //字符串 ${xx?number}//整数 ${xx?currency}//小数 ${xx?percent}//百分比 2. 截取字符串长度 有的时候 ...
- IOS ScrollowView 滑动到边缘后不允许再拖动
当scrollowview滑动图片时,滑动到最后一张图本应该不让其滑动,但是如果不可以去设置属性,依然可以滑动,露出白色的底色,挺影响美观的, 可以设置其属性: sv.bounces=NO; 这样就不 ...