|
Sjrv Newbie
Joined: 14 Jul 2009 Posts: 6
|
Posted: 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 :) |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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.
|
|
|
|
Sjrv Newbie
Joined: 14 Jul 2009 Posts: 6
|
Posted: 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 :) |
|
|
|
|
|