SSCANF multiple optionals.. Not processing.. Why? -
TheStreetsRP - 25.05.2013
Here is my SQL result:
Код:
[Sat May 25 13:51:14 2013] Function: mysql_fetch_row executed with result: "2,Bandage,1,0,0,0,0,0,64,0,1,100,Bandage,100,NULL,NULL,NULL,NULL".
Here is the PAWN code:
Код:
#define MAX_ITEMS 200
enum itmEnum { entID, entName[32], itemID, relID, wepID, wepLvl, fxID, fxLvl, itemAmount, bagID, safeID, quality, itemName[32], maxStack, wepName[32], gameID, wepBaseDmg, fxName[32] };
new ItemStats[MAX_ITEMS][itmEnum];
public OnGameModeInit()
{
mysql_query("SELECT itement.entID, itement.entName, itement.itemID, itement.relID, itement.wepID, itement.wepLvl, itement.fxID, itement.fxLvl, itement.amount, itement.charID, itement.safeID, itement.quality, itemtmp.itemName, itemtmp.itemMaxStack, weptmp.wepName, weptmp.gameID, weptmp.wepBaseDmg, wepfx.fxName FROM itement LEFT JOIN itemtmp ON itement.itemID = itemtmp.itemID LEFT JOIN weptmp ON itement.wepID = weptmp.wepID LEFT JOIN wepfx ON itement.fxID = wepfx.fxID WHERE safeid != 0");
mysql_store_result();
i=1;
while(mysql_fetch_row(data, ",")) {
if(sscanf(data, "p<,>is[32]iiiiiiiiiiS(test)[32]I(0)S(test)[32]I(0)I(0)S(test)[32]", ItemStats[i][entID], ItemStats[i][entName], ItemStats[i][itemID], ItemStats[i][relID], ItemStats[i][wepID], ItemStats[i][wepLvl], ItemStats[i][fxID], ItemStats[i][fxLvl], ItemStats[i][itemAmount], ItemStats[i][bagID], ItemStats[i][safeID], ItemStats[i][quality], ItemStats[i][itemName], ItemStats[i][maxStack], ItemStats[i][wepName], ItemStats[i][gameID], ItemStats[i][wepBaseDmg], ItemStats[i][fxName]))
return print("ERROR: Item sscanf executed without all fields.");
i++;
}
mysql_free_result();
}
The problem, as I hope described in title, is that server continuously prints "Item sscanf executed without all fields." I'm sure there's just some stupid thing I've done, but I'm really scratching my head on this one.
PS - This is obviously not my full OnGameModeInit(), just making sure I don't get any lazy answers.
Re: SSCANF multiple optionals.. Not processing.. Why? -
TheStreetsRP - 26.05.2013
I actually read about it yesterday (the "e" specifier) as I was scouring your documentation and have since started making the switch, however I thought I read it wasn't compatible with multi-dimensional arrays. I'll review the documentation and if I'm wrong, so many headaches have been relieved.
. Thanks for this, I didn't realize that the SQL result "NULL" was actually being read by PAWN as a string. Stupid mistake, definitely should have thought of it myself!
Thanks so much ******.
Re: SSCANF multiple optionals.. Not processing.. Why? -
TheStreetsRP - 26.05.2013
Just for anybody searching for this in the future pertaining to MySQL queries with left joins that may result in NULL results (by design) look into the MySQL query function COALESCE (usage: COALESCE(columnName, 0))
Here is my new query
Код:
mysql_query("SELECT itement.*, itemtmp.itemName, COALESCE(itemtmp.itemMaxStack, 0), weptmp.wepName, COALESCE(weptmp.gameID, 0), COALESCE(weptmp.wepBaseDmg, 0), wepfx.fxName FROM itement LEFT JOIN itemtmp ON itement.itemID = itemtmp.itemID LEFT JOIN weptmp ON itement.wepID = weptmp.wepID LEFT JOIN wepfx ON itement.fxID = wepfx.fxID WHERE safeID != '0'");
Here is the result:
Код:
[Sun May 26 13:59:38 2013] Function: mysql_fetch_row executed with result: "2|Bandage|1|0|0|0|0|0|64|0|1|100|Bandage|100|NULL|0|0|NULL".
COALESCE returns a "0" if the result is NULL. This solved my issues entirely.