PDA

View Full Version : MySql Prob.


newbie scripter
17/04/2014, 02:01 PM
idk why its occuring to me and idk to solve it. Im using BlueG's R7 mysql plugin.
Im sure that line is the one causing Problems.

The Whole Callback

public SavePlayer(playerid)
{
new IP[20];
GetPlayerIp(playerid, IP, 20);
new Query[500];
new QueryFinal[1500] = "UPDATE `playerdata` SET ";
format(Query, sizeof(Query), "`username`='%s',`Deaths`='%d',`ArmstreaksInHand`=' %d', `TimePlayer`='%d', `Rank`='%d', `Achievements`='%d', `HeadShots`='%d', `LongShots`='%d', `IP`='%s', `Kills`='%d',`Cash`='%d', `ArmstreakRecieved`='%d',`PlayerXP`='%d',`PlayerRa nkNumber`='%d' WHERE `Username`='%s'", ReturnPlayerName(playerid),PlayerInfo[playerid][pDeaths],PlayerInfo[playerid][pArmstreak],PlayerInfo[playerid][pTimePlayer],PlayerInfo[playerid][pRank],PlayerInfo[playerid][pAchievements],PlayerInfo[playerid][pHeadShots], PlayerInfo[playerid][pLongShots], IP, PlayerInfo[playerid][pKills],PlayerInfo[playerid][pCash],PlayerInfo[playerid][pArmstreakRecieved],PlayerInfo[playerid][pXP],PlayerInfo[playerid][pRankNumber],ReturnPlayerName(playerid));
strcat(QueryFinal, Query);
mysql_tquery(conn, QueryFinal, false, "OnQuerySend", "");
return 1;
}

That whole line

format(Query, sizeof(Query), "`username`='%s',`Deaths`='%d',`ArmstreaksInHand`=' %d', `TimePlayer`='%d', `Rank`='%d', `Achievements`='%d', `HeadShots`='%d', `LongShots`='%d', `IP`='%s', `Kills`='%d',`Cash`='%d', `ArmstreakRecieved`='%d',`PlayerXP`='%d',`PlayerRa nkNumber`='%d' WHERE `Username`='%s'", ReturnPlayerName(playerid),PlayerInfo[playerid][pDeaths],PlayerInfo[playerid][pArmstreak],PlayerInfo[playerid][pTimePlayer],PlayerInfo[playerid][pRank],PlayerInfo[playerid][pAchievements],PlayerInfo[playerid][pHeadShots], PlayerInfo[playerid][pLongShots], IP, PlayerInfo[playerid][pKills],PlayerInfo[playerid][pCash],PlayerInfo[playerid][pArmstreakRecieved],PlayerInfo[playerid][pXP],PlayerInfo[playerid][pRankNumber],ReturnPlayerName(playerid));



Prob:
DDM.pwn(362) : error 017: undefined symbol "cache_get_data"
DDM.pwn(361) : warning 203: symbol is never used: "field"
DDM.pwn(378) : error 017: undefined symbol "cache_get_data"
DDM.pwn(377) : warning 203: symbol is never used: "field"
DDM.pwn(388) : error 017: undefined symbol "mysql_tquery"
DDM.pwn(397) : error 075: input line too long (after substitutions)
DDM.pwn(398) : error 017: undefined symbol "playeri"
DDM.pwn(399) : error 017: undefined symbol "d"
DDM.pwn(399) : error 029: invalid expression, assumed zero
DDM.pwn(399) : error 029: invalid expression, assumed zero
DDM.pwn(399) : fatal error 107: too many error messages on one line


its just because of that line (it worked before but after i got a new HDD and forgot to save a bkup D: )
Im stuck in this line for some time.

Made a post in "Little Coding Question" but i couldn't get a fix. Hope someone help me with this

Tried R33, R5 and R7 with tquery and mysql_function_query

newbie scripter
18/04/2014, 06:27 AM
Bump

Conradus
18/04/2014, 07:55 AM
Idk if it solves the problem, but I think you need to change "mysql_tquery" to "mysql_query"

iZN
18/04/2014, 08:10 AM
Idk if it solves the problem, but I think you need to change "mysql_tquery" to "mysql_query"

Nice solution.


@OP:

Firstly. mysql_function_query was available till R7 to R21, after that mysql_tquery was introduced but the query is now cache only.

About the 'cache_get_data'. Where it is coming from? Use cache_get_row_count (http://wiki.sa-mp.com/wiki/MySQL/R33#cache_get_row_count) for getting row counts and cache_get_field_count (http://wiki.sa-mp.com/wiki/MySQL/R33#cache_get_field_count) for getting field counts which is better than getting both fields, rows and passing into a variable which is little slow.

Also, just use if it's a update query.

mysql_tquery(conn, QueryFinal);

Also, please look the native before doing silly stuff:

native mysql_tquery(connectionHandle, query[], callback[] = "", format[] = "", {Float,_}:...);

Use, wiki page (http://wiki.sa-mp.com/wiki/MySQL/R33) if you want to know about all the natives.

newbie scripter
18/04/2014, 09:09 AM
I asked another person to script it but he told me to ask in forums about to prob. will try what u say.
What is the one causing Problems?

EDIT:

public CheckAccount(playerid, account[])
{
new rows, field;
cache_get_data(rows, field);
if(rows>=1)
{
ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_PASSWORD, "Welcome back","Welcome back to Contract Wars!\n\nType in your password below to login","Login","Leave");
accountExists[playerid] = true;
}
else
{
ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "New account","Please input your password below to register a account","Register","Leave");
accountExists[playerid] = false;
}
return 1;
}
public CheckAccountEx(account[])
{
new rows, field;
cache_get_data(rows, field);
if(rows >= 1) { QueryState = true; }
else { QueryState = false; }
return QueryState;
}


cache_get_data comes in these two lines.
line 359-382

Edit: If i use cache_get_row_count(), it says error 017: undefined symbol "cache_get_row_count"

iZN
18/04/2014, 11:21 AM
I asked another person to script it but he told me to ask in forums about to prob. will try what u say.
What is the one causing Problems?

EDIT:

public CheckAccount(playerid, account[])
{
new rows, field;
cache_get_data(rows, field);
if(rows>=1)
{
ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_PASSWORD, "Welcome back","Welcome back to Contract Wars!\n\nType in your password below to login","Login","Leave");
accountExists[playerid] = true;
}
else
{
ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "New account","Please input your password below to register a account","Register","Leave");
accountExists[playerid] = false;
}
return 1;
}
public CheckAccountEx(account[])
{
new rows, field;
cache_get_data(rows, field);
if(rows >= 1) { QueryState = true; }
else { QueryState = false; }
return QueryState;
}


cache_get_data comes in these two lines.
line 359-382

Edit: If i use cache_get_row_count(), it says error 017: undefined symbol "cache_get_row_count"


if(rows >= 1) // Nah, no need to do like this.

if(rows) // There are rows found!

if(!rows) // No rows found!

// OR

if(rows)
{
// Found rows
}
else
{
// No rows found
}

// If you really want to use the cache_get_data, just simply.

new rows, field;
cache_get_data(rows, field);
#undef fields
// OR if you're getting fields so
#undef rows

// Little bit simplifying your CheckAccountEx function

public CheckAccountEx(account[])
{
new rows, field;
cache_get_data(rows, field);
#undef field
if(rows)
QueryState = true;
else
QueryState = false;
return (QueryState ? true : false); // IDK, maybe just return QueryState. (Not needed this I guess)
}


Are you REALLY sure that you are using the latest release of BlueG's plugin R38?
https://github.com/pBlueG/SA-MP-MySQL/releases

Eh, you don't need to do this "accountExists[playerid]" variable at all. You can just simply get the rows and save them to the player variables instead of doing that afterwards. Waste of memory.

newbie scripter
21/04/2014, 11:32 AM
public CheckAccount(playerid, account[])
{
new rows, field;
cache_get_data(rows, field); // 362
#undef field // 363
if(rows) // 364
{
ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_PASSWORD, "Welcome back","Welcome back to Contract Wars!\n\nType in your password below to login","Login","Leave");
accountExists[playerid] = true;
}
else
{
ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "New account","Please input your password below to register a account","Register","Leave");
accountExists[playerid] = false;
}
return 1;
}

public CheckAccountEx(account[])
{
new rows, field;
cache_get_data(rows, field);
#undef field
if(rows)
QueryState = true;
else
QueryState = false;
return QueryState;
}


Errors:

DDM.pwn(362) : error 017: undefined symbol "cache_get_data"
DDM.pwn(363) : error 017: undefined symbol "field"
DDM.pwn(363) : error 029: invalid expression, assumed zero
DDM.pwn(363 -- 364) : warning 215: expression has no effect
DDM.pwn(364) : error 001: expected token: ";", but found "if"
DDM.pwn(364) : fatal error 107: too many error messages on one lin


Tried cache_get_row_count instead of cache_get_data but got more errors

RajatPawar
21/04/2014, 11:35 AM
From where are you sending the query for CheckAccount? And AFAIK, there's nothing except a wrong version that could cause an unknown symbol error.

newbie scripter
21/04/2014, 11:39 AM
CheckAccountExist(playerid, account[])
{
if(IsPlayerNPC(playerid)) return 0;
new Query[90];
format(Query, sizeof(Query), "SELECT * FROM `playerdata` WHERE Username='%s'", account);
mysql_tquery(conn, Query, true, "CheckAccount", "is", playerid, account);
return 1;
}

newbie scripter
22/04/2014, 12:34 PM
bump and the place i use CheckAccountExist is

public OnPlayerConnect(playerid)
{
// other things
CheckAccountExist(playerid, ReturnPlayerName(playerid));
// other things
}

and ReturnPlayerName:

ReturnPlayerName(playerid)
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
return pName;
}

newbie scripter
23/04/2014, 12:09 PM
.... Bump, anyone please help me.

newbie scripter
25/04/2014, 02:50 PM
.... Bump, anyone please help me.
Bump

iZN
25/04/2014, 04:50 PM
Please escape strings, or else you will get hunt by SQL Injection (http://en.wikipedia.org/wiki/SQL_injection).

stock CheckAccountExist(playerid)
{
if(IsPlayerNPC(playerid)) return 0;
new Query[90];
mysql_format(conn, Query, sizeof(Query), "SELECT * FROM playerdata WHERE Username = '%e'", ReturnPlayerName(playerid));
mysql_tquery(conn, Query, true, "CheckAccount", "is", playerid, account);
return 1;
}

newbie scripter
26/04/2014, 10:44 AM
didnt fix the errors. i really need some help to fix it, btw thanks for that, i forgot about it.

Onfroi
26/04/2014, 08:08 PM
You probably have 2 or more server folders. Make sure you have the include a_mysql in all of them.

newbie scripter
27/04/2014, 04:43 AM
i've kept my .inc file in pawno/include no where else.
and u all i didnt keep it in includes folder (which is along with server.cfg)

newbie scripter
27/04/2014, 01:36 PM
i found the prob. i typed #define instead of #include but i got this problem now


y_debug.inc(112) : fatal error 100: cannot read from file: "internal\y_version"

newbie scripter
29/04/2014, 01:40 PM
Bump