Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
I_RELDB with Python

 
Post new topic   Reply to topic Printable version
 View previous topic  misc as3 stuff Post :: Post Having an issue  View next topic  
Author Message
Deathonline
Newbie


Joined: Dec 27 2008
Posts: 4
Offline

PostPosted: Sun Jan 18, 2009 12:21 pm    Post subject: I_RELDB with Python Reply to topic Reply with quote

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
Back to top
View users profile Send private message Add User to Ignore List
Grelminar
Creator of Asss


Joined: Feb 26 2003
Posts: 378
Offline

PostPosted: Mon Jan 19, 2009 6:36 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email Visit posters website
Deathonline
Newbie


Joined: Dec 27 2008
Posts: 4
Offline

PostPosted: Mon Jan 19, 2009 8:33 am    Post subject: Reply to topic Reply with quote

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")
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 45 page(s) served in previous 5 minutes.

phpBB Created this page in 0.708106 seconds : 26 queries executed (97.5%): GZIP compression disabled