SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 25/06/2018, 08:58 PM   #1
Uberanwar
Gangsta
 
Uberanwar's Avatar
 
Join Date: May 2012
Location: Malaysia
Posts: 893
Reputation: 63
Default Q: MySQL

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.
Uberanwar is offline   Reply With Quote
Old 25/06/2018, 09:32 PM   #2
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,227
Reputation: 205
Default Re: Q: MySQL

In old version, there was macro called ismysqlnull. In R40 and above, there is function cache_is_value_null
Calisthenics is offline   Reply With Quote
Old 25/06/2018, 11:25 PM   #3
Uberanwar
Gangsta
 
Uberanwar's Avatar
 
Join Date: May 2012
Location: Malaysia
Posts: 893
Reputation: 63
Default Re: Q: MySQL

Alright, thank you will look into that.

How about the Exam field issue?
Uberanwar is offline   Reply With Quote
Old 26/06/2018, 03:05 AM   #4
div
Huge Clucker
 
Join Date: Dec 2017
Location: Rajasthan ka chorra :P
Posts: 216
Reputation: 18
Default Re: Q: MySQL

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.
div is offline   Reply With Quote
Old 26/06/2018, 05:18 AM   #5
Sew_Sumi
Banned
 
Join Date: Jun 2008
Location: Azerbaijan
Posts: 6,243
Reputation: 525
Default Re: Q: MySQL

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.
Sew_Sumi is offline   Reply With Quote
Old 26/06/2018, 07:04 AM   #6
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,227
Reputation: 205
Default Re: Q: MySQL

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);
Calisthenics is offline   Reply With Quote
Old 26/06/2018, 08:19 AM   #7
GTLS
High-roller
 
GTLS's Avatar
 
Join Date: Aug 2014
Location: India
Posts: 1,072
Reputation: 119
Default Re: Q: MySQL

Print the value for pExam for debug processes.

Tip: Use R40+.
__________________

I don't help for rep. I help cuz I was helped in the past.


Retired from SAMP Scene. Might open SAMP Forums once in a while.

Some treats for ya. Click em
Basic House System
Simple Speedo
Base Login/Register Script

GTLS is offline   Reply With Quote
Old 06/07/2018, 06:58 AM   #8
Uberanwar
Gangsta
 
Uberanwar's Avatar
 
Join Date: May 2012
Location: Malaysia
Posts: 893
Reputation: 63
Default Re: Q: MySQL

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..
Uberanwar is offline   Reply With Quote
Old 06/07/2018, 07:10 AM   #9
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,227
Reputation: 205
Default Re: Q: MySQL

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.
Calisthenics is offline   Reply With Quote
Old 06/07/2018, 07:29 AM   #10
Uberanwar
Gangsta
 
Uberanwar's Avatar
 
Join Date: May 2012
Location: Malaysia
Posts: 893
Reputation: 63
Default Re: Q: MySQL

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.

Last edited by Uberanwar; 09/03/2019 at 04:53 AM.
Uberanwar is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Plugin r39-2 Error: Can't connect to local MySQL server through socket Emre__ Scripting Help 10 30/07/2014 08:26 AM
[Tutorial] [VIDEO] MySQL ORM r38: How to pair GM with MySQL & creation of registration/connection system cArnasLT Tutorials 3 19/05/2014 02:08 PM
BlueG MySQL plugin - Failed (plugins/mysql.so: undefined symbol: _Z13stringvprintfPKcPc) linuxthefish Plugin Development 10 13/07/2013 10:56 AM
[Tool/Web/Other] MySQL DB Manager - Easily manage your MySQL databases with this remote application fiki574 Tools and Files 13 22/07/2012 09:41 AM


All times are GMT. The time now is 08:07 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.