|
Zafrusteria Wanderer
Joined: 11 Oct 2000 Posts: 94 Location: United Kingdom
|
Posted: 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 |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Sat Apr 05, 2003 6:54 pm |
Use %concat to build the string passed to the Execute method.
Kjata |
|
|
|
Zafrusteria Wanderer
Joined: 11 Oct 2000 Posts: 94 Location: United Kingdom
|
Posted: 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 |
|
|
|
scobie Beginner
Joined: 01 Nov 2002 Posts: 24 Location: Sweden
|
Posted: Mon Apr 07, 2003 1:19 pm |
ough... overkill...
#MAPQUERY {[Name] LIKE '~%%-1~%'}
that's enuff
zMUD 6.16 - scobie@linux.se |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: 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 |
|
|
|
|
|