 |
Server Help Community forums for Subgame, ASSS, and bots
|
Author |
Message |
Deathonline Newbie
Joined: Dec 27 2008 Posts: 4 Offline
|
Posted: 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:
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
?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 |
|
Back to top |
|
 |
Grelminar Creator of Asss
Joined: Feb 26 2003 Posts: 378 Offline
|
Posted: 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. |
|
Back to top |
|
 |
Deathonline Newbie
Joined: Dec 27 2008 Posts: 4 Offline
|
Posted: Mon Jan 19, 2009 8:33 am Post subject: |
 |
|
|
|
Thanks, this worked
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")
|
|
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
Software by php BB © php BB Group Server Load: 45 page(s) served in previous 5 minutes.
|