Jump to content
  • 0

Script SQL


Kakaroto

Question


  • Group:  Members
  • Topic Count:  99
  • Topics Per Day:  0.02
  • Content Count:  624
  • Reputation:   94
  • Joined:  05/11/12
  • Last Seen:  

Hello good evening, someone could please help me with this script? I can not upgrade it to use the new rathena ... I am getting the following alerts in map_server:

[SQL]: DB error - You have an error in your SQL syntax; check the manual that co
rresponds to your MySQL server version for the right syntax to use near '' at li
ne 1
[Debug]: at ..\src\map\script.c:16961 - SELECT name FROM `char` WHERE char_id =
0 OR char_id = 0 OR char_id = 0 OR char_id = 0 OR char_id = 0 OR
[Debug]: Source (NPC): BG Ranker at new_1-1 (51,109)

script:

new_1-1,51,109,5    script    BG Ranker    55,{

    mes .name$;
    mes "I can give you the Battlegrounds Raking Information.";
    mes "Choose what do you want to know.";
    next;
    
    set .@selection, select( implode( .menu$, ":" ) ) - 1;
    
    query_sql "SELECT char_id, "+ .tables$[.@selection] +" FROM char_bg ORDER BY "+ .tables$[.@selection] +" DESC LIMIT "+ .maxsize , @char_id, @bgtop;
    
    for ( .@a = 0; .@a < .maxsize; .@a++ )
        set .@fetch_name$, .@fetch_name$ + "char_id = "+ @char_id[.@a]+ " OR ";
    
    query_sql "SELECT name FROM `char` WHERE "+ .@fetch_name$, @char_name;
    
    mes .name$;
    mes .menu$[.@selection];
    for ( .@a = 0; .@a < .maxsize; .@a++ )
        mes "["+ (.@a+1) +"] "+ ( (@char_name) ? @char_name : "^FF0000None^000000" );
    close;
    
    OnInit:
        set .name$,        "[^0000FFBattlegrounds Ranker^000000]";
        
        setarray .menu$[0],        "Top Game Win",
                                "Top Game Tie",
                                "Top Game Lost",
                                "Top Leader Game Win",
                                "Top Leader Game Tie",
                                "Top Leader Game Lost";
        
        setarray .tables$[0],    "win",
                                "tie",
                                "lost",
                                "leader_win",
                                "leader_tie",
                                "leader_lost";
                                
        set .maxsize,    5;        //Amount of player that will appear
        end;
        
}

Thank you in advance anyone who can help me.

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

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

it's caused by this.

    for ( .@a = 0; .@a < .maxsize; .@a++ )
        set .@fetch_name$, .@fetch_name$ + "char_id = "+ @char_id[.@a]+ " OR ";

the word "OR" is appended on the end of the string.

 

 

you can fix it by

create a new query that consist another sub query inside the SQL statement.

example

SELECT `a`,`b`,`c` FROM `tables1` WHERE `char_id` IN ( SELECT `char_id` FROM `char_bg` )

or

change the way to populate the string, example:

	.@fetch_name$ = "char_id = "+@char_id[0];
	for ( .@a = 1; .@a < .maxsize; .@a++ )
		set .@fetch_name$, .@fetch_name$ + " OR " + " char_id = "+ @char_id[.@a];

anyway for your case that required to check more than one variables, it's better if you just use the IN Operator.

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

query_sql "SELECT name FROM `char` WHERE "+ .@fetch_name$, @char_name;

If you replace the content of .@fetch_name$ you will find out what's wrong

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  99
  • Topics Per Day:  0.02
  • Content Count:  624
  • Reputation:   94
  • Joined:  05/11/12
  • Last Seen:  

query_sql "SELECT name FROM `char` WHERE "+ .@fetch_name$, @char_name;

If you replace the content of .@fetch_name$ you will find out what's wrong

 

 

I tried but it did not really work '-'

Edited by Kakaroto
Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

    for ( .@a = 0; .@a < .maxsize; .@a++ )
        set .@fetch_name$, .@fetch_name$ + "char_id = "+ @char_id[.@a]+ " OR ";
    
    query_sql "SELECT name FROM `char` WHERE "+ .@fetch_name$, @char_name;

>>

query_sql "SELECT name FROM `char` WHERE char_id = "+ @char_id[.@a]+ " OR ", @char_name;

there is an extra OR at the end of the query

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  99
  • Topics Per Day:  0.02
  • Content Count:  624
  • Reputation:   94
  • Joined:  05/11/12
  • Last Seen:  

XPfIsXr.png

 

nop '--'

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  26
  • Topics Per Day:  0.01
  • Content Count:  350
  • Reputation:   43
  • Joined:  09/07/12
  • Last Seen:  

query_sql("query string",@varname);

or

query_sql "query string";

https://rathena.org/wiki/Query_sql

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  99
  • Topics Per Day:  0.02
  • Content Count:  624
  • Reputation:   94
  • Joined:  05/11/12
  • Last Seen:  

it's caused by this.

    for ( .@a = 0; .@a < .maxsize; .@a++ )
        set .@fetch_name$, .@fetch_name$ + "char_id = "+ @char_id[.@a]+ " OR ";

the word "OR" is appended on the end of the string.

 

 

you can fix it by

create a new query that consist another sub query inside the SQL statement.

example

SELECT `a`,`b`,`c` FROM `tables1` WHERE `char_id` IN ( SELECT `char_id` FROM `char_bg` )

or

change the way to populate the string, example:

	.@fetch_name$ = "char_id = "+@char_id[0];
	for ( .@a = 1; .@a < .maxsize; .@a++ )
		set .@fetch_name$, .@fetch_name$ + " OR " + " char_id = "+ @char_id[.@a];

anyway for your case that required to check more than one variables, it's better if you just use the IN Operator.

 

Testing ..

Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  547
  • Reputation:   270
  • Joined:  11/08/11
  • Last Seen:  

Honestly you could solve all your problems if you merge those two sql selects and additionally increase the npcs performance too.

 

new_1-1,51,109,5    script    BG Ranker    55,{

    mes .name$;
    mes "I can give you the Battlegrounds Raking Information.";
    mes "Choose what do you want to know.";
    next;
    
    set .@selection, select( implode( .menu$, ":" ) ) - 1;
    
    query_sql "select c.name, " + .tables$[.@selection] + " from `char_bg` cb inner join `char` c on c.char_id = cb.char_id order by " + .tables$[.@selection] + " desc limit " + .maxsize, .@char_name$, .@bgtop;
    
    mes .name$;
    mes .menu$[.@selection];
    for ( .@a = 0; .@a < .maxsize; .@a++ )
        mes "["+ (.@a+1) +"] "+ ( (.@char_name$) ? .@char_name$ : "^FF0000None^000000" );
    close;
    
    OnInit:
        set .name$,        "[^0000FFBattlegrounds Ranker^000000]";
        
        setarray .menu$[0],        "Top Game Win",
                                "Top Game Tie",
                                "Top Game Lost",
                                "Top Leader Game Win",
                                "Top Leader Game Tie",
                                "Top Leader Game Lost";
        
        setarray .tables$[0],    "win",
                                "tie",
                                "lost",
                                "leader_win",
                                "leader_tie",
                                "leader_lost";
                                
        set .maxsize,    5;        //Amount of player that will appear
        end;
        
}

 

I did not test it, but you should get the idea behind it. ;)

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  99
  • Topics Per Day:  0.02
  • Content Count:  624
  • Reputation:   94
  • Joined:  05/11/12
  • Last Seen:  

Problem solved, thanks guys!

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...