Q: MySQL
#1

Hi, I got a question regarding MySQL, I am pretty new on this.

How can I check if a field is NULL? And how can I read an integer value from a field correctly?

I have something like this in my script

Code:
PlayerData[extraid][pExam] = cache_get_field_int(0, "Exam");

if(!PlayerData[playerid][pExam]) StartExam(playerid);
Although the pExam field value is 1, it still starts the exam.
Reply
#2

In old version, there was macro called ismysqlnull. In R40 and above, there is function cache_is_value_null
Reply
#3

Alright, thank you will look into that.

How about the Exam field issue?
Reply
#4

cache get field content in a new defined variable, then compare the value

Code:
PlayerData[extraid][pExam] = cache_get_field_int(0, "Exam");

if(!PlayerData[playerid][pExam]) >=1)

//REST CODE GOES HERE
 StartExam(playerid);
So, it will only allow 1 or more than 1, not less than that.
Reply
#5

Quote:
Originally Posted by div
View Post
cache get field content in a new defined variable, then compare the value

Code:
if(!PlayerData[playerid][pExam]) >=1)
So, it will only allow 1 or more than 1, not less than that.
That's broken... You've got another bracket in there.

If you check a variable with the ! operator, it's a not, so anything other than 1, being 0, or -1 will return a result.

The if statement the OP had, should at least give some result.



OP, chuck a print statement in there so you know whether it's actually hitting that check and whether it's making it out the other side.
Reply
#6

Quote:
Originally Posted by Uberanwar
View Post
How about the Exam field issue?
Your original code:
Code:
PlayerData[extraid][pExam] = cache_get_field_int(0, "Exam");

if(!PlayerData[playerid][pExam]) StartExam(playerid);
Reply
#7

Print the value for pExam for debug processes.

Tip: Use R40+.
Reply
#8

This is what I do

Quote:

public OnPlayerRequestClass(playerid, classid)
{
if(IsPlayerNPC(playerid)) return 1;

if (!PlayerData[playerid][pAccount] && !PlayerData[playerid][pKicked])
{
/*new
time[3];

gettime(time[0], time[1], time[2]);
SetPlayerTime(playerid, time[0], time[1]);*/

PlayerData[playerid][pAccount] = 1;
TogglePlayerSpectating(playerid, 1);

SetPlayerColor(playerid, DEFAULT_COLOR);
SetTimerEx("AccountCheck", 400, false, "d", playerid); // 400 ms
}
return true;
}

Quote:

forward AccountCheck(playerid);
public AccountCheck(playerid)
{
//SetPlayerPos(playerid, -1988.752075, -72.294998, 38.647026);
//SetPlayerCameraPos(playerid, -1988.752075, -72.294998, 58.647026);
//SetPlayerCameraLookAt(playerid, -2006.489868, -72.107597, 55.977474);

SetCameraData(playerid);
SQL_CheckAccount(playerid);
return true;
}

Quote:

SQL_CheckAccount(playerid)
{
new
query[128];

format(query, sizeof(query), "SELECT `Username` FROM `characters` WHERE `Character` = '%s'", ReturnName(playerid));
mysql_tquery(g_iHandle, query, "OnQueryFinished", "dd", playerid, THREAD_FIND_USERNAME);
}

Quote:

OnQueryFinished
..
case THREAD_FIND_USERNAME:
{
static
query[1000]; // previous: 128

cache_get_row_count(rows);
cache_get_field_count(fields);

if (rows)
{
new
name[MAX_PLAYER_NAME + 1];

cache_get_value_index(0, 0, name);

if (strcmp(name, PlayerData[extraid][pUsername], false) != 0)
{
format(PlayerData[extraid][pUsername], sizeof(name), name);
SetPlayerName(extraid, name);
}
}
format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `Username` = '%s'", PlayerData[extraid][pUsername]);
mysql_tquery(g_iHandle, query, "OnQueryFinished", "dd", extraid, THREAD_CHECK_ACCOUNT);
}

Quote:

case THREAD_CHECK_ACCOUNT:
{
//cache_get_data(rows, fields, g_iHandle);
cache_get_row_count(rows);
cache_get_field_count(fields);

if (rows)
{
static
loginDate[36];

cache_get_value_index(0, 0, loginDate);

format(PlayerData[extraid][pLoginDate], 36, loginDate);

PlayerData[extraid][pExam] = cache_get_field_int(0, "Exam");

cache_get_value_name(0, "SecurityQuestion1", PlayerData[extraid][pSecurityQuestion1], 12;
cache_get_value_name(0, "SecurityAnswer1", PlayerData[extraid][pSecurityAnswer1], 65);

cache_get_value_name(0, "SecurityQuestion2", PlayerData[extraid][pSecurityQuestion2], 12;
cache_get_value_name(0, "SecurityAnswer2", PlayerData[extraid][pSecurityAnswer2], 65);

cache_get_value_name(0, "SecurityQuestion3", PlayerData[extraid][pSecurityQuestion3], 12;
cache_get_value_name(0, "SecurityAnswer3", PlayerData[extraid][pSecurityAnswer3], 65);

Dialog_Show(extraid, LoginScreen, DIALOG_STYLE_PASSWORD, "Account Login", "Welcome back to Asauth RPG!\n\nYour account was last seen on: %s.\n\nPlease enter your password below to login to your account:", "Login", "Cancel", PlayerData[extraid][pLoginDate]);
}
else
{
Dialog_Show(extraid, RegisterScreen, DIALOG_STYLE_PASSWORD, "Account Registration", "Welcome to Asauth RPG, %s.\n\nNotice: Your account is not registered yet. Please enter your desired password:", "Register", "Cancel", ReturnName(extraid));
}
}

In the logs it says no active cache, which could be the factor why the exam system keeps detecting that the player pExam value is 0..
Reply
#9

Does it report any other error/warning in mysql logs? If you compile with debug info, it will report exact line to make it easier for both of us.
Reply
#10

Quote:
Originally Posted by Calisthenics
View Post
Does it report any other error/warning in mysql logs? If you compile with debug info, it will report exact line to make it easier for both of us.
No, only the 'cache_get_value_name: no active cache'.

I did compile with -d3.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)