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
gamesover
Novice


Joined: 06 Jun 2007
Posts: 30

PostPosted: Wed May 05, 2010 4:17 pm   

How to quote variable in SQL select in CMUD
 
Per http://www.zuggsoft.com/zmud/comado.htm, I can #call the following command sucessfully

#VAR rs @Conn.Execute( "SELECT * FROM Mudlist WHERE Title = 'Realms of Despair'")

But I failed to quote variable into the above command, such as

#VAR rs @Conn.Execute( "SELECT * FROM Mudlist WHERE Title = '%1'") ------------provided %1= Realms of Despair")

OR

#VAR rs @Conn.Execute( "SELECT * FROM Mudlist WHERE Title = '@a'") --------------provided #val a Realms of Despair
Reply with quote
gamesover
Novice


Joined: 06 Jun 2007
Posts: 30

PostPosted: Thu May 06, 2010 12:52 am   
 
Could someone give me a hand?

How to use variable in ADO mode of CMUD?

Such as

#trig {you are using (*)}

{

#VAR Conn %comcreate( "ADODB.Connection");
#CALL @Conn.Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=weapon.mdb");
#VAR rs @Conn.Execute( "SELECT action FROM weapon WHERE weapon = '%1'");
@rs.GetString

}

Thanks in advance.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu May 06, 2010 2:39 am   
 
anything in double quotes never gets expanded, parsed, or otherwise messed with. In your above examples, you are telling SQL to look for the literal string of %1. If you want to use a variable's value, you must preform the string using %concat():

$searchstring = %concat("SELECT action FROM weapon WHERE weapon='",%1,"'")
_________________
EDIT: I didn't like my old signature
Reply with quote
gamesover
Novice


Joined: 06 Jun 2007
Posts: 30

PostPosted: Thu May 06, 2010 5:02 am   
 
Thanks very much for your help. It settles!

I change the code as following, it works.

#trig {you are using (*)}

{

#VAR Conn %comcreate( "ADODB.Connection");
#CALL @Conn.Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=weapon.mdb");
$searchstring = %concat("SELECT action FROM weapon WHERE weapon='",%1,"'")
#VAR rs @Conn.Execute( $searchstring);
#echo @rs.GetString;

}
Reply with quote
gamesover
Novice


Joined: 06 Jun 2007
Posts: 30

PostPosted: Thu May 06, 2010 6:42 am   
 
Hi, I met another problem. When database serach return NULL(no result in access database), the cmud 2.37 would pop up a dialogue with some words meaning " you did not find anything from the database". But I do not want to pop up this dialogue, no result is normal result as well.

Could I set cmud not to pop up this dialogue if it selects nothing from the database?
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Thu May 06, 2010 5:57 pm   
 
No.
_________________
Taz :)
Reply with quote
Zugg
MASTER


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

PostPosted: Thu May 06, 2010 7:41 pm   
 
CMUD is just displaying the errors generated by the ADODB Windows object. If selecting nothing from the database causes ADODB to generate an error exception, then CMUD is going to display it in a popup window. No way around that, sorry.
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Thu May 06, 2010 7:46 pm   
 
Indeed! Which is why I said no, ok not a very informative answer. I also looked into connection properties and found nothing that would help either :(
_________________
Taz :)
Reply with quote
gamesover
Novice


Joined: 06 Jun 2007
Posts: 30

PostPosted: Sat May 08, 2010 7:25 am   
 
I find a way to block the dialogue.

Under Recordset mode, check both BOF and EOF, if both of them are true, which means no record found in the database, do not get the result from database.

The following code is an example.

#VAR rs %comcreate( "ADODB.Recordset")
#VAR ConnStr "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\CMUDPro\weapon.mdb"
$Sql = %concat("SELECT action FROM weapon WHERE weapon='",%1,"'")
#CALL @rs.Open( $Sql, @ConnStr,2)
#if (@rs.bof AND @rs.eof) {#beep} {action=%trim(@rs.GetString)}
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Sat May 08, 2010 10:25 am   
 
Yep that's a very good solution, well done!
_________________
Taz :)
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