Jump to content
raptor2x

[SOLVED] A small problem with SQL

Recommended Posts

Hello,
Ok so my problem is easy to understand and I think that it is also easy to resolve.
To explain that quickly, here is my code :

_userUID = getPlayerUID player;
_alreadyAnswered = [format ["getAnswerAuthor:%1", _userUID], 2] call extDB_Database_async;
systemChat format ["%1", _alreadyAnswered];

if(_alreadyAnswered == what can I write here ?) then
{
	blablabla
}
else
{
	blablabla
};

And here is the SQL code referring to "getAnswerAuthor" :

[getAnswerAuthor]
SQL1_1 = SELECT COUNT(*) FROM sondages WHERE UID = ?;

Prepared Statement Cache = false
Number of Inputs = 1
SQL1_INPUTS = 1

So the SQL query just checks if there is the UID of the player in the "sondages" table, then it returns 1 or 0 in alreadyAnswered.

It's actually working well, when I check what's the result with systemChat format ["%1", _alreadyAnswered]; , it says in the chat [0] or [1].

 

But the problem is that I want to do something with this [1] or that [0], as you can see at the line 5.

I don't know how I can do that because it's not a simple true/false or a 1/0, there are the "[]" next to the number.

 

So basically how can I do that if(_alreadyAnswered == [1]) ?

 

Thanks !

Share this post


Link to post
Share on other sites

You can do this:

_trueOrFalse = _alreadyAnswered select 0;if(_trueOrFalse isEqualTo 1) then{        // UID is in DB} else {        // UID is not in DB};
OR

You can change your query to return 'true' or 'false' then you do:

_trueOrFalse = _alreadyAnswered select 0;if (_trueOrFalse) then{        // UID is in DB} else {        // UID is not in DB};
OR

You can use (with both of the method below):

switch (_alreadyAnswered select 0) do 
{
    case 0/false: {}; // UID not in DB
    case 1/true: {}; // UID in DB
};
OR

You can alter your async function to filter things out and remove unwanted array when not needed (in you case).

I use extDB and opted for the last one. I use this query to check if player exists:

SQL1_1 = SELECT CASE WHEN EXISTS (SELECT PID, SID FROM PLAYERS WHERE PID=? AND SID=?) THEN 'true' ELSE 'false' END;
And in my async func I just get rid of the array which then returns just true or false.
  • Like 1

Share this post


Link to post
Share on other sites

Thank you so much for your help hoverguy !

Now it works perfectly. :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×