MySQL save problem (BIG string)
#1

Basically, I have a really big string while saving, the current one is only able to read about... half of it. Is there a better way I can do this without increasing the string size - However I'm sure I wouldn't be able to increase the string so much so it all fit. (From my understanding - Big string = bad - Memory)

pawn Код:
stock savePlayer(playerid)
{
    new
        szQuery[1024];  // Since we're going to save a lot of data, our query size will need to be big.

    PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
    PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
    PlayerInfo[playerid][pINT] = GetPlayerInterior(playerid);
    PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(playerid);
    PlayerInfo[playerid][pWantedLevel] = GetPlayerWantedLevel(playerid);
    new
        Float:x,
        Float:y,
        Float:z
    ;
    GetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
    GetPlayerArmour(playerid,PlayerInfo[playerid][pArmor]);
    GetPlayerPos(playerid,x,y,z);
    PlayerInfo[playerid][pPos_x] = x;
    PlayerInfo[playerid][pPos_y] = y;
    PlayerInfo[playerid][pPos_z] = z;
    GetPlayerPos(playerid,PlayerInfo[playerid][pPos_x],PlayerInfo[playerid][pPos_y],PlayerInfo[playerid][pPos_z]);

    format(szQuery, sizeof(szQuery), "UPDATE players SET Cash = '%d', Deposit = '%d', CreditCard = '%d', PayDay = '%d', PayCheck = '%d', ConnectTime = '%d'", PlayerInfo[playerid][pCash], PlayerInfo[playerid][pDeposit], PlayerInfo[playerid][pCreditCard], PlayerInfo[playerid][pPayDay], PlayerInfo[playerid][pPayCheck], PlayerInfo[playerid][pConnectTime]);
    format(szQuery, sizeof(szQuery), "%s, WRestricted = '%d', Age = '%d', Sex = '%d', Level = '%d', HasCellphone = '%d', Internet = '%d'", szQuery, PlayerInfo[playerid][pWRestricted], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pSex], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pHasCellphone], PlayerInfo[playerid][pInternet]);
    format(szQuery, sizeof(szQuery), "%s, Song1 = '%d', Song2 = '%d', Number = '%d', SpeakerPhone = '%d', PB = '%d' , PhonePrivacy = '%d'", szQuery, PlayerInfo[playerid][pSong][1], PlayerInfo[playerid][pSong][2], PlayerInfo[playerid][pNumber], PlayerInfo[playerid][pSpeakerPhone], PlayerInfo[playerid][pPB], PlayerInfo[playerid][pPhonePrivacy]);
    format(szQuery, sizeof(szQuery), "%s, JobID = '%d', JobID2 = '%d', MechTime = '%d', DetSkill = '%d', DrugsSkill = '%d', SmugSkill = '%d'", szQuery, PlayerInfo[playerid][pJobID], PlayerInfo[playerid][pJobID2], PlayerInfo[playerid][pMechTime], PlayerInfo[playerid][pDetSkill], PlayerInfo[playerid][pDrugsSkill], PlayerInfo[playerid][pSmugSkill]);
    format(szQuery, sizeof(szQuery), "%s, ArmsSkill = '%d', LawSkill = '%d', TruckSkill = '%d', MechSkill = '%d', FishSkill = '%d', TraderPerk = '%d'", szQuery, PlayerInfo[playerid][pArmsSkill], PlayerInfo[playerid][pLawSkill], PlayerInfo[playerid][pTruckSkill], PlayerInfo[playerid][pMechSkill], PlayerInfo[playerid][pFishSkill], PlayerInfo[playerid][pTraderPerk]);
    format(szQuery, sizeof(szQuery), "%s, Skin = '%d', Team = '%d', Accent = '%d', Admin = '%d', Helper = '%d', DutyHours = '%d', AcceptedHelp = '%d'", szQuery, PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pTeam], PlayerInfo[playerid][pAccent], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pHelper], PlayerInfo[playerid][pDutyHours], PlayerInfo[playerid][pAcceptedHelp]);
    format(szQuery, sizeof(szQuery), "%s, Spectate = '%d', Banned = '%d', PermaBanned = '%d', LiveBanned = '%d', Muted = '%d', ReportMuted = '%d'", szQuery, PlayerInfo[playerid][pSpectate], PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pPermaBanned], PlayerInfo[playerid][pLiveBanned], PlayerInfo[playerid][pMuted], PlayerInfo[playerid][pReportMuted]);
    format(szQuery, sizeof(szQuery), "%s, Exp = '%d', VIP = '%d', VMuted = '%d', Jailed = '%d', JailTime = '%d', BeingSentenced = '%d'", szQuery, PlayerInfo[playerid][pExp], PlayerInfo[playerid][pVIP], PlayerInfo[playerid][pVMuted], PlayerInfo[playerid][pJailed], PlayerInfo[playerid][pJailTime], PlayerInfo[playerid][pBeingSentenced]);
    format(szQuery, sizeof(szQuery), "%s, ProbationTime = '%d', PrisonReason = '%s', PrisonedBy = '%s', BannedReason = '%s', BannedBy = '%s'", szQuery, PlayerInfo[playerid][pProbationTime], PlayerInfo[playerid][pPrisonReason], PlayerInfo[playerid][pPrisonedBy], PlayerInfo[playerid][pBannedReason], PlayerInfo[playerid][pBannedBy]);
    format(szQuery, sizeof(szQuery), "%s, ToggedVIPChat = '%d', Warns = '%d', GangWarn = '%d', Pos_x = '%f', Pos_y = '%f', Pos_z = '%f'", szQuery, PlayerInfo[playerid][pToggedVIPChat], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pGangWarn], PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z]);
    format(szQuery, sizeof(szQuery), "%s, Pos_a = '%f', Health = '%f', Armor = '%f', SHealth = '%f', SArmor = '%f', Materials = '%d'", szQuery, PlayerInfo[playerid][pPos_a], PlayerInfo[playerid][pHealth], PlayerInfo[playerid][pArmor], PlayerInfo[playerid][pSHealth], PlayerInfo[playerid][pSArmor], PlayerInfo[playerid][pMaterials]);
    format(szQuery, sizeof(szQuery), "%s, Cocaine = '%d', Fishes = '%d', BiggestFish = '%d', Crates = '%d', INT = '%d', VW = '%d', Dice = '%d'", szQuery, PlayerInfo[playerid][pCocaine], PlayerInfo[playerid][pFishes], PlayerInfo[playerid][pBiggestFish], PlayerInfo[playerid][pCrates], PlayerInfo[playerid][pINT], PlayerInfo[playerid][pVW], PlayerInfo[playerid][pDice]);
    for(new i = 0; i < 11; i++)
    {
        format(szQuery, sizeof(szQuery), "%s, Weapon%d = '%d'", szQuery, i, PlayerInfo[playerid][pWeapon][i]);
        format(szQuery, sizeof(szQuery), "%s, Weapona%d = '%d'", szQuery, i, PlayerInfo[playerid][pWeapona][i]);
    }
    format(szQuery, sizeof(szQuery), "%s, KillLog0 = '%s', KillLog1 = '%s', KillLog2 = '%s', KillLog3 = '%s', KillLog4 = '%s', KillLog5 = '%s'", szQuery, PlayerInfo[playerid][pKillLog0], PlayerInfo[playerid][pKillLog1], PlayerInfo[playerid][pKillLog2], PlayerInfo[playerid][pKillLog3], PlayerInfo[playerid][pKillLog4], PlayerInfo[playerid][pKillLog5]);
    format(szQuery, sizeof(szQuery), "%s, KillLog6 = '%s', KillLog7 = '%s', KillLog8 = '%s', KillLog9 = '%s', Deaths = '%d', Faction = '%d'", szQuery, PlayerInfo[playerid][pKillLog6], PlayerInfo[playerid][pKillLog7], PlayerInfo[playerid][pKillLog8], PlayerInfo[playerid][pKillLog9], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pFaction]);
    format(szQuery, sizeof(szQuery), "%s, GangID = '%d', GangRank = '%d', BeingInvitedToGang = '%d', Rank = '%d', Division = '%d', Leader = '%d'", szQuery, PlayerInfo[playerid][pGangID], PlayerInfo[playerid][pGangRank], PlayerInfo[playerid][pBeingInvitedToGang], PlayerInfo[playerid][pRank], PlayerInfo[playerid][pDivision], PlayerInfo[playerid][pLeader]);
    format(szQuery, sizeof(szQuery), "%s, Married = '%d', MarriedTo = '%s', Duty = '%d', JobDuty = '%d', Crimes = '%d', WantedLevel = '%d'", szQuery, PlayerInfo[playerid][pMarried], PlayerInfo[playerid][pMarriedTo], PlayerInfo[playerid][pDuty], PlayerInfo[playerid][pJobDuty], PlayerInfo[playerid][pCrimes], PlayerInfo[playerid][pWantedLevel]);
    format(szQuery, sizeof(szQuery), "%s, Radio = '%d', RadioFreq = '%d', Wristwatch = '%d', Blindfold = '%d', Rope = '%d', Dashboard = '%d'", szQuery, PlayerInfo[playerid][pRadio], PlayerInfo[playerid][pRadioFreq], PlayerInfo[playerid][pWristwatch], PlayerInfo[playerid][pBlindfold], PlayerInfo[playerid][pRope], PlayerInfo[playerid][pDashboard]);
    format(szQuery, sizeof(szQuery), "%s, Speedo = '%d', Phousekey = '%d', Phousekey2 = '%d', Renting = '%d', RefPoints = '%d', RefPlayer = '%s'", szQuery, PlayerInfo[playerid][pSpeedo], PlayerInfo[playerid][pPhousekey], PlayerInfo[playerid][pPhousekey2], PlayerInfo[playerid][pRenting], PlayerInfo[playerid][pRefPoints], PlayerInfo[playerid][pRefPlayer]);
    format(szQuery, sizeof(szQuery), "%s, HSpawn = '%d', HSpawnX = '%f', HSpawnY = '%f', HSpawnZ = '%f', HSpawnInt = '%d', HSpawnVW = '%d'", szQuery, PlayerInfo[playerid][pHSpawn], PlayerInfo[playerid][pHSpawnX], PlayerInfo[playerid][pHSpawnY], PlayerInfo[playerid][pHSpawnZ], PlayerInfo[playerid][pHSpawnInt], PlayerInfo[playerid][pHSpawnVW]);
    format(szQuery, sizeof(szQuery), "%s, Biz = '%d', VBiz = '%d', RequestingBackup = '%d', AttendingBackupCall = '%d', Bugged = '%d'", szQuery, PlayerInfo[playerid][pBiz], PlayerInfo[playerid][pVBiz], PlayerInfo[playerid][pRequestingBackup], PlayerInfo[playerid][pAttendingBackupCall], PlayerInfo[playerid][pBugged]);
    format(szQuery, sizeof(szQuery), "%s, HeadValue = '%d', ContractBy = '%s', ContractDetail = '%s', C4Used = '%d', C4 = '%d', Bombs = '%d'", szQuery, PlayerInfo[playerid][pHeadValue], PlayerInfo[playerid][pContractBy], PlayerInfo[playerid][pContractDetail], PlayerInfo[playerid][pC4Used], PlayerInfo[playerid][pC4], PlayerInfo[playerid][pBombs]);
    format(szQuery, sizeof(szQuery), "%s, CHits = '%d', FHits = '%d', AcceptReport = '%d', TrashReport = '%d', Spraycan = '%d', Boombox = '%d'", szQuery, PlayerInfo[playerid][pCHits], PlayerInfo[playerid][pFHits], PlayerInfo[playerid][pAcceptReport], PlayerInfo[playerid][pTrashReport], PlayerInfo[playerid][pSpraycan], PlayerInfo[playerid][pBoombox]);
    format(szQuery, sizeof(szQuery), "%s, BoomboxOwned = '%d', BankPIN = '%d', BankPINReset = '%d', Lock = '%d', LockCar = '%d', GasCan = '%d'", szQuery, PlayerInfo[playerid][pBoomboxOwned], PlayerInfo[playerid][pBankPIN], PlayerInfo[playerid][pBankPINReset], PlayerInfo[playerid][pLock], PlayerInfo[playerid][pLockCar], PlayerInfo[playerid][pGasCan]);
    format(szQuery, sizeof(szQuery), "%s, Firstaid = '%d', Sprunk = '%d', Cigar = '%d', Crack = '%d', Pot = '%d', DrugsTime = '%d', LawyerTime = '%d'", szQuery, PlayerInfo[playerid][pFirstaid], PlayerInfo[playerid][pSprunk], PlayerInfo[playerid][pCigar], PlayerInfo[playerid][pCrack], PlayerInfo[playerid][pPot], PlayerInfo[playerid][pDrugsTime], PlayerInfo[playerid][pLawyerTime]);
    format(szQuery, sizeof(szQuery), "%s, WExists = '%d', WX = '%f, WY = '%f', WZ = '%f', WVW = '%d', WInt = '%d', WValue = '%d', WSeeds = '%d'", szQuery, PlayerInfo[playerid][pWExists], PlayerInfo[playerid][pWX], PlayerInfo[playerid][pWY], PlayerInfo[playerid][pWZ], PlayerInfo[playerid][pWVW], PlayerInfo[playerid][pWInt], PlayerInfo[playerid][pWValue], PlayerInfo[playerid][pWSeeds]);
    format(szQuery, sizeof(szQuery), "%s, WObject = '%d', WTimer = '%d', CarLic = '%d', FlyLic = '%d', BoatLic = '%d', WeaponLic = '%d'", szQuery, PlayerInfo[playerid][pWObject], PlayerInfo[playerid][pWTimer], PlayerInfo[playerid][pCarLic], PlayerInfo[playerid][pFlyLic], PlayerInfo[playerid][pBoatLic], PlayerInfo[playerid][pWeaponLic]);
    format(szQuery, sizeof(szQuery), "%s, Tutorial = '%d', TutorialStep = '%d', TutorialStepDelay = '%d', FightStyle = '%d', Insurance = '%d', Hospital = '%d'", szQuery, PlayerInfo[playerid][pTutorial], PlayerInfo[playerid][pTutorialStep], PlayerInfo[playerid][pTutorialStepDelay], PlayerInfo[playerid][pFightStyle], PlayerInfo[playerid][pInsurance], PlayerInfo[playerid][pHospital]);
    format(szQuery, sizeof(szQuery), "%s, NMute = '%d', NMuteTotal = '%d', ADMute = '%d', ADMuteTotal = '%d', Flag = '%s', IP = '%s'", szQuery, PlayerInfo[playerid][pNMute], PlayerInfo[playerid][pNMuteTotal], PlayerInfo[playerid][pADMute], PlayerInfo[playerid][pADMuteTotal], PlayerInfo[playerid][pFlag], PlayerInfo[playerid][pIP]);
    format(szQuery, sizeof(szQuery), "%s, Status = %d WHERE ID = %d", szQuery, PlayerInfo[playerid][pStatus], PlayerInfo[playerid][pDBID]);

    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);

    return 1;
}
Error I get in console:

Quote:

[15:32:33] Error #1064 - Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 1 | Query: UPDATE players SET Cash = '600', Deposit = '3000', CreditCard = '0', PayDay = '0', PayCheck = '0', ConnectTime = '0', WRestricted = '2', Age = '21', Sex = '0', Level = '0', HasCellphone = '0', Internet = '0', Song1 = '0', Song2 = '0', Number = '0', SpeakerPhone = '0', PB = '0' , PhonePrivacy = '0', JobID = '0', JobID2 = '0', MechTime = '0', DetSkill = '0', DrugsSkill = '0', SmugSkill = '0', ArmsSkill = '0', LawSkill = '0', TruckSkill = '0', MechSkill = '0', FishSkill = '0', TraderPerk = '0', Skin = '299', Team = '0', Accent = '0', Admin = '0', Helper = '0', DutyHours = '0', AcceptedHelp = '0', Spectate = '0', Banned = '0', PermaBanned = '0', LiveBanned = '0', Muted = '0', ReportMuted = '0', Exp = '0', VIP = '0', VMuted = '0', Jailed = '0', JailTime = '0', BeingSentenced = '0', ProbationTime = '0', PrisonReason = 'None', PrisonedBy = 'None', BannedReason = 'None', BannedBy = 'None', ToggedVIPChat = '0', Warns = '0', GangWarn = '0', Pos_x = '1668.943237', Pos_y = '-1458.119750', Pos_z = '120.611900', Pos_a = '

Note: I'm new to MySQL; Base Script (Well, MySQL part) = https://sampforum.blast.hk/showthread.php?tid=344978

Another note: string = szQuery - I just refer to it as string.
Reply
#2

HOLY F***
I tgink I am on crack. Did I just see a string the size of 1024 Don't, kid.
Reply
#3

Doesn't help but yeah, the whole point of the thread was to lower and actually save the query.
Reply
#4

You have two options that i can think of.

1): See if you can increase the array size to fit the query (without the stack/heap collision warning)
2): Do several queries.

I'd favor increasing the array size. It wont be too bad on memory because it's a local variable and will be destroyed when it goes out of scope, and it will be faster than several queries.

If you get the stack/heap warning you should do several queries.

EDIT: Also might be better if you sort all that data into separate tables.
Reply
#5

What do you mean by the second option? Re-formatting the query each time with different sections? - I probably wont be able to use the first option due to not all the enum being actually saved right now.
Reply
#6

something like the following example. (i kept the query size low for clarity)
pawn Код:
format(szQuery, sizeof(szQuery), "UPDATE players SET Cash = '%d', Deposit = '%d' WHERE ID='%d'", ...);
mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);

format(szQuery, sizeof(szQuery), "UPDATE players SET WRestricted = '%d', Age = '%d', WHERE ID='%d'", ...);
mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);
Which is why I'd try to increase the array size first, second method isn't very elegant.

Or sort the data into categorized tables.
Reply
#7

Tried the first method, however it resulted in a crash, looks like it couldn't handle the Query size. I guess I'll try out the second method.
Reply
#8

After I split it into several queries, I get some errors:
Quote:

[01:02:30] Error #1064 - Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0.000000', WZ = '0.000000', WVW = '0', WInt = '0', WValue = '0', WSeeds = '0', W' at line 1 | Query: UPDATE players SET WExists = '0', WX = '0.000000, WY = '0.000000', WZ = '0.000000', WVW = '0', WInt = '0', WValue = '0', WSeeds = '0', WObject = '0', WTimer = '0', CarLic = '0', FlyLic = '0', BoatLic = '0', WeaponLic = '0', Tutorial = '0', TutorialStep = '0', TutorialStepDelay = '0', FightStyle = '0', Insurance = '0', Hospital = '1', NMute = '0', NMuteTotal = '0', ADMute = '0', ADMuteTotal = '0', Flag = '', IP = '90.222.221.85', Status = 1 WHERE ID = 0
[01:02:30] Error #1064 - Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Lock = '0', LockCar = '0', GasCan = '0', Firstaid = '0', Sprunk = '0', Cigar = '' at line 1 | Query: UPDATE players SET CHits = '0', FHits = '0', AcceptReport = '0', TrashReport = '0', Spraycan = '0', Boombox = '0', BoomboxOwned = '0', BankPIN = '0', BankPINReset = '0', Lock = '0', LockCar = '0', GasCan = '0', Firstaid = '0', Sprunk = '0', Cigar = '0', Crack = '0', Pot = '0', DrugsTime = '0', LawyerTime = '0' WHERE ID = 0
[01:02:30] (MySQL) Query: UPDATE players SET Speedo = '0', Phousekey = '0', Phousekey2 = '0', Renting = '0', RefPoints = '0', RefPlayer = '', HSpawn = '0', HSpawnX = '0.000000', HSpawnY = '0.000000', HSpawnZ = '0.000000', HSpawnInt = '0', HSpawnVW = '0', Biz = '0', VBiz = '0', RequestingBackup = '0', AttendingBackupCall = '0', Bugged = '0', HeadValue = '0', ContractBy = '', ContractDetail = '', C4Used = '0', C4 = '0', Bombs = '0' WHERE ID = 0 | ResultID: 4
[01:02:30] (MySQL) Query: UPDATE players SET KillLog6 = '', KillLog7 = '', KillLog8 = '', KillLog9 = '', Deaths = '0', Faction = '0', GangID = '0', GangRank = '0', BeingInvitedToGang = '0', Rank = '0', Division = '0', Leader = '0', Married = '0', MarriedTo = '', Duty = '0', JobDuty = '0', Crimes = '0', WantedLevel = '0', Radio = '0', RadioFreq = '0', Wristwatch = '0', Blindfold = '0', Rope = '0', Dashboard = '0' WHERE ID = 0 | ResultID: 4
[01:02:30] Error #1064 - Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT = '0', VW = '0', Dice = '0', Weapon0 = '0', Weapona0 = '0', Weapon1 = '0', W' at line 1 | Query: UPDATE players SET ToggedVIPChat = '0', Warns = '0', GangWarn = '0', Pos_x = '1999.530761', Pos_y = '-1449.328125', Pos_z = '10.559399', Pos_a = '0.000000', Health = '4.000000', Armor = '0.000000', SHealth = '0.000000', SArmor = '0.000000', Materials = '0', Cocaine = '0', Fishes = '0', BiggestFish = '0', Crates = '0', INT = '0', VW = '0', Dice = '0', Weapon0 = '0', Weapona0 = '0', Weapon1 = '0', Weapona1 = '0', Weapon2 = '0', Weapona2 = '0', Weapon3 = '0', Weapona3 = '0', Weapon4 = '0', Weapona4 = '0', Weapon5 = '0', Weapona5 = '0', Weapon6 = '0', Weapona6 = '0', Weapon7 = '0', Weapona7 = '0', Weapon8 = '0', Weapona8 = '0', Weapon9 = '0', Weapona9 = '0', Weapon10 = '0', Weapona10 = '0', KillLog0 = '', KillLog1 = '', KillLog2 = '', KillLog3 = '', KillLog4 = '', KillLog5 = '' WHERE ID = 0
[01:02:30] (MySQL) Query: UPDATE players SET Spectate = '0', Banned = '0', PermaBanned = '0', LiveBanned = '0', Muted = '0', ReportMuted = '0', Exp = '0', VIP = '0', VMuted = '0', Jailed = '0', JailTime = '0', BeingSentenced = '0', ProbationTime = '0', PrisonReason = '', PrisonedBy = '', BannedReason = '', BannedBy = '' WHERE ID = 0 | ResultID: 4
[01:02:30] (MySQL) Query: UPDATE players SET JobID = '0', JobID2 = '0', MechTime = '0', DetSkill = '0', DrugsSkill = '0', SmugSkill = '0', ArmsSkill = '0', LawSkill = '0', TruckSkill = '0', MechSkill = '0', FishSkill = '0', TraderPerk = '0', Skin = '0', Team = '0', Accent = '0', Admin = '0', Helper = '0', DutyHours = '0', AcceptedHelp = '0' WHERE ID = 0 | ResultID: 4
[01:02:30] (MySQL) Query: UPDATE players SET Cash = '0', Deposit = '0', CreditCard = '0', PayDay = '0', PayCheck = '0', ConnectTime = '0', WRestricted = '0', Age = '0', Sex = '0', Level = '0', HasCellphone = '0', Internet = '0', Song1 = '0', Song2 = '0', Number = '0', SpeakerPhone = '0', PB = '0' , PhonePrivacy = '0' WHERE ID = 0 | ResultID: 4

This is the code now:
pawn Код:
stock savePlayer(playerid)
{
    // Let's save the player's information into the mysql database so when they login it can be reset.
    // Before we do anything, we need to grab the most up-to-date information and save it into the player variables.

    new
        szQuery[1024];  // Since we're going to save a lot of data, our query size will need to be big.

    PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
    PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
    PlayerInfo[playerid][pINT] = GetPlayerInterior(playerid);
    PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(playerid);
    PlayerInfo[playerid][pWantedLevel] = GetPlayerWantedLevel(playerid);
    new
        Float:x,
        Float:y,
        Float:z
    ;
    GetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
    GetPlayerArmour(playerid,PlayerInfo[playerid][pArmor]);
    GetPlayerPos(playerid,x,y,z);
    PlayerInfo[playerid][pPos_x] = x;
    PlayerInfo[playerid][pPos_y] = y;
    PlayerInfo[playerid][pPos_z] = z;
    GetPlayerPos(playerid,PlayerInfo[playerid][pPos_x],PlayerInfo[playerid][pPos_y],PlayerInfo[playerid][pPos_z]);

    // We will now take the nformation we grabbed and input it to make a query.
    // Remember the database ID? This is one instance of where it will be useful to use.
    format(szQuery, sizeof(szQuery), "UPDATE players SET Cash = '%d', Deposit = '%d', CreditCard = '%d', PayDay = '%d', PayCheck = '%d', ConnectTime = '%d'", PlayerInfo[playerid][pCash], PlayerInfo[playerid][pDeposit], PlayerInfo[playerid][pCreditCard], PlayerInfo[playerid][pPayDay], PlayerInfo[playerid][pPayCheck], PlayerInfo[playerid][pConnectTime]);
    format(szQuery, sizeof(szQuery), "%s, WRestricted = '%d', Age = '%d', Sex = '%d', Level = '%d', HasCellphone = '%d', Internet = '%d'", szQuery, PlayerInfo[playerid][pWRestricted], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pSex], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pHasCellphone], PlayerInfo[playerid][pInternet]);
    format(szQuery, sizeof(szQuery), "%s, Song1 = '%d', Song2 = '%d', Number = '%d', SpeakerPhone = '%d', PB = '%d' , PhonePrivacy = '%d' WHERE ID = %d", szQuery, PlayerInfo[playerid][pSong][1], PlayerInfo[playerid][pSong][2], PlayerInfo[playerid][pNumber], PlayerInfo[playerid][pSpeakerPhone], PlayerInfo[playerid][pPB], PlayerInfo[playerid][pPhonePrivacy], PlayerInfo[playerid][pDBID]);
    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);
   
    format(szQuery, sizeof(szQuery), "UPDATE players SET JobID = '%d', JobID2 = '%d', MechTime = '%d', DetSkill = '%d', DrugsSkill = '%d', SmugSkill = '%d'", PlayerInfo[playerid][pJobID], PlayerInfo[playerid][pJobID2], PlayerInfo[playerid][pMechTime], PlayerInfo[playerid][pDetSkill], PlayerInfo[playerid][pDrugsSkill], PlayerInfo[playerid][pSmugSkill]);
    format(szQuery, sizeof(szQuery), "%s, ArmsSkill = '%d', LawSkill = '%d', TruckSkill = '%d', MechSkill = '%d', FishSkill = '%d', TraderPerk = '%d'", szQuery, PlayerInfo[playerid][pArmsSkill], PlayerInfo[playerid][pLawSkill], PlayerInfo[playerid][pTruckSkill], PlayerInfo[playerid][pMechSkill], PlayerInfo[playerid][pFishSkill], PlayerInfo[playerid][pTraderPerk]);
    format(szQuery, sizeof(szQuery), "%s, Skin = '%d', Team = '%d', Accent = '%d', Admin = '%d', Helper = '%d', DutyHours = '%d', AcceptedHelp = '%d' WHERE ID = %d", szQuery, PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pTeam], PlayerInfo[playerid][pAccent], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pHelper], PlayerInfo[playerid][pDutyHours], PlayerInfo[playerid][pAcceptedHelp], PlayerInfo[playerid][pDBID]);
    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);
   
    format(szQuery, sizeof(szQuery), "UPDATE players SET Spectate = '%d', Banned = '%d', PermaBanned = '%d', LiveBanned = '%d', Muted = '%d', ReportMuted = '%d'", PlayerInfo[playerid][pSpectate], PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pPermaBanned], PlayerInfo[playerid][pLiveBanned], PlayerInfo[playerid][pMuted], PlayerInfo[playerid][pReportMuted]);
    format(szQuery, sizeof(szQuery), "%s, Exp = '%d', VIP = '%d', VMuted = '%d', Jailed = '%d', JailTime = '%d', BeingSentenced = '%d'", szQuery, PlayerInfo[playerid][pExp], PlayerInfo[playerid][pVIP], PlayerInfo[playerid][pVMuted], PlayerInfo[playerid][pJailed], PlayerInfo[playerid][pJailTime], PlayerInfo[playerid][pBeingSentenced]);
    format(szQuery, sizeof(szQuery), "%s, ProbationTime = '%d', PrisonReason = '%s', PrisonedBy = '%s', BannedReason = '%s', BannedBy = '%s' WHERE ID = %d", szQuery, PlayerInfo[playerid][pProbationTime], PlayerInfo[playerid][pPrisonReason], PlayerInfo[playerid][pPrisonedBy], PlayerInfo[playerid][pBannedReason], PlayerInfo[playerid][pBannedBy], PlayerInfo[playerid][pDBID]);
    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);
   
    format(szQuery, sizeof(szQuery), "UPDATE players SET ToggedVIPChat = '%d', Warns = '%d', GangWarn = '%d', Pos_x = '%f', Pos_y = '%f', Pos_z = '%f'", PlayerInfo[playerid][pToggedVIPChat], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pGangWarn], PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z]);
    format(szQuery, sizeof(szQuery), "%s, Pos_a = '%f', Health = '%f', Armor = '%f', SHealth = '%f', SArmor = '%f', Materials = '%d'", szQuery, PlayerInfo[playerid][pPos_a], PlayerInfo[playerid][pHealth], PlayerInfo[playerid][pArmor], PlayerInfo[playerid][pSHealth], PlayerInfo[playerid][pSArmor], PlayerInfo[playerid][pMaterials]);
    format(szQuery, sizeof(szQuery), "%s, Cocaine = '%d', Fishes = '%d', BiggestFish = '%d', Crates = '%d', INT = '%d', VW = '%d', Dice = '%d'", szQuery, PlayerInfo[playerid][pCocaine], PlayerInfo[playerid][pFishes], PlayerInfo[playerid][pBiggestFish], PlayerInfo[playerid][pCrates], PlayerInfo[playerid][pINT], PlayerInfo[playerid][pVW], PlayerInfo[playerid][pDice]);
    for(new i = 0; i < 11; i++)
    {
        format(szQuery, sizeof(szQuery), "%s, Weapon%d = '%d'", szQuery, i, PlayerInfo[playerid][pWeapon][i]);
        format(szQuery, sizeof(szQuery), "%s, Weapona%d = '%d'", szQuery, i, PlayerInfo[playerid][pWeapona][i]);
    }
    format(szQuery, sizeof(szQuery), "%s, KillLog0 = '%s', KillLog1 = '%s', KillLog2 = '%s', KillLog3 = '%s', KillLog4 = '%s', KillLog5 = '%s' WHERE ID = %d", szQuery, PlayerInfo[playerid][pKillLog0], PlayerInfo[playerid][pKillLog1], PlayerInfo[playerid][pKillLog2], PlayerInfo[playerid][pKillLog3], PlayerInfo[playerid][pKillLog4], PlayerInfo[playerid][pKillLog5], PlayerInfo[playerid][pDBID]);
    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);
   
    format(szQuery, sizeof(szQuery), "UPDATE players SET KillLog6 = '%s', KillLog7 = '%s', KillLog8 = '%s', KillLog9 = '%s', Deaths = '%d', Faction = '%d'", PlayerInfo[playerid][pKillLog6], PlayerInfo[playerid][pKillLog7], PlayerInfo[playerid][pKillLog8], PlayerInfo[playerid][pKillLog9], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pFaction]);
    format(szQuery, sizeof(szQuery), "%s, GangID = '%d', GangRank = '%d', BeingInvitedToGang = '%d', Rank = '%d', Division = '%d', Leader = '%d'", szQuery, PlayerInfo[playerid][pGangID], PlayerInfo[playerid][pGangRank], PlayerInfo[playerid][pBeingInvitedToGang], PlayerInfo[playerid][pRank], PlayerInfo[playerid][pDivision], PlayerInfo[playerid][pLeader]);
    format(szQuery, sizeof(szQuery), "%s, Married = '%d', MarriedTo = '%s', Duty = '%d', JobDuty = '%d', Crimes = '%d', WantedLevel = '%d'", szQuery, PlayerInfo[playerid][pMarried], PlayerInfo[playerid][pMarriedTo], PlayerInfo[playerid][pDuty], PlayerInfo[playerid][pJobDuty], PlayerInfo[playerid][pCrimes], PlayerInfo[playerid][pWantedLevel]);
    format(szQuery, sizeof(szQuery), "%s, Radio = '%d', RadioFreq = '%d', Wristwatch = '%d', Blindfold = '%d', Rope = '%d', Dashboard = '%d' WHERE ID = %d", szQuery, PlayerInfo[playerid][pRadio], PlayerInfo[playerid][pRadioFreq], PlayerInfo[playerid][pWristwatch], PlayerInfo[playerid][pBlindfold], PlayerInfo[playerid][pRope], PlayerInfo[playerid][pDashboard], PlayerInfo[playerid][pDBID]);
    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);
   
    format(szQuery, sizeof(szQuery), "UPDATE players SET Speedo = '%d', Phousekey = '%d', Phousekey2 = '%d', Renting = '%d', RefPoints = '%d', RefPlayer = '%s'", PlayerInfo[playerid][pSpeedo], PlayerInfo[playerid][pPhousekey], PlayerInfo[playerid][pPhousekey2], PlayerInfo[playerid][pRenting], PlayerInfo[playerid][pRefPoints], PlayerInfo[playerid][pRefPlayer]);
    format(szQuery, sizeof(szQuery), "%s, HSpawn = '%d', HSpawnX = '%f', HSpawnY = '%f', HSpawnZ = '%f', HSpawnInt = '%d', HSpawnVW = '%d'", szQuery, PlayerInfo[playerid][pHSpawn], PlayerInfo[playerid][pHSpawnX], PlayerInfo[playerid][pHSpawnY], PlayerInfo[playerid][pHSpawnZ], PlayerInfo[playerid][pHSpawnInt], PlayerInfo[playerid][pHSpawnVW]);
    format(szQuery, sizeof(szQuery), "%s, Biz = '%d', VBiz = '%d', RequestingBackup = '%d', AttendingBackupCall = '%d', Bugged = '%d'", szQuery, PlayerInfo[playerid][pBiz], PlayerInfo[playerid][pVBiz], PlayerInfo[playerid][pRequestingBackup], PlayerInfo[playerid][pAttendingBackupCall], PlayerInfo[playerid][pBugged]);
    format(szQuery, sizeof(szQuery), "%s, HeadValue = '%d', ContractBy = '%s', ContractDetail = '%s', C4Used = '%d', C4 = '%d', Bombs = '%d' WHERE ID = %d", szQuery, PlayerInfo[playerid][pHeadValue], PlayerInfo[playerid][pContractBy], PlayerInfo[playerid][pContractDetail], PlayerInfo[playerid][pC4Used], PlayerInfo[playerid][pC4], PlayerInfo[playerid][pBombs], PlayerInfo[playerid][pDBID]);
    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);
   
    format(szQuery, sizeof(szQuery), "UPDATE players SET CHits = '%d', FHits = '%d', AcceptReport = '%d', TrashReport = '%d', Spraycan = '%d', Boombox = '%d'", PlayerInfo[playerid][pCHits], PlayerInfo[playerid][pFHits], PlayerInfo[playerid][pAcceptReport], PlayerInfo[playerid][pTrashReport], PlayerInfo[playerid][pSpraycan], PlayerInfo[playerid][pBoombox]);
    format(szQuery, sizeof(szQuery), "%s, BoomboxOwned = '%d', BankPIN = '%d', BankPINReset = '%d', Lock = '%d', LockCar = '%d', GasCan = '%d'", szQuery, PlayerInfo[playerid][pBoomboxOwned], PlayerInfo[playerid][pBankPIN], PlayerInfo[playerid][pBankPINReset], PlayerInfo[playerid][pLock], PlayerInfo[playerid][pLockCar], PlayerInfo[playerid][pGasCan]);
    format(szQuery, sizeof(szQuery), "%s, Firstaid = '%d', Sprunk = '%d', Cigar = '%d', Crack = '%d', Pot = '%d', DrugsTime = '%d', LawyerTime = '%d' WHERE ID = %d", szQuery, PlayerInfo[playerid][pFirstaid], PlayerInfo[playerid][pSprunk], PlayerInfo[playerid][pCigar], PlayerInfo[playerid][pCrack], PlayerInfo[playerid][pPot], PlayerInfo[playerid][pDrugsTime], PlayerInfo[playerid][pLawyerTime], PlayerInfo[playerid][pDBID]);
    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);
   
    format(szQuery, sizeof(szQuery), "UPDATE players SET WExists = '%d', WX = '%f, WY = '%f', WZ = '%f', WVW = '%d', WInt = '%d', WValue = '%d', WSeeds = '%d'", PlayerInfo[playerid][pWExists], PlayerInfo[playerid][pWX], PlayerInfo[playerid][pWY], PlayerInfo[playerid][pWZ], PlayerInfo[playerid][pWVW], PlayerInfo[playerid][pWInt], PlayerInfo[playerid][pWValue], PlayerInfo[playerid][pWSeeds]);
    format(szQuery, sizeof(szQuery), "%s, WObject = '%d', WTimer = '%d', CarLic = '%d', FlyLic = '%d', BoatLic = '%d', WeaponLic = '%d'", szQuery, PlayerInfo[playerid][pWObject], PlayerInfo[playerid][pWTimer], PlayerInfo[playerid][pCarLic], PlayerInfo[playerid][pFlyLic], PlayerInfo[playerid][pBoatLic], PlayerInfo[playerid][pWeaponLic]);
    format(szQuery, sizeof(szQuery), "%s, Tutorial = '%d', TutorialStep = '%d', TutorialStepDelay = '%d', FightStyle = '%d', Insurance = '%d', Hospital = '%d'", szQuery, PlayerInfo[playerid][pTutorial], PlayerInfo[playerid][pTutorialStep], PlayerInfo[playerid][pTutorialStepDelay], PlayerInfo[playerid][pFightStyle], PlayerInfo[playerid][pInsurance], PlayerInfo[playerid][pHospital]);
    format(szQuery, sizeof(szQuery), "%s, NMute = '%d', NMuteTotal = '%d', ADMute = '%d', ADMuteTotal = '%d', Flag = '%s', IP = '%s'", szQuery, PlayerInfo[playerid][pNMute], PlayerInfo[playerid][pNMuteTotal], PlayerInfo[playerid][pADMute], PlayerInfo[playerid][pADMuteTotal], PlayerInfo[playerid][pFlag], PlayerInfo[playerid][pIP]);
    format(szQuery, sizeof(szQuery), "%s, Status = %d WHERE ID = %d", szQuery, PlayerInfo[playerid][pStatus], PlayerInfo[playerid][pDBID]);

    mysql_query(szQuery, THREAD_NO_RESULT, playerid, iConnectionHandle);

    return 1;
}
Reply
#9

Hello. You need to learn to read the error messages.

#1: "Error #1064....near '0.000000', WZ = '0.000000'" It's telling you where the problem is in your query.
If you look below this, you can see at the point it mentioned: "WX = '0.000000, WY = '0.000000', WZ = '0.000000'"
Notice how you are missing a ' after the value for "WX".

I am seeing if I can find the problem with your other queries, but in both other error messages it tells you where the problem may be.
Reply
#10

Okay, there's only one error left now (The second one was query not long enough) -
Quote:

[01:56:23] Error #1064 - Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Lock = '0', LockCar = '0', GasCan = '0', Firstaid = '0', Sprunk = '0', Cigar = '' at line 1 | Query: UPDATE players SET CHits = '0', FHits = '0', AcceptReport = '0', TrashReport = '0', Spraycan = '0', Boombox = '0', BoomboxOwned = '0', BankPIN = '0', BankPINReset = '0', Lock = '0', LockCar = '0', GasCan = '0', Firstaid = '0', Sprunk = '0', Cigar = '0', Crack = '0', Pot = '0', DrugsTime = '0', LawyerTime = '0' WHERE ID = 0

It's hard to go though code after you've been writing hours of it :/ ...
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)