AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SQL help needed for plugin (https://forums.alliedmods.net/showthread.php?t=10500)

slurpycof 02-21-2005 10:54

SQL help needed for plugin
 
I wrote a map vote plugin that works great on my server using a local MySQL database. People posted that it would create the table for them, but that the results would not get added to the database. I used an external database from a website to test the plugin and I am getting the same results as they are. It creates the database and when the vote is it done, I am getting the "[AMXX] sql_mapvote results added to database" added to the logs, but the data is not added to the database. It is only happening on remote databases. Is there something I can do to make this work?


Code:
public sql_insert() {     if (dbc == SQL_FAILED) return PLUGIN_CONTINUE     new mapname[33]     get_mapname(mapname,32)     new totalint     totalint = floatround(total)     //Insert map information into the tables     result = dbi_query(dbc,"INSERT INTO maprank2 (map_name, good, okay, bad, total) values ('%s',%i,%i,%i,%i) ON DUPLICATE KEY UPDATE map_name=map_name, good=good+%i, okay=okay+%i, bad=bad+%i, total=total+%i",mapname,state[0],state[1],state[2],totalint,state[0],state[1],state[2],totalint)     if (result < RESULT_NONE) {         new err[255]         new errNum = dbi_error(dbc, err, 254)         log_amx("[AMXX] sql_mapvote error: %s|%d", err, errNum)         server_print("[AMXX] sql_mapvote error: %s|%d", err, errNum)         return 1     }else{         log_amx("[AMXX] sql_mapvote results added to database")     }     dbi_free_result(result)     return PLUGIN_CONTINUE  }
________
QR50

XxAvalanchexX 02-21-2005 16:17

Code:
"INSERT INTO maprank2 (map_name, good, okay, bad, total) values ('%s',%i,%i,%i,%i) ...
I believe that you must use apostrophes around every value in this case, whether or not string or integer. Perhaps the creation script could help in finding out why the query might not work?

slurpycof 02-22-2005 20:18

Responding to myself in case someone can needs this info.

I figured this out. It was a problem with pre- 4.1 MySQL databases. You have to use
Code:
    result = dbi_query(dbc,"SELECT * FROM maprank where map_name ='%s'",mapname)     if (dbi_num_rows(result) < 1) {         result = dbi_query(dbc,"INSERT INTO maprank (map_name, good, okay, bad, total) values ('%s',%i,%i,%i,%i)",mapname,state[0],state[1],state[2],totalint)     }else{         result = dbi_query(dbc,"UPDATE maprank SET good=good+%i, okay=okay+%i, bad=bad+%i, total=total+%i WHERE map_name='%s'",state[0],state[1],state[2],totalint,mapname)     }

Instead of
Code:
    result = dbi_query(dbc,"INSERT INTO maprank (map_name, good, okay, bad, total) values ('%s',%i,%i,%i,%i) ON DUPLICATE KEY UPDATE map_name=map_name, good=good+%i, okay=okay+%i, bad=bad+%i, total=total+%i",mapname,state[0],state[1],state[2],totalint,state[0],state[1],state[2],totalint)
________
Suzuki TS125 DUSTER

Johnny got his gun 02-23-2005 03:02

Be sure to dbi_free_result() on all results > RESULT_NONE.

slurpycof 02-23-2005 06:19

Will make sure, thanks. :)
________
Harley-Davidson FXSTB


All times are GMT -4. The time now is 14:09.

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