Raised This Month: $ Target: $400
 0% 

SQL help needed for plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
slurpycof
Senior Member
Join Date: Nov 2004
Old 02-21-2005 , 10:54   SQL help needed for plugin
Reply With Quote #1

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

Last edited by slurpycof; 01-19-2011 at 05:01.
slurpycof is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 02-21-2005 , 16:17  
Reply With Quote #2

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?
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
slurpycof
Senior Member
Join Date: Nov 2004
Old 02-22-2005 , 20:18  
Reply With Quote #3

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

Last edited by slurpycof; 01-19-2011 at 05:01.
slurpycof is offline
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 02-23-2005 , 03:02  
Reply With Quote #4

Be sure to dbi_free_result() on all results > RESULT_NONE.
Johnny got his gun is offline
slurpycof
Senior Member
Join Date: Nov 2004
Old 02-23-2005 , 06:19  
Reply With Quote #5

Will make sure, thanks.
________
Harley-Davidson FXSTB

Last edited by slurpycof; 01-19-2011 at 05:01.
slurpycof is offline
Reply


Thread Tools
Display Modes

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 14:09.


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