一个小例子,

  1. # -*- coding:utf-8 -*-
  2. '''
  3. Created on 2015年10月8日
  4. (1.1)Python 2.7 Tutorial Pt 12 SQLite -
  5. https://www.youtube.com/watch?v=Ll_ufNL5rDA
  6. (1.2) sqlite3.connect(":memory:") 这个是亮点.
  7. (1.3)
  8. [Python] 74 Creating a database with SQLite 3 -
  9. https://www.youtube.com/watch?v=n-Rtfd1Vv_M
  10. db.row_factory = sqlite3.Row
  11. 在我电脑上,是否加上上面这句没什么影响.
  12.  
  13. (2.1)存储中文时,同样的必须加 u . 但是直接打印出来的是 \uxxxx 格式的内容
  14. (2.2)如果不加 u ,报错如下:
  15. sqlite3.ProgrammingError:
  16. You must not use 8-bit bytestrings unless you use a text_factory
  17. that can interpret 8-bit bytestrings (like text_factory = str).
  18. It is highly recommended that you instead just switch your application to Unicode strings.
  19. '''
  20. import sqlite3
  21.  
  22. # con = sqlite3.connect("sample.db")
  23. # con = sqlite3.connect(":memory:")
  24.  
  25. def main():
  26. db = sqlite3.connect(":memory:")
  27. db.row_factory = sqlite3.Row
  28. db.execute("drop table if exists test")
  29. db.execute("create table test (t1 text, i1 int)")
  30. db.execute('insert into test (t1, i1) values(?,?)', (u'一', 1))
  31. db.execute('insert into test (t1, i1) values(?,?)', ('two', 2))
  32. db.execute('insert into test (t1, i1) values(?,?)', ('three', 3))
  33. db.execute('insert into test (t1, i1) values(?,?)', ('four', 4))
  34. db.commit()
  35. cursor = db.execute('select i1, t1 from test order by i1')
  36. for row in cursor:
  37. print(row)
  38.  
  39. db.close()
  40. 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. Floyd-Warshall算法的理解

    Floyd算法可以求图内任意两点之间的最短路径,三重循环搞定,虽然暴力,但是属于算法当中最难的动态规划的一种,很有必要理解. 花了一晚上和半个下午专门看这个,才看个一知半解,智商被碾压没办法. 我一直 ...

  2. POJ2407–Relatives(欧拉函数)

    题目大意 给定一个正整数n,要求你求出所有小于n的正整数当中与n互质的数的个数 题解 欧拉函数模板题~~~因为n过大~~~所以直接用公式求 代码: #include<iostream> # ...

  3. console.read()读入的内容

    今天写的特别简单的代码,大体是一个模式选择,从控制台读入一个数,然后做出相应的选择. 代码如下: using System; using System.Collections.Generic; usi ...

  4. go语言与所谓的包

    import后面接的是目录的名字,而不是所谓包的名字,并且如果一个目录下面还有目录的话都必须要写进去,比如: import "MyPackage" import "MyP ...

  5. hdoj 3549 Flow Problem【网络流最大流入门】

    Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tota ...

  6. windows 文件名太长无法删除的解决方法

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  7. iOS 使用CLGeocoder获取地理位置

    placemark(MKPlacemark类的对象)其实是geocoder(MKReverseGeocoder类的对象)的一个属性.从geocoder里面取placemark这个和直接取placema ...

  8. 【42】了解typename的双重意义

    1.在template声明中,class与typename是等价的,但是使用typename更好. 2.在template实现中,模版形参是从属名称,嵌套在模版形参中的类型是嵌套从属名称,不依赖任何t ...

  9. solr 搜索引擎

    http://www.cnblogs.com/wenxinghaha/p/4088790.html

  10. java list&lt;string&gt;组 传递到值js排列

    方法一 后台:     String sql = "select * from tree";     list = this.treeService.getTreeList(sql ...