Jump to content
  • 0

SQL in script


Fratini

Question


  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  153
  • Reputation:   8
  • Joined:  07/01/14
  • Last Seen:  

Hi!

The script check if the map where the user died is in the table 'maps_nod'. It returns 1 if the map is there. The 'var1' is INT and has 1 in all maps.

query_sql "SELECT `var1` FROM `maps_nod` WHERE `map_name`='"+strcharinfo(3)+"'",@map;
if(!@map){

I tried using only strings before but still didn't work.

query_sql "SELECT `map_name` FROM `maps_nod` WHERE `map_name`='"+strcharinfo(3)+"'",@map$;
if(!@map$){

I don't know what else I can do =\

 

Thank you for your time

 

Edit:

After a LONG search and research through google, rAthena I found nothing useful. I start to search for new commands that I didn't know in script_commands and BAM! Fixed  /no1

 

For those who have or had the same problem...

Use escape_sql(<value>):

*escape_sql(<value>)

Converts the value to a string and escapes special characters so that it is safe to
use in query_sql(). Returns the escaped form of the given value.

Example:
	.@name$ = "John's Laptop";
	.@esc_str$ = escape_sql(.@name$); // Escaped string: John\'s Laptop

In my case will be like:

query_sql "SELECT `map_name` FROM `maps_nod` WHERE `map_name`='"+escape_sql(strcharinfo(3))+"'",@map$;
if(!@map$){

Or I could do like:

set @str$,strcharinfo(3);
query_sql "SELECT `map_name` FROM `maps_nod` WHERE `map_name`='"+escape_sql(@str$)+"'",@map$;
if(!@map$){
Edited by Fratini
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  54
  • Topics Per Day:  0.01
  • Content Count:  513
  • Reputation:   84
  • Joined:  08/11/12
  • Last Seen:  

Well, I'm not really sure how will be able to help you with so little info on what you're trying to achieve. :)

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10018
  • Reputation:   2373
  • Joined:  10/28/11
  • Last Seen:  

@Ninja

I believe Fratini solved his issue by adding the usage of escape_sql when using query_sql.

 

certain characters required to use escape_sql to be used in SQL statement. 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  54
  • Topics Per Day:  0.01
  • Content Count:  513
  • Reputation:   84
  • Joined:  08/11/12
  • Last Seen:  

@Emistry

Yes I understand. I was looking into future posts :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...