Skip to content

Instantly share code, notes, and snippets.

@fereria
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fereria/d643199e0fc3ee314666 to your computer and use it in GitHub Desktop.
Save fereria/d643199e0fc3ee314666 to your computer and use it in GitHub Desktop.
sqlite decorator test
## -*- coding: utf-8 -*-
"""
DecoでConnect
"""
import sqlite3
import charcode
def dbConnect(func):
def _dbConnect(*args,**kw):
con = sqlite3.connect("./db/jpTest.db")
csr = con.cursor()
result = func(csr)
con.close()
return result
return _dbConnect
@dbConnect
def test(csr=None):
csr.execute('select name,price from test;')
for name,price in csr.fetchall():
print name.encode('utf-8')
print price
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment