AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Whats wrong with this SQL query? (https://forums.alliedmods.net/showthread.php?t=308298)

jonatat 06-15-2018 05:33

Whats wrong with this SQL query?
 
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...

shauli 06-15-2018 05:57

Re: Whats wrong with this SQL query?
 
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.

jonatat 06-15-2018 06:23

Re: Whats wrong with this SQL query?
 
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?

shauli 06-15-2018 07:02

Re: Whats wrong with this SQL query?
 
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 


jonatat 06-15-2018 07:08

Re: Whats wrong with this SQL query?
 
Quote:

Originally Posted by shauli (Post 2597072)
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); 


shauli 06-15-2018 07:25

Re: Whats wrong with this SQL query?
 
Quote:

Originally Posted by jonatat (Post 2597074)
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.

CrazY. 06-15-2018 08:41

Re: Whats wrong with this SQL query?
 
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)


All times are GMT -4. The time now is 04:40.

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