Raised This Month: $32 Target: $400
 8% 

Solved [MySQL]Value different than in Database


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nerus
Senior Member
Join Date: Aug 2010
Location: Poland
Old 02-24-2019 , 04:48   [MySQL]Value different than in Database
Reply With Quote #1

SOLVED: Array auth was too short for SteamID64 correct length is 21

Hi guys I have problem with taken value from DB after query - all the time I've getting value equals to 0, but executing same query on DB I'll get correct value.

DB Vip table:
Code:
VipId|SteamId|Expired|ServerId
PHP Code:
static Handle database null;

public 
void OnPluginStart()
{
    
InitDB();
}

public 
void InitDB()
{
    
SQL_TConnect(SQLConnecting"Vips");
}

public 
void SQLConnecting(Handle ownerHandle hndl, const char[] errorany data)
{    
    if(
owner == null || owner == INVALID_HANDLE)
        
ThrowError("Can't connect to the database, error occurred:\n%s"error);

    
database hndl;
}

public 
void OnClientPostAdminCheck(int client)
{
    if(!
IsValidPlayer(clienttrue))
        return;

    
char auth[17];
    if(
GetClientAuthId(clientAuthId_SteamID64auth17true))
    {
        
char query[256];
        
//Format(query, 256, "SELECT IsVip('%s');", auth);
        
Format(query256"SELECT COUNT(VipId) FROM Vips WHERE SteamId = '%s' AND Expired >= NOW() LIMIT 1;"auth);
        
SQL_TQuery(databaseCheckPlayerVipqueryclient);
    }
        
}

stock void CheckPlayerVip(Handle ownerHandle result, const char[] errorany client)
{
    if (
result != null && SQL_FetchRow(result))
    {
        
int value SQL_FetchInt(result0);
        
bool isVip view_as<bool>(value);

        
PrintToServer("Player %N isVip %d"clientvvalue);

        if(
isVip)
            
AddUserFlags(clientAdmin_Reservation);
    
        
delete result;
    }
    else
        
PrintToServer("Error occurred: '%s'"error);


Last edited by Nerus; 02-24-2019 at 07:35. Reason: Array auth was too short for SteamID64 correct length is 21
Nerus is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 02-24-2019 , 05:07   Re: [MySQL]Value different than in Database
Reply With Quote #2

PHP Code:
Format(query256"SELECT SteamId FROM Vips WHERE SteamId = '%s' AND Expired >= NOW();"auth); 
SteamId should be a primary key. Then in callback function you check if steamid is not null.
Use the new syntax btw.

PHP Code:
static Handle database null
static with global variables?

PHP Code:
SQL_TQuery(databaseCheckPlayerVipqueryclient); 
Send the userid of the clients. The client can disconnect before the callback.
__________________

Last edited by Ilusion9; 02-24-2019 at 05:08.
Ilusion9 is offline
Nerus
Senior Member
Join Date: Aug 2010
Location: Poland
Old 02-24-2019 , 05:34   Re: [MySQL]Value different than in Database
Reply With Quote #3

Quote:
Originally Posted by Ilusion9 View Post
PHP Code:
Format(query256"SELECT SteamId FROM Vips WHERE SteamId = '%s' AND Expired >= NOW();"auth); 
SteamId should be a primary key. Then in callback function you check if steamid is not null.
Use the new syntax btw.
Problem is I have ServerId field in this table, so I need other index than SteamId, we can have couple clients that can be in relation with Servers (many to many).
First post edited please look at table.

Last edited by Nerus; 02-24-2019 at 05:39.
Nerus is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 10:49.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode