Raised This Month: $51 Target: $400
 12% 

Whats wrong with this SQL query?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jonatat
Senior Member
Join Date: Dec 2017
Old 06-15-2018 , 05:33   Whats wrong with this SQL query?
Reply With Quote #1

PHP Code:
new MVPsteamid[32]
new 
MLPsteamid[32]
get_user_authidtopKilleridMVPsteamidcharsmax(MVPsteamid))
get_user_authidtopDeathsidMLPsteamidcharsmax(MLPsteamid))
new 
szQuery[1000];

formatexszQuery999"UPDATE `users` SET `MVP` = 'MVP + 1' WHERE steam_id = '%s';"MVPsteamid); 
formatexszQuery999"UPDATE `users` SET `MLP` = 'MLP + 1' WHERE steam_id = '%s';"MLPsteamid); 
formatexszQuery999"UPDATE `matches` SET `MVP_steamid` = '%s', `MLP_steamid` = '%s' WHERE match_id = '%s';"MVPsteamidMLPsteamidszLine); 
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 
Whats wrong with this? I'm getting only 'matches' but not +1 MVP or + 1 MLP into database...
jonatat is offline
shauli
Member
Join Date: Jun 2018
Old 06-15-2018 , 05:57   Re: Whats wrong with this SQL query?
Reply With Quote #2

You are overwriting 'szQuery' again and again. The problem is in the amxx code, not in the query.
Try something like this:
PHP Code:
formatexszQuery999"UPDATE `users` SET `MLP` = 'MLP + 1' WHERE steam_id = '%s';"MLPsteamid);  
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 
formatexszQuery999"UPDATE `matches` SET `MVP_steamid` = '%s', `MLP_steamid` = '%s' WHERE match_id = '%s';"MVPsteamidMLPsteamidszLine);  
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 
Also I recommend you to merge the 1st and the 2nd query to a single query.

You can also try like this:
PHP Code:
formatexszQuery999"UPDATE `users` SET `MLP` = 'MLP + 1' WHERE steam_id = '%s';UPDATE `matches` SET `MVP_steamid` = '%s', `MLP_steamid` = '%s' WHERE match_id = '%s';"MLPsteamidMVPsteamidMLPsteamidszLine);  
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 
But i'm not sure if it's works in here. As far as I know, you have to pre-configure that you want to allow multiple queries and I don't know if it's possible in AMXX, but worth a try.
shauli is offline
jonatat
Senior Member
Join Date: Dec 2017
Old 06-15-2018 , 06:23   Re: Whats wrong with this SQL query?
Reply With Quote #3

Thanks for reply. Ok so i tried:

PHP Code:
formatexszQuery999"UPDATE `users` SET `MVP` = 'MVP + 1' WHERE steam_id = '%s';"MVPsteamid);
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery);
formatexszQuery999"UPDATE `users` SET `MLP` = 'MLP + 1' WHERE steam_id = '%s';"MLPsteamid); 
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 
formatexszQuery999"UPDATE `matches` SET `MVP_steamid` = '%s', `MLP_steamid` = '%s' WHERE match_id = '%s';"MVPsteamidMLPsteamidszLine); 
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 
log_amx(szQuery
Same thing...

LOG:

PHP Code:
UPDATE `matchesSET `MVP_steamid` = 'STEAM_0:0:107365441', `MLP_steamid` = 'STEAM_0:0:155654489' WHERE match_id 'fG5A8F46EDJb4c5ec8271a71'
But nothing about `users` ... why?

Last edited by jonatat; 06-15-2018 at 06:34.
jonatat is offline
shauli
Member
Join Date: Jun 2018
Old 06-15-2018 , 07:02   Re: Whats wrong with this SQL query?
Reply With Quote #4

You're only logging the last line. If you want to log all 3 you'll have to use log_amx each time *before* you overwrite it again with formatex, like this:
PHP Code:
formatexszQuery999"UPDATE `users` SET `MVP` = 'MVP + 1' WHERE steam_id = '%s';"MVPsteamid);
log_amx(szQuery

SQL_ThreadQueryg_hTuple"QuerySetData"szQuery);

formatexszQuery999"UPDATE `users` SET `MLP` = 'MLP + 1' WHERE steam_id = '%s';"MLPsteamid); 
log_amx(szQuery

SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 

formatexszQuery999"UPDATE `matches` SET `MVP_steamid` = '%s', `MLP_steamid` = '%s' WHERE match_id = '%s';"MVPsteamidMLPsteamidszLine); 
log_amx(szQuery

SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 
Here's an example for the mistake:
PHP Code:
formatexszQuery999"hello!" ); //szQuery is now 'hello!'
formatexszQuery999"good morning!" ); //szQuery is now 'good morning!'
formatexszQuery999"good night!" ); //szQuery is now 'good night!'
log_amxszQuery ); //'good night!' logged 

Last edited by shauli; 06-15-2018 at 07:03.
shauli is offline
jonatat
Senior Member
Join Date: Dec 2017
Old 06-15-2018 , 07:08   Re: Whats wrong with this SQL query?
Reply With Quote #5

Quote:
Originally Posted by shauli View Post
You're only logging the last line. If you want to log all 3 you'll have to use log_amx each time *before* you overwrite it again with formatex, like this:
PHP Code:
formatexszQuery999"UPDATE `users` SET `MVP` = 'MVP + 1' WHERE steam_id = '%s';"MVPsteamid);
log_amx(szQuery

SQL_ThreadQueryg_hTuple"QuerySetData"szQuery);

formatexszQuery999"UPDATE `users` SET `MLP` = 'MLP + 1' WHERE steam_id = '%s';"MLPsteamid); 
log_amx(szQuery

SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 

formatexszQuery999"UPDATE `matches` SET `MVP_steamid` = '%s', `MLP_steamid` = '%s' WHERE match_id = '%s';"MVPsteamidMLPsteamidszLine); 
log_amx(szQuery

SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 
Here's an example for the mistake:
PHP Code:
formatexszQuery999"hello!" ); //szQuery is now 'hello!'
formatexszQuery999"good morning!" ); //szQuery is now 'good morning!'
formatexszQuery999"good night!" ); //szQuery is now 'good night!'
log_amxszQuery ); //'good night!' logged 
Ok really weird. Not working + 1 syntax, not code. I tried like that:

PHP Code:
formatexszQuery999"UPDATE `users` SET `MVP` = '1' WHERE steam_id = '%s';"MVPsteamid); 
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery);

formatexszQuery999"UPDATE `users` SET `MLP` = '1' WHERE steam_id = '%s';"MLPsteamid); 
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery);

formatexszQuery999"UPDATE `matches` SET `MVP_steamid` = '%s', `MLP_steamid` = '%s' WHERE match_id = '%s';"MVPsteamidMLPsteamidszLine); 
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 
log_amx(szQuery
And works fint, just offcourse not counting +1. So where is mistake with + 1 ? Maybe try something like that? :

PHP Code:
formatexszQuery999"UPDATE `users` SET MLP = MLP + 1 WHERE steam_id = '%s';"MLPsteamid); 
jonatat is offline
shauli
Member
Join Date: Jun 2018
Old 06-15-2018 , 07:25   Re: Whats wrong with this SQL query?
Reply With Quote #6

Quote:
Originally Posted by jonatat View Post
Ok really weird. Not working + 1 syntax, not code. I tried like that:

PHP Code:
formatexszQuery999"UPDATE `users` SET `MVP` = '1' WHERE steam_id = '%s';"MVPsteamid); 
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery);

formatexszQuery999"UPDATE `users` SET `MLP` = '1' WHERE steam_id = '%s';"MLPsteamid); 
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery);

formatexszQuery999"UPDATE `matches` SET `MVP_steamid` = '%s', `MLP_steamid` = '%s' WHERE match_id = '%s';"MVPsteamidMLPsteamidszLine); 
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 
log_amx(szQuery
And works fint, just offcourse not counting +1. So where is mistake with + 1 ? Maybe try something like that? :

PHP Code:
formatexszQuery999"UPDATE `users` SET MLP = MLP + 1 WHERE steam_id = '%s';"MLPsteamid); 
Yep, you wrote SET `MVP` = 'MVP + 1' instead of SET `MVP` = 'MVP' + '1' or SET `MVP` = MVP + 1.
shauli is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-15-2018 , 08:41   Re: Whats wrong with this SQL query?
Reply With Quote #7

You're only logging the last query.

Code:
formatex( szQuery, charsmax(szQuery), "UPDATE `users` SET `MVP` = '1' WHERE steam_id = '%s';", MVPsteamid);  SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery); log_amx(szQuery) formatex( szQuery, charsmax(szQuery), "UPDATE `users` SET `MLP` = '1' WHERE steam_id = '%s';", MLPsteamid);  SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery); log_amx(szQuery) formatex( szQuery, charsmax(szQuery), "UPDATE `matches` SET `MVP_steamid` = '%s', `MLP_steamid` = '%s' WHERE match_id = '%s';", MVPsteamid, MLPsteamid, szLine);  SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery)log_amx(szQuery)
__________________








CrazY. is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:57.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode