Mysql format
#1

I'm having one of those blonde moments, where I've done something stupid but I can't see.

This code doesn't format:
pawn Код:
mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "UPDATE `accounts` SET `name` = '%e', `accent` = '%e', `password` = '%e'", PlayerInformation[playerid][pName], PlayerInformation[playerid][pAccent], PlayerInformation[playerid][pPassword]);
If I printf after that, it prints what mysqlquery was last formatted to.

Any ideas?
Reply
#2

You have no where clause?
Reply
#3

Quote:
Originally Posted by JessThompson
Посмотреть сообщение
You have no where clause?
Nah I don't.
Reply
#4

Is that not what is causing the issue because the statement does not know where to update?
Reply
#5

Quote:
Originally Posted by JessThompson
Посмотреть сообщение
Is that not what is causing the issue because the statement does not know where to update?
Here's the full code.

pawn Код:
forward SavePlayerInformation(playerid);
public SavePlayerInformation(playerid)
{
    new Float:x, Float:y, Float:z, Float:a, Float:health, Float:armour;
    GetPlayerPos(playerid, x, y ,z); GetPlayerFacingAngle(playerid, a);
    PlayerInformation[playerid][pLastX] = x; PlayerInformation[playerid][pLastY] = y; PlayerInformation[playerid][pLastZ] = z; PlayerInformation[playerid][pLastA] = a;
    GetPlayerHealth(playerid, health); GetPlayerArmour(playerid, armour);
    PlayerInformation[playerid][pHealth] = health; PlayerInformation[playerid][pArmour] = armour;
    mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "UPDATE `accounts` SET `name` = '%e', `accent` = '%e', `password` = '%e'", PlayerInformation[playerid][pName], PlayerInformation[playerid][pAccent], PlayerInformation[playerid][pPassword]);
    mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s, `money` = '%d', `bank` = '%d', `health` = '%f', `armour` = '%f'", mysqlquery, PlayerInformation[playerid][pMoney], PlayerInformation[playerid][pBank], PlayerInformation[playerid][pHealth], PlayerInformation[playerid][pArmour]);
    mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s, `lastx` = '%f', `lasty` = '%f', `lastz` = '%f', `lasta` = '%f'", mysqlquery, PlayerInformation[playerid][pLastX], PlayerInformation[playerid][pLastY], PlayerInformation[playerid][pLastZ], PlayerInformation[playerid][pLastA]);
    mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s, `interior` = '%d', `world` = '%d'", mysqlquery, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
   
    mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s WHERE `uniqueid` = '%d'", mysqlquery, PlayerInformation[playerid][pUniqueID]);
    mysql_query(MySQLCon, mysqlquery);
    printf("%s", mysqlquery);
    return 1;
}
The first format doesn't work, the second one does. However it uses the mysqlquery that was last formatted before that.

So for example, if mysqlquery was formatted to "NULL" in a previous code, it will use "NULL" instead of formatting to the first line.
Reply
#6

O i tend to do it like this, because it looks cleaner and ez'er to edit

Код:
	format(query, sizeof(query), "UPDATE `samp_doors` SET `Door_Info` = '%s', `Door_Pos_X` = '%f', `Door_Pos_Y` = '%f', `Door_Pos_Z` = '%f' WHERE `ID` = '%i'", 
	DoorInfo[DoorID][dInfo],
	DoorInfo[DoorID][dEnterX],
	DoorInfo[DoorID][dEnterY],
	DoorInfo[DoorID][dEnterZ],
	DoorInfo[DoorID][dID]);
	mysql_function_query(g_iHandle, query, false, "", "");


	format(query, sizeof(query), "UPDATE `samp_doors` SET `Door_Ext_X` = '%f', `Door_Ext_Y` = '%f', `Door_Ext_Z` = '%f', `Door_Ent_Int` = '%i', `Door_Ext_Int` = '%i' WHERE `ID` = '%i'", 
	DoorInfo[DoorID][dExitX],
	DoorInfo[DoorID][dExitY],
	DoorInfo[DoorID][dExitZ],
	DoorInfo[DoorID][dEnterInterior],
	DoorInfo[DoorID][dExitInterior],
	DoorInfo[DoorID][dID]);
	mysql_function_query(g_iHandle, query, false, "", "");


	format(query, sizeof(query), "UPDATE `samp_doors` SET `Door_VW` = '%i', `Door_Icon` = '%i' WHERE `ID` = '%i'",
	DoorInfo[DoorID][dVirtualWorld],
	DoorInfo[DoorID][dPickupIcon],
	DoorInfo[DoorID][dID]);
	mysql_function_query(g_iHandle, query, false, "", "");
Reply
#7

Quote:
Originally Posted by JessThompson
Посмотреть сообщение
O i tend to do it like this, because it looks cleaner and ez'er to edit

Код:
	format(query, sizeof(query), "UPDATE `samp_doors` SET `Door_Info` = '%s', `Door_Pos_X` = '%f', `Door_Pos_Y` = '%f', `Door_Pos_Z` = '%f' WHERE `ID` = '%i'", 
	DoorInfo[DoorID][dInfo],
	DoorInfo[DoorID][dEnterX],
	DoorInfo[DoorID][dEnterY],
	DoorInfo[DoorID][dEnterZ],
	DoorInfo[DoorID][dID]);
	mysql_function_query(g_iHandle, query, false, "", "");


	format(query, sizeof(query), "UPDATE `samp_doors` SET `Door_Ext_X` = '%f', `Door_Ext_Y` = '%f', `Door_Ext_Z` = '%f', `Door_Ent_Int` = '%i', `Door_Ext_Int` = '%i' WHERE `ID` = '%i'", 
	DoorInfo[DoorID][dExitX],
	DoorInfo[DoorID][dExitY],
	DoorInfo[DoorID][dExitZ],
	DoorInfo[DoorID][dEnterInterior],
	DoorInfo[DoorID][dExitInterior],
	DoorInfo[DoorID][dID]);
	mysql_function_query(g_iHandle, query, false, "", "");


	format(query, sizeof(query), "UPDATE `samp_doors` SET `Door_VW` = '%i', `Door_Icon` = '%i' WHERE `ID` = '%i'",
	DoorInfo[DoorID][dVirtualWorld],
	DoorInfo[DoorID][dPickupIcon],
	DoorInfo[DoorID][dID]);
	mysql_function_query(g_iHandle, query, false, "", "");
Unfortunately I don't think that would make a difference.
Reply
#8

Код:
	mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "UPDATE `accounts` SET `name` = '%e', `accent` = '%e', `password` = '%e'", PlayerInformation[playerid][pName], PlayerInformation[playerid][pAccent], PlayerInformation[playerid][pPassword]);
	mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s, `money` = '%d', `bank` = '%d', `health` = '%f', `armour` = '%f'", mysqlquery, PlayerInformation[playerid][pMoney], PlayerInformation[playerid][pBank], PlayerInformation[playerid][pHealth], PlayerInformation[playerid][pArmour]);
	mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s, `lastx` = '%f', `lasty` = '%f', `lastz` = '%f', `lasta` = '%f'", mysqlquery, PlayerInformation[playerid][pLastX], PlayerInformation[playerid][pLastY], PlayerInformation[playerid][pLastZ], PlayerInformation[playerid][pLastA]);
	mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s, `interior` = '%d', `world` = '%d'", mysqlquery, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
	
	mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s WHERE `uniqueid` = '%d'", mysqlquery, PlayerInformation[playerid][pUniqueID]);
Debug the code using printf after each mysql_format line by showing what is inside mysqlquery string (the query that you are sending) and you will understand.
Reply
#9

Quote:
Originally Posted by Unte99
Посмотреть сообщение
Код:
	mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "UPDATE `accounts` SET `name` = '%e', `accent` = '%e', `password` = '%e'", PlayerInformation[playerid][pName], PlayerInformation[playerid][pAccent], PlayerInformation[playerid][pPassword]);
	mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s, `money` = '%d', `bank` = '%d', `health` = '%f', `armour` = '%f'", mysqlquery, PlayerInformation[playerid][pMoney], PlayerInformation[playerid][pBank], PlayerInformation[playerid][pHealth], PlayerInformation[playerid][pArmour]);
	mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s, `lastx` = '%f', `lasty` = '%f', `lastz` = '%f', `lasta` = '%f'", mysqlquery, PlayerInformation[playerid][pLastX], PlayerInformation[playerid][pLastY], PlayerInformation[playerid][pLastZ], PlayerInformation[playerid][pLastA]);
	mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s, `interior` = '%d', `world` = '%d'", mysqlquery, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
	
	mysql_format(MySQLCon, mysqlquery, sizeof(mysqlquery), "%s WHERE `uniqueid` = '%d'", mysqlquery, PlayerInformation[playerid][pUniqueID]);
Debug the code using printf after each mysql_format line by showing what is inside mysqlquery string (the query that you are sending) and you will understand.
I did. And I got this:
Quote:

[13:26:59] INSERT INTO `accounts` (`name`, `password`) VALUES ('Jack Leslie91', '2F9959B230A44678DD2DC29F037BA1159F233AA9AB183CE3A 0678EAAE002E5AA6F27F47144A1A4365116D3DB1B58EC47896 623B92D85CB2F191705DAF11858B8'), `money` = '250', `bank` = '100', `health` = '100.000000', `armour` = '0.000000', `lastx` = '1679.822388', `lasty` = '1480.007568', `lastz` = '10.763532', `lasta` = '255.419006', `interior` = '0', `world` = '0' WHERE `uniqueid` = '6'

Quote:

INSERT INTO `accounts` (`name`, `password`) VALUES ('Jack Leslie91', '2F9959B230A44678DD2DC29F037BA1159F233AA9AB183CE3A 0678EAAE002E5AA6F27F47144A1A4365116D3DB1B58EC47896 623B92D85CB2F191705DAF11858B8')

Is what it was last formatted too.
I don't understand? Every format code I have after it is the exact same, they format, but just that one doesn't.
Reply
#10

What string size you have for "mysqlquery"?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)