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
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Mon Aug 25, 2008 3:20 pm   

Complex %mapquery usage question.
 
So, couldn't think I would see the day but purchased CMud today! Cool

Anyway, I'm re-visiting old issues again I brought up week or more ago and didn't want to spam old threads with questions that aren't into subject there.

As per suggested in one of those threads, I'm trying to work out how to use %mapquery instead of %mapfilter. Even if there's not really a major point of changing, I'd still want to learn how if not anything else than to finally learn the works.

Consider the %mapfilter script.

Code:

#call %mapfilter(%concat("Name"," LIKE ","'%",%replace(@RoomSearch,"'","''"),"%'"," AND ","ZoneID"," = ",%zonenum))


Basically I got, hopefully, a pretty good idea how SQL queries work. And getting behind the logic there doesn't seem to be so bad for me.

However, even though I think I even figured out how to concat all the stuff I want together, I'm still missing something.
And very likely I'm messing up some tables or such.

Code:

data=%mapquery(%concat("SELECT ObjID FROM ObjectTBL WHERE NAME LIKE '%",%-1,"%' AND ","ZoneID"," = ",%zonenum))


What I want to be returned: Room number from the table where room name is something or another and zoneID is current zone.

The code above works, but made a *huge* string list with about 15K items so unlikely its correct one :P

Code:

 <alias name="test" autoappend="true" id="417">
    <value>data=%mapquery(%concat("SELECT ObjID FROM ObjectTBL WHERE NAME LIKE '%",%-1,"%' AND ","ZoneID"," = ",%zonenum))</value>
  </alias>
<var name="data" type="StringList" id="1890"/>


The code above is what I use right now for testing. %-1 is value given by Test Alias: "test east" for example without quotes.

I really appreciate if someone can nudge me towards a correct way for doing this!

EDIT: Actually the %mapquery above doesn't provide any result at all. I suppose I have the ObjID wrong but it caught my eye when I looked at Map DB's spreadsheet within CMud. Excuse my probable ignorance.

Thanks.
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
Merilix
Beginner


Joined: 20 Aug 2008
Posts: 24
Location: Germany

PostPosted: Mon Aug 25, 2008 4:45 pm   
 
%mapquery accepts only the WHERE part so this should work for you:

Code:
$sql = %concat("Name like '%",%-1,"%' AND ","ZoneID"," = ",%zonenum)
data=%mapquery($sql)
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Mon Aug 25, 2008 4:57 pm   
 
Well, heh. Why don't I realize tricks like that....

Yeah, this works. Adds roomvnum to Data Variable the way its supposed to.

I really would like to learn queries like that but it seems that my personal logic considering these things always completely fails me.

Many thanks, Merilix.


Prog
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
Toxic
Adept


Joined: 27 May 2008
Posts: 299

PostPosted: Mon Aug 25, 2008 5:00 pm   
 
why cant you just do
Code:

data = %mapquery("Name like '%"%-1"%' AND ZoneID = "%zonenum)


Untested, but not sure why it wouldn't.
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Mon Aug 25, 2008 5:44 pm   
 
Meh. Yeah. This one also works. I suppose the bottom line is that I didn't know using this simple query, it'd give string list results as roomvnums...

Oh well, maybe all this needs some sort of common sense that I severely lack.

As a side note, Merlix's code gives better speed than the one Toxic gave.

Very first query came back at 18ms with Toxic's code and 8ms with Merlix' on my system.
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
Toxic
Adept


Joined: 27 May 2008
Posts: 299

PostPosted: Mon Aug 25, 2008 5:46 pm   
 
Thats weird... technically mine should be faster since its taking out one step, but maybe it takes longer to eval the functions inside the mapquery than it does inside a concat... shrug
Reply with quote
Merilix
Beginner


Joined: 20 Aug 2008
Posts: 24
Location: Germany

PostPosted: Wed Aug 27, 2008 1:19 am   
 
Hmm... looks like the first %mapquery call had to establish a db connection first
and subsequent calls just use this already open connection
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