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
Turncoat
Newbie


Joined: 19 Sep 2011
Posts: 5

PostPosted: Tue Nov 20, 2012 7:57 am   

Querying a database
 
Hello Everyone!

So this is the first time I've tried using databases in cMUD. I created a normal database within cMUD and I also created an sqlite database using sqliteman. I went ahead and put some test data in it so I could mess around. The database is called "testing", and currently the only table in the database is one called "mobtab". The table "mobtab" has only 2 fields, "shortName" and "longName". This table is for holding mob information, the longName is the string/sentence of a mob when you see it in a room. The shortName is the name used for interactions with the mob (killing it, or talking to it, or giving it something).

What I am trying to do is query the database for a match and if there is one, add the shortName to a string list. The stringlist will be used later for various tasks (checking for new items being sold, or killing them, or checking for keys), this last part isn't exactly important at this time. The only thing I am racking my brain over right now is just retrieving that information.

If any help could be provided, It would be greatly appreciated!

I am currently using cMUD 3.34. Thanks!
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Nov 20, 2012 1:41 pm   
 
To open the sqlite database, you use the command:
Code:
#SQLDB testing.db

To query the database, you can execute SQL code, such as:
Code:
$row = %sql(testing, "SELECT * FROM mobtab")

You can manipulate or display the data returned in $row with various methods, like:
Code:
#WHILE (!$row.EOF()) {
  #SHOW $row.Item("shortName") " : " $row.Item("longName")
  #CALL $row.Next
}

When you are done, you can close the database with:
Code:
#SQLCLOSE testing


See the documentation for #SQLDB, #SQLCLOSE, %sql, and %sqldb.
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