Server Help

ASSS Questions - I_RELDB with Python

Deathonline - Sun Jan 18, 2009 12:21 pm
Post subject: I_RELDB with Python
1) Has anyone used the I_RELDB interface from a Python module? I am under the impression that you can use the mysql stuff with Python, but I cant figure out how to call the Query function. reldb.h has the following:
int (*Query)(query_callback cb, void *clos, int notifyfail, const char *fmt, ...);
/* pyint: (int, db_res, clos -> void) dynamic failval 0, clos, int, string -> int */

In my code I have:
Code: Show/Hide

def DBCallback(status, result, p):
    pass

def mm_attach(arena):
    arena.BONUSDB   = asss.get_interface(asss.I_RELDB)


I've tried:

arena.BONUSDB.Query(DBCallback, p, 0, "SELECT blah blah")
TypeError: function takes exactly 3 arguments (4 given)

arena.BONUSDB.Query(0, res, "SELECT blah blah'")
TypeError: an integer is required

arena.BONUSDB.Query(DBCallback, p, "SELECT blah blah")
TypeError: an integer is required

And in game with exec icon_smile.gif
?py res = a.BONUSDB.Query(0,0, "SELECT * FROM tblczmedals")
TypeError: func isn't callable <- Does that mean it wont work with Python? arena.BONUSDB.GetStatus() and EscapeString work
Grelminar - Mon Jan 19, 2009 6:36 am
Post subject:
I think you want:
arena.BONUSDB.Query(DBCallback, 0, "SELECT blah blah")
You don't get to use the closure parameter yourself in python, it's used internally to call the right function. If you need to pass extra data to the callback, use a python closure (inner function, function with default arg values, or callable class instance).

Note for anyone thinking about redoing the python interface: an iterator would be more natural here.
Deathonline - Mon Jan 19, 2009 8:33 am
Post subject:
Thanks, this worked

Code: Show/Hide

def DummyCB(status, result):
        pass

def InitPlayer(p, arena):

        def DBCallback(status, result):

                if status == 0 and result:
                        p.BONUSFromDB = True

                        if arena.BONUSDB.GetRowCount(result) > 0:

                                row = arena.BONUSDB.GetRow(result)

                                p.BONUSBonuses = arena.BONUSDB.GetField(row, 0)
                                p.BONUSBan     = (arena.BONUSDB.GetField(row, 1) != 0)
                        else:   
                                arena.BONUSDB.Query(DummyCB, 0, "INSERT INTO blah blah")

        arena.BONUSDB.Query(DBCallback, 0, "SELECT blah blah")

All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group