Created
June 23, 2014 06:42
-
-
Save aguegu/4b28ea89da9c35a8d2d1 to your computer and use it in GitHub Desktop.
why python sqlite3 convert str to number by default?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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