AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SQL] Datadropped & Help Optimizing (https://forums.alliedmods.net/showthread.php?t=62618)

mikes3ds 10-31-2007 15:42

[SQL] Datadropped & Help Optimizing
 
[SQL] Data Dropped & Help Optimizing
The SMALL & SQL code working;however,

Every so often data is lost, do not know how. The code is set up to update every one in the server to the SQL database on map change, and to each client once they are authorized [steamid].

I need help to figure why sometimes data is being lost when I update/load to the SQL Database. It has around 16,000 Steamids in it.

Any fix or way to optimize the way the code does that does the SQL hookup, I would be very thankful.

[Note] I have searched, for any information on this topic, if any one has a link to help please do so.

Thank you for your time.
-Mikes3ds

Code bellow
Code:
  //SQL SAVING SYSTEM 3.0.0 #define PLUGIN "UPCMOD" #define VER "3.0.0" #define AUTHOR "Mikes3ds" //Header #include <amxmodx> #include <amxmisc> #include <dbi> //Arrays new Sql:dbc   new Result:result   new g_ConnectTime[33] new g_TotalKills[33] new g_TotalDeaths[33] new g_newplayer[33] public plugin_init() {     register_plugin(PLUGIN, VER, AUTHOR)     set_task(0.1,"sql_init")     register_clcmd("save_test", "save_info") //To test and debug     register_clcmd("load_test", "load_info") //To test and debug } public sql_init() {         new error[256]         dbc = dbi_connect("IP", "USERNAME", "PSW", "DATABASE",error,255) //DBC:SQL                 if (dbc == SQL_FAILED)         log_amx("[UPC MOD] SQL Connection Failed = %s", error)         else         {             dbi_query(dbc,"CREATE TABLE IF NOT EXISTS `upcmod` (`lastname` VARCHAR(32) NOT NULL,`steamid` VARCHAR(32) NOT NULL,`connecttime` INT NOT NULL,`totalkills` INT NOT NULL,`totaldeaths` INT NOT NULL,`date` TIMESTAMP, PRIMARY KEY(`steamid`))")             log_amx("[UPC MOD] SQL Connection Connected")         } } public client_authorized(id) //User STEAMID Authorized, load there data/info {     load_info(id)     return PLUGIN_CONTINUE } public client_disconnect(id)  //User Disconnected, So save {     save_info(id)     return PLUGIN_CONTINUE } public load_info(id)  //Loading SQL database data {     if ( is_user_bot(id) )  //Do not save     {           return PLUGIN_CONTINUE     }     if (is_user_hltv(id) )  //Do not save     {         return PLUGIN_CONTINUE     }             new authid[32]      get_user_authid(id,authid,31)         result = dbi_query(dbc,"SELECT * FROM `credits` WHERE steamid = '%s'",authid) //Tries to find person         if (result == RESULT_FAILED)     {         log_amx("[UPC MOD] MySQL Query failed")         return PLUGIN_CONTINUE     }     else if (result == RESULT_NONE)     {         g_newplayer[id] = 1 //Stores that user is not in DATABASE         g_ConnectTime[id] = 5         g_TotalKills[id] = 0         g_TotalDeaths[id] = 0     }     else     {         dbi_nextrow(result)         g_ConnectTime[id] = dbi_result(result,"connecttime")         g_TotalKills[id] = dbi_result(result, "totalkills")         g_TotalDeaths[id]= dbi_result(result, "totaldeaths")         //log_amx("[UPC MOD] Loaded user %s",authid)     }     dbi_free_result(result)         return PLUGIN_CONTINUE } public save_info(id){  //Saving data to SQL database         if ( is_user_bot(id) ) //Do not save     {           return PLUGIN_CONTINUE     }     if (is_user_hltv(id) ) //Do not save     {         return PLUGIN_CONTINUE     }     //log_amx("[UPC MOD] Trying to save")         new authid[32], player_name[33], playtime         playtime =  (get_user_time(id) + g_ConnectTime[id]) //Total Connect time         get_user_authid(id,authid,31) //Get user steamid     get_user_name(id,player_name,31) //Get user name         if (g_newplayer[id] == 1) { //If user not in database, add  them                     result = dbi_query(dbc,"INSERT INTO `upcmod` (lastname, steamid, connecttime, totalkills, totaldeaths, date) values ('%s','%s',%i,%i,%i,NOW())",player_name,authid,playtime,g_TotalKills[id],g_TotalDeaths[id])             //log_amx("[UPC MOD] Added a new user %s steamid %s playtime %i",player_name,authid,playtime)     }     else{               //Update user if in database             result = dbi_query(dbc,"UPDATE `upcmod` SET lastname='%s', connecttime=%i, totalkills=%i, totaldeaths=%i, date=NOW() WHERE steamid='%s'",player_name,playtime, g_TotalKills[id],g_TotalDeaths[id],authid)             //log_amx("[UPC MOD] Saved for user %s steamid %s playtime %i",player_name,authid,playtime)     }     if (result == RESULT_FAILED)     { //         log_amx("[UPC MOD] MySQL Save failed for user %s steamid %s playtime %i",player_name,authid,playtime)         return PLUGIN_CONTINUE     }     dbi_free_result(result)         return PLUGIN_CONTINUE }

mikes3ds 11-01-2007 15:22

Re: [SQL] Datadropped & Help Optimizing
 
Okays if I code it using SQLX, do you think that will help.....

I really do not know what is happening....so I guess I may try coding it for SQLX....

I am not that advanced in datatbase systems...so if any one has any advise on what is the best way to save the data please tell....


All times are GMT -4. The time now is 01:22.

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