Skip to content

Instantly share code, notes, and snippets.

@richard4339
Created April 23, 2012 17:37
Show Gist options
  • Save richard4339/2472544 to your computer and use it in GitHub Desktop.
Save richard4339/2472544 to your computer and use it in GitHub Desktop.
Sqlite
D:\Documents\Dropbox\Projects\mRPG>python sqltest.py
In getage
# Using the "dbmodule" from the previous example, create a ConnectionPool
from twisted.enterprise import adbapi
from twisted.internet import reactor, defer
dbpool = adbapi.ConnectionPool('sqlite3', "mrpg.db", check_same_thread=False)
# equivalent of cursor.execute(statement), return cursor.fetchall():
def getAge(user):
print "In getage"
return dbpool.runQuery("SELECT username FROM users WHERE username = ?", (user,))
def printResult(l):
print "In printresult"
if l:
print(l)
print l[0][0], " years old"
else:
print "No such user"
getAge("richard").addCallback(printResult)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment