Created
April 23, 2012 17:37
-
-
Save richard4339/2472544 to your computer and use it in GitHub Desktop.
Sqlite
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
D:\Documents\Dropbox\Projects\mRPG>python sqltest.py | |
In getage |
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
# 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