Skip to content

Instantly share code, notes, and snippets.

@aguegu
Created June 23, 2014 06:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save aguegu/4b28ea89da9c35a8d2d1 to your computer and use it in GitHub Desktop.
why python sqlite3 convert str to number by default?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3
import sys
con = None
try:
con = sqlite3.connect(':memory:')
con.execute('create table tbl (val string);')
con.commit()
l = [tuple('%d' % s) for s in range(10)]
print l
# [('0',), ('1',), ('2',), ('3',), ('4',), ('5',), ('6',), ('7',), ('8',), ('9',)]
con.executemany('insert into tbl (val) values(?)', l)
con.commit()
cur = con.cursor()
cur.execute('select * from tbl;')
print cur.fetchall()
# [(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,)]
cur.close()
except sqlite3.Error, e:
print "Error %s:" % e.args[0]
sys.exit(1)
finally:
if con:
con.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment