Skip to content

Instantly share code, notes, and snippets.

@puriketu99
Created August 29, 2014 10:50
Show Gist options
  • Save puriketu99/0c4416869143be597ffe to your computer and use it in GitHub Desktop.
Save puriketu99/0c4416869143be597ffe to your computer and use it in GitHub Desktop.
【解決】sqlite3で"0001"をstringのカラムにinsertすると"1"として入る問題 ref: http://qiita.com/puriketu99/items/135542b08ad295fb8744
import sqlite3
DATABASE = "unko"
def sql4execute(sql,params=[]):
db = sqlite3.connect(DATABASE)
db.text_factory = str
cur = db.execute(sql,params)
db.commit()
db.close()
sql = "insert into unko (a) values ('0001')"
sql4execute(sql)
#unkoのaに'1'が入る
#aの桁数は固定ではないのでzero paddingできない。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment