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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
umdbandit
Wanderer


Joined: 31 Oct 2004
Posts: 94

PostPosted: Mon Aug 25, 2008 6:52 pm   

Tutorial Request: Connecting to an external Database
 
Hey all,

For a while now, I've been reading a lot about the addition of the SQLite database and such. I've also previously tried to connect my Cmud (and zmud) to external databases with pretty much no success. I was wondering if anyone could walk me through setting up and connecting to an external database. In the past, I havnt been able to use more than one table with the built in db thing, and as far as I can tell, it is still like that. I know the db module is coming soon, but I have a project that I'd like to move ahead with, before that upgrade is made.

If there's another work around/solution that would solve my need for multiple tables, I am all ears. In the past, I have just been using implicit tables stored column by column as string lists. It is clunky and all the queries are homemade and slow :P Time to move on.

I'm running windows XP with the most recent registered version of CMUD. I'm willing to install/use any database that you all want me to, provided my queries will run reasonably quick :)

I also plan on, after making this work for me, polishing it off and putting it into the CMUD knowledge base so that others may use it later.

Thanks ahead of time all,

-R
_________________
Rufus- Winner of Stuff
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Aug 25, 2008 10:23 pm   
 
Even though the "db module" won't be done until after the mapper rewrite (so probably not until later in 2009), you might be surprised how soon you might see commands and functions added to CMUD to handle SQLite databases.

In other words, the rewrite of the DB Module "User Interface" won't be done for many many months. But in the work that I've been doing on the new mapper (which uses SQLite 3.0), the addition of commands and functions to manipulate SQLite (2 and 3) tables is being added very very soon.

The main reason for this is that in the past, the mapper used Microsoft ADO/MDAC database format, and you could access the mapper data directly by creating COM objects for ADO. But with the migration to SQLite, you would lose this capability because you cannot create simple COM objects for SQLite. So there might be people using COM objects who couldn't use the new mapper because of this.

To allow these ADO COM scripts to be converted into something that would work with the new SQLite map database, I am adding the commands and functions needed to access the SQLite database directly.

You can currently do this via the Lua support in CMUD, but it's very tricky. I decided it was just better to add native support to this for CMUD.

So, if you are willing to wait another few weeks and deal with the new 3.x beta version, that might be the best. Or I'm sure someone can go ahead and help you figure out how to do SQLite via the Lua interface. But I recommend that you stick with SQLite as the database if you can, since you'll eventually get the native support (and eventually the new DB Module GUI).
Reply with quote
umdbandit
Wanderer


Joined: 31 Oct 2004
Posts: 94

PostPosted: Mon Aug 25, 2008 10:54 pm   
 
Awesome.. Thanks a ton Zugg. Currently about to sit down for dinner, but I cant wait to get home and play around with it all. Responses like this are what makes me happy to have purchased (and happy to continue purchasing) your products.

-R
_________________
Rufus- Winner of Stuff
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Tue Aug 26, 2008 1:12 am   
 
While it's not a formalized tutorial, here are some brief notes on what I did to get LuaSQL working on CMUD. I'll eventually do one, but it won't be for a while. Hopefully before Zugg does the database module so it's actually useful to someone else.
_________________
Asati di tempari!
Reply with quote
Merilix
Beginner


Joined: 20 Aug 2008
Posts: 24
Location: Germany

PostPosted: Tue Aug 26, 2008 1:43 am   
 
in zMud i had something like this to access the mapper database via com object:
Code:

#VAR Conn %comcreate( "ADODB.Connection")
#CALL @Conn.Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\zMUD\UNItopia\UNItopia.mdb")
#EXECUTE %concat( "#VARIABLE Rooms @Conn.Execute( ", %char( 34), "SELECT ObjID,X,Y FROM ObjectTbl WHERE ObjId = ", %roomnum, , %char( 34), ")")
#CALL @Rooms.MoveFirst
#say "MapX="[@Rooms("X")/240]", MapY="[@Rooms("Y")/-240]
Conn=""

may need to be adaptet for CMUD but when sqlite ODBC driver is installed this could possibly work.

-- edit
just now testet in cmud:
Code:

#VAR Conn %comcreate( "ADODB.Connection")
#call @Conn.Open("DSN=SQLite Datasource;Database=D:\Programme\CMUD\muds.db")
#EXECUTE %concat( "#VAR Mudlist @Conn.Execute( ", %char( 34), "SELECT Title FROM Mudlist",%char( 34), ")")
Result=""
#while (not(@Mudlist.Eof)) {
  Result=%additem(@MudList("Title"),@Result)
  @Mudlist.MoveNext
}
#say @Result

That works but there may be a better solution.

@Tech: I tried your Lua example but it does nothing. Anyhow, it would be interesting for me.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Tue Aug 26, 2008 5:26 am   
 
What exactly didn't work for you? Did you remember download the sqlite dll from luasql website?
_________________
Asati di tempari!
Reply with quote
Merilix
Beginner


Joined: 20 Aug 2008
Posts: 24
Location: Germany

PostPosted: Tue Aug 26, 2008 2:13 pm   
 
ahh yes, that works.
I just tried sqlite3dll from cmud root and was wondering about absolute no feedback.

edit:
Quote:
if zs.numparam ~= 0 then
dbName = zs.param(1)

what is zs? It looks like an object to access zscript stuff. Is it somewhere documented?
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Aug 26, 2008 5:11 pm   
 
CMUD Documentation: Open Feature Reference, then Lua Scripting, then zs Object: http://www.zuggsoft.com/kb/cmud_lua_zs
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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