[Twisted-Python] multiple mysql results in function

Ryan McGuire RDMcGuire01 at indianatech.net
Wed Dec 12 12:26:00 EST 2007

 I am using xmlrpc to send and recieve messages to a "thought board" kind of thing, and being COMPLETELY new to python and twisted, I am kind of stuck on something.

I have everything working except for the fact that I want to return multiple rows when I run the mysql query.

Here is the code I have:

from twisted.web import xmlrpc, server
import MySQLdb
from twisted.enterprise import adbapi

class itr(xmlrpc.XMLRPC):

    def xmlrpc_thought(self, uname, pwrd, arg, msg):
        """Return the most recent thought"""
        if arg == "get":
                return db.runQuery("""
                        SELECT * FROM thoughts
                        WHERE tid > (SELECT curtid FROM users
                        WHERE uid = (SELECT uid FROM users
                        WHERE username='%s' AND password='%s'))
                """ % (uname, pwrd)).addCallback(lambda results: results[0][2])
        if arg == "post":
                        INSERT INTO thoughts(uid,thought)
                        VALUES((SELECT uid FROM users WHERE
                        username='%s' AND password='%s'),
                """ % (uname, pwrd, msg))
                x='Thought added'
                return x

if __name__ == '__main__':
    from twisted.internet import reactor
    r = itr()
    reactor.listenTCP(8899, server.Site(r))

I believe something needs to be changed in the callback, but I very well may be wrong.

Thanks in advance!

RDMcGuire01 at indianatech.net

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20071212/07ad6c41/attachment.htm 

More information about the Twisted-Python mailing list