SA-MP Forums Archive
MySQL problem. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: MySQL problem. (/showthread.php?tid=203863)



MySQL problem. - Tomejus - 28.12.2010

Hello everyone,

So I have a problem with string loading with MySQL. Then I set my variable to string everything is ok. MySQL inserts it to table and everything looks nice. But when I need to load that string MySQL loads for me only one word, not all sentence but only one word.

On top I put variable to enum, so it looks like:
Код:
<..>
enum Item
{
        <...>
	priezastis[ 128 ], // variable.
        <...>
}
new playerDB[ MAX_PLAYERS ][ Item ];
Load Script:
Код:
forward LoadPlayer(playerid);
public LoadPlayer(playerid)
{
	new fetch[ 256 ], tmpa;
	format(query, 256, "SELECT * FROM `"TABLENAME"` WHERE id = '%i'", pInfo[playerid][pId]);
	mysql_query(query);
	mysql_store_result();
	mysql_retrieve_row();

       <...>

	mysql_fetch_field_row(fetch,"Priezastis"); // Reason
	sscanf(fetch, "s", tmpa);
	sscanf(fetch, "s[128]", playerDB[playerid][priezastis]); // variable.
       
        <...>

	mysql_free_result();
}



Re: MySQL problem. - armyoftwo - 28.12.2010

why do you sscanf it?
Код:
	mysql_fetch_field_row(fetch,"Priezastis"); // Reason
        format(playerDB[playerid][priezastis], 128, "%s", fetch);
Try this


or better
pawn Код:
mysql_fetch_field_row(playerDB[playerid][priezastis],"Priezastis");



Re: MySQL problem. - Tomejus - 28.12.2010

Wow! it seems to work. Thank you !!!


Re: MySQL problem. - Tomejus - 28.12.2010

One more question about loading... I'm has edited this loading system, so I suppose t remove sscanf, but how?

Код:
forward LoadPlayer(playerid);
public LoadPlayer(playerid)
{
	new fetch[ 256 ], tmpa;
	format(query, 256, "SELECT * FROM `"TABLENAME"` WHERE id = '%i'", pInfo[playerid][pId]);
	mysql_query(query);
	mysql_store_result();
	mysql_retrieve_row();

	mysql_fetch_field_row(fetch,"Lygis");
	new tmplygis;
	sscanf(fetch, "i", tmplygis);
	SetPlayerScore(playerid, tmplygis);
	mysql_fetch_field_row(fetch,"Wanted");
	new tmpwanted;
	sscanf(fetch, "i", tmpwanted);
	SetPlayerWantedLevel(playerid, tmpwanted);
	mysql_fetch_field_row(fetch,"Pinigai");
	ResetPlayerMoney(playerid);
	new tmpmoney;
	sscanf(fetch, "i", tmpmoney);
	GivePlayerMoney(playerid, tmpmoney);
	mysql_fetch_field_row(fetch,"World");
	new tmpworld;
	sscanf(fetch, "i", tmpworld);
	SetPlayerVirtualWorld(playerid, tmpworld);
	mysql_fetch_field_row(fetch,"Skin");
	new tmpskin;
	sscanf(fetch, "i", tmpskin);
	SetPlayerSkin(playerid, tmpskin);
	mysql_fetch_field_row(fetch,"Admin");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", pInfo[playerid][admin]);
	mysql_fetch_field_row(fetch,"Bankas");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][bankas]);
	mysql_fetch_field_row(fetch,"Uniforma");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][uniforma]);
	mysql_fetch_field_row(fetch,"Uzdarbis");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][uzdarbis]);
	mysql_fetch_field_row(fetch,"VIPL");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][vipl]);
	mysql_fetch_field_row(fetch,"Kalejimas");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][klaikas]);
	mysql_fetch_field_row(fetch,"Exp");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", pInfo[playerid][exp]);
	mysql_fetch_field_row(fetch,"VIP");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][vip]);
	mysql_fetch_field_row(fetch,"Telefonas");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][tel]);
	mysql_fetch_field_row(fetch,"THealth");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][telhealth]);
	mysql_fetch_field_row(fetch,"Saskaita");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][saskaita]);
	mysql_fetch_field_row(fetch,"Tinklas");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][tinklas]);
	mysql_fetch_field_row(fetch,"Papildymas");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][papildymas]);
	mysql_fetch_field_row(playerDB[playerid][priezastis],"Priezastis");
	mysql_fetch_field_row(playerDB[playerid][dpriezastis],"dPriezastis");
	mysql_fetch_field_row(fetch,"Spec");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][spec]);
	mysql_fetch_field_row(fetch,"Ispejimai");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][ispejimai]);
	mysql_fetch_field_row(fetch,"dIspejimai");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][dispejimai]);
	mysql_fetch_field_row(fetch,"Direktorius");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][direktorius]);
	mysql_fetch_field_row(fetch,"Prangas");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][rangas]);
	mysql_fetch_field_row(fetch,"Uzraktai");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", MaxVehicles[playerid]);
	mysql_fetch_field_row(fetch,"Ziebtuvelis");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][ziebtuvelis]);
	mysql_fetch_field_row(fetch,"Cigaretes");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][cigaretes]);
	mysql_fetch_field_row(fetch,"Namai");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", MaxHouses[playerid]);
	mysql_fetch_field_row(fetch,"Surakintas");
	sscanf(fetch, "i", tmpa);
	sscanf(fetch, "i", playerDB[playerid][surakintas]);
	mysql_fetch_field_row(fetch,"Teises");
	new tmpteises;
	sscanf(fetch, "i", tmpteises);
	sscanf(fetch, "i", playerDB[playerid][teises]);
	mysql_fetch_field_row(fetch,"MTeises");
	new tmpmteises;
	sscanf(fetch, "i", tmpmteises);
	sscanf(fetch, "i", playerDB[playerid][mteises]);
	mysql_fetch_field_row(fetch,"GPS");
	new tmpgps;
	sscanf(fetch, "i", tmpgps);
	if (tmpgps) playerDB[playerid][gps] = true;
	mysql_fetch_field_row(fetch,"Bankok");
	new tmpbankok;
	sscanf(fetch, "i", tmpbankok);
	if (tmpbankok) playerDB[playerid][bankok] = true;
	mysql_fetch_field_row(fetch,"Uniformed");
	new tmpuniformed;
	sscanf(fetch, "i", tmpuniformed);
	if (tmpuniformed) playerDB[playerid][uniformed] = true;
	mysql_fetch_field_row(fetch,"Pakrovejas");
	new tmppakrovejas;
	sscanf(fetch, "i", tmppakrovejas);
	if (tmppakrovejas) playerDB[playerid][pakrovejas] = true;
	mysql_fetch_field_row(fetch,"Apakrovejas");
	new tmpapakrovejas;
	sscanf(fetch, "i", tmpapakrovejas);
	if (tmpapakrovejas) playerDB[playerid][apakrovejas] = true;
	mysql_fetch_field_row(fetch,"MTeorija");
	new tmpmteorija;
	sscanf(fetch, "i", tmpmteorija);
	if (tmpmteorija) playerDB[playerid][mteorija] = true;
	mysql_fetch_field_row(fetch,"MMTeorija");
	new tmpmmteorija;
	sscanf(fetch, "i", tmpmmteorija);
	if (tmpmmteorija) playerDB[playerid][mmteorija] = true;
	mysql_free_result();
}
How I have to load veriables correctly?


Re: MySQL problem. - _rAped - 30.12.2010

Quote:
Originally Posted by Tomejus
Посмотреть сообщение
up!! anyone?
You can just remove sscanf if that's what you want, but I suggest you to replace it with strval and floastr in case it's a float or integr.


Re: MySQL problem. - Tomejus - 30.12.2010

Thanks for you answer. But how can I do it? I didin't know how : / it's really hard to me, it would be easier if I had example. By the way can this script or saving in my case improve ram usage ? because my gamemode uses alot of ram memory and I think its MySQL job. Anyway if u can give me example. Thank you!


Re: MySQL problem. - _rAped - 30.12.2010

Quote:
Originally Posted by Tomejus
Посмотреть сообщение
Thanks for you answer. But how can I do it? I didin't know how : / it's really hard to me, it would be easier if I had example. By the way can this script or saving in my case improve ram usage ? because my gamemode uses alot of ram memory and I think its MySQL job. Anyway if u can give me example. Thank you!
I'm not sure what plugin you are using but something like this should work just fine:
pawn Код:
new tmplygis;
    mysql_fetch_field_row(fetch,"Lygis"); tmplygis = strval(fetch);
    SetPlayerScore(playerid, tmplygis);



Re: MySQL problem. - Tomejus - 02.01.2011

Thank you. That works fine for me.