Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Sjrv
Newbie


Joined: 14 Jul 2009
Posts: 6

PostPosted: Tue Jul 14, 2009 9:04 pm   

Zmud mysql support
 
After hours of searching, googling and scouring the web I couldn't find any help or solution.
Has anybody tried creating a zmud plugin that would make zmud-mysql server communication possible via commands/functions?
The only thing I was able to write was a simple zmud->command line batch->mysql->text file<-zmud interface (using #LAUNCH command and some DDE stuff), but it's way too slow and too crude.
Yes I know that there is a database support in zmud itself, but that's not what I need right now :)
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Jul 14, 2009 9:18 pm   
 
COM is the way you'll probably want to tackle this in zMUD. It's considerably easier in CMUD (since CMUD's database module will be migrated to SQL at some point anyway) with the Lua interface and LuaSQL.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Sjrv
Newbie


Joined: 14 Jul 2009
Posts: 6

PostPosted: Wed Jul 15, 2009 8:28 am   
 
Dunno if it's a good way to write such things as it's my first time, but I was able to create an alias like that:

Alias name: /sql
Example: /sql "SELECT * FROM members WHERE id>2"
Code:
Code:

;generates an error otherwise
#IF {!%len( %1)} {#ABORT 1}
#VARIABLE Conn %comcreate( "ADODB.connection")
;a user DSN has to be defined - named MySQL, configured as connection to localhost database
#CALL @Conn.Open( "MySQL")
#VARIABLE rs @Conn.Execute( %1)
;cannot execute such a loop with anything else but SELECT due to the lack of any returned value
#IF { %word( %1, 1) =~ SELECT}
{
  #VARIABLE Fields @rs.Fields
  #VARIABLE Count @Fields.Count
;you can put anything in here - like adding the results to an array or list etc.
  #WHILE ( not @rs.EOF AND @Count)
  {
    #LOOP 0,@Count-1
    {
      #SHOW @Fields(%i).Name @Fields(%i).Value
    }
    #CALL @rs.MoveNext
  }
;cannot execute Close if query is anything else than SELECT
  #CALL @rs.Close
} {}
#VARIABLE Rows ""
#VARIABLE Fields ""
#VARIABLE rs ""
#VARIABLE Conn ""

I could bet it sucks and isn't really efficient, but at least it appears like it worked. Still needs some safety switches against any erroneous queries (since it crashes when there is a typo in query, like "SELEC * FROM members" instead of "SELECT..."). It's sure faster than my previous way of communicating with MySQL server (via #LAUNCH, dde, batch scripts and pipes), but I have my doubts :)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot 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

© 2009 Zugg Software. Hosted by Wolfpaw.net