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
Zafrusteria
Wanderer


Joined: 11 Oct 2000
Posts: 94
Location: United Kingdom

PostPosted: Sat Apr 05, 2003 3:36 pm   

ADO connection to mapper database
 
The tutorial pages Zugg has done are good but missed one vital bit of information. :-)

What is the syntax to use a value in a zmud variable in a sql statement.
Simple script to show all room names in your map that contain the word living.

#VARIABLE Conn %comcreate( "ADODB.Connection")
#CALL @Conn.Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Zmudtwinmapper.mdb")
#IF (@Conn.ConnectionString ="") {
#SHOW "could not open connection to database"
#ABORT
}
#VARIABLE rs @Conn.Execute( "SELECT z.name, o.name FROM ZoneTbl z, ObjectTbl o WHERE o.name LIKE '%living%' AND o.zoneid = z.zoneid ORDER BY z.name, o.name")
#ECHO @rs.GetString"
#CALL @rs.Close

The bit I'm interested in is to be able to pass a value in to the WHERE clause so I have the effect of either

WHERE o.name LIKE '%{%1}%' AND o.zoneid = z.zoneid

OR

WHERE o.name LIKE '%{@RoomName}%' AND o.zoneid = z.zoneid

needless to say neither of these work, I have also build the whole SQl statement into a variable and tried executing that as in

#var sql "SELECT * from ObjectTbl"
#VARIABLE rs @Conn.Execute( @sql)

This also fails with an error message.

So any ideas on this one?





Zaf
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Sat Apr 05, 2003 6:54 pm   
 
Use %concat to build the string passed to the Execute method.

Kjata
Reply with quote
Zafrusteria
Wanderer


Joined: 11 Oct 2000
Posts: 94
Location: United Kingdom

PostPosted: Sat Apr 05, 2003 7:11 pm   
 
DOH, I forgot about that function,

great that works a treat now. The line looks like this

#VARIABLE rs @Conn.Execute( %concat("SELECT z.name, o.name FROM ZoneTbl z, ObjectTbl o WHERE o.name LIKE '%", %1 "%' AND o.zoneid = z.zoneid ORDER BY z.name, o.name"))

Thanks,





Zaf
Reply with quote
scobie
Beginner


Joined: 01 Nov 2002
Posts: 24
Location: Sweden

PostPosted: Mon Apr 07, 2003 1:19 pm   
 
ough... overkill...
#MAPQUERY {[Name] LIKE '~%%-1~%'}

that's enuff

zMUD 6.16 - scobie@linux.se
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Mon Apr 07, 2003 2:17 pm   
 
It's not the same scobie, the way Zafrusteria is doing it, you have script access to the actual contents of the map database.

Kjata
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