'%e' - MySQL R7
#1

Am I the only one encountering the problem where the '%e' prefix in format does not work (escapes incorrectly)?
Another question, what's the " | d" at the end of the first line below?
(Escaping using mysql_real_escape_string function and the '%s' works just as fine)

Logs:
Код:
Passing query SELECT `test` FROM `table` WHERE `name` = 'e' LIMIT 0,1 | d
ProcessQueryThread(OnAPublic) - Query was successful. (SELECT `test` FROM `table` WHERE `name` = 'e' LIMIT 0,1)
Code:
pawn Код:
new query[64];
format(query, sizeof(query), "SELECT `test` FROM `table` WHERE `name` = '%e' LIMIT 0,1", GetName(playerid));
mysql_function_query(Handler, query, true, "OnAPublic", "d", playerid);

forward OnAPublic(playerid);
public OnAPublic(playerid)
{
     // ......
     return 1;
}

GePlayerName(playerid)
{
     new name[MAX_PLAYER_NAME]
     GetPlayerName(playerid, name, sizeof(name));
     return name;
}
Reply
#2

Bump.
Reply
#3

The '%e' placeholder ONLY works in mysql_format, not regular format. But I seem to recall that being bugged in R7. Not sure in what revision it was fixed but it ought to be somewhere in R25 or above.
Reply
#4

Alright, I see, thanks!

Another question, how can I check if a username exists? (R7 - returning '1' at the end of the function basically cleaning the cache, so How do I return either true or false without breaking anything?)

pawn Код:
stock CheckUser(playerid, name[MAX_PLAYER_NAME])
{
    new query[124];
    format(query, sizeof(query), "SELECT `name` FROM `table` WHERE `name` = '%s'", name);
    mysql_function_query(1, query, true, "OnUserCheck", "d", playerid);
}

forward OnUserCheck(playerid); // Andre
public OnUserCheck(playerid) // Andre
{
    if(playerid != INVALID_PLAYER_ID)
    {
        new rows, fields;
        cache_get_data(rows, fields);

        if(rows == 1)
        {
            // Account already exists!
        }
        else
        {
            // No account!
        }
    }
    return 1;
}
Reply
#5

Bump.
Reply
#6

This is from my system when the player connects. It's written in SQLite but I'm sure you can change it to MySQL because I'm not really familiar with it's functions.
pawn Код:
new DBResult:dbresult, string[128];
        format(string, sizeof(string), "SELECT NAME FROM `USERS` WHERE `NAME`='%s'", DB_Escape(RPN(playerid)));
        dbresult = db_query(UserDatabase, string);
        if(db_num_rows(dbresult) > 0)
        {
            // something
        }
        else
        {
           // something
        }
        db_free_result(dbresult);
Reply
#7

That's not really help me though... R7 has this build in (clears the chace) unlike the older versions..
I'm not sure how to create this function since in order to clear stuff you have to return 1 at the end..
All I want is a function that returns either true or false whenever checking if a string (user) exists (without breaking anything).
Reply
#8

Quote:
Originally Posted by Loot
Посмотреть сообщение
That's not really help me though... R7 has this build in (clears the chace) unlike the older versions..
I'm not sure how to create this function since in order to clear stuff you have to return 1 at the end..
All I want is a function that returns either true or false whenever checking if a string (user) exists (without breaking anything).
At the first look of your cool it looks confusing because, you can't the name when player connects to the server, your code should look something like this but I am not sure if this is what you want.

Pawn Code
pawn Код:
#include <a_samp>
#include <a_mysql>

new
    SQLConnection ; // variable.

public OnGameModeInit()
{
    return SQLConnection = mysql_connect(  "Host", "Username", "Database", "Password"  );
}

public OnPlayerConnect( playerid )
{
    return CheckUser( playerid );
}


stock CheckUser( playerid )
{
    new
        query [ 128 ], name[ MAX_PLAYER_NAME ];

    GetPlayerName( playerid, name, sizeof( name ) );

    format( query, sizeof( query ), "SELECT `name` FROM `table` WHERE `name` = '%s'", name );
    return mysql_function_query( SQLConnection, query, true, "OnUserCheck", "d", playerid );
}

forward OnUserCheck( playerid ); // Andre
public OnUserCheck( playerid ) // Andre
{
    if( playerid != INVALID_PLAYER_ID )
    {
        new
            rows, fields ;

        cache_get_data( rows, fields, SQLConnection );

        if( rows == 1 )
        {
            // Account already exists!
        }
        else
        {
            // No account!
        }
    }
    return true;
}
Compilation
Код:
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

Header size:            300 bytes
Code size:              692 bytes
Data size:              376 bytes
Stack/heap size:      16384 bytes; estimated max. usage=528 cells (2112 bytes)
Total requirements:   17752 bytes
[Finished in 0.1s]
Reply
#9

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
At the first look of your cool it looks confusing because, you can't the name when player connects to the server, your code should look something like this but I am not sure if this is what you want.

Pawn Code
pawn Код:
#include <a_samp>
#include <a_mysql>

new
    SQLConnection ; // variable.

public OnGameModeInit()
{
    return SQLConnection = mysql_connect(  "Host", "Username", "Database", "Password"  );
}

public OnPlayerConnect( playerid )
{
    return CheckUser( playerid );
}


stock CheckUser( playerid )
{
    new
        query [ 128 ], name[ MAX_PLAYER_NAME ];

    GetPlayerName( playerid, name, sizeof( name ) );

    format( query, sizeof( query ), "SELECT `name` FROM `table` WHERE `name` = '%s'", name );
    return mysql_function_query( SQLConnection, query, true, "OnUserCheck", "d", playerid );
}

forward OnUserCheck( playerid ); // Andre
public OnUserCheck( playerid ) // Andre
{
    if( playerid != INVALID_PLAYER_ID )
    {
        new
            rows, fields ;

        cache_get_data( rows, fields, SQLConnection );

        if( rows == 1 )
        {
            // Account already exists!
        }
        else
        {
            // No account!
        }
    }
    return true;
}
Compilation
Код:
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

Header size:            300 bytes
Code size:              692 bytes
Data size:              376 bytes
Stack/heap size:      16384 bytes; estimated max. usage=528 cells (2112 bytes)
Total requirements:   17752 bytes
[Finished in 0.1s]
I know.
But that doesn't really answer my question..
pawn Код:
public OnUserCheck( playerid ) // Andre
{
    if( playerid != INVALID_PLAYER_ID )
    {
        new
            rows, fields ;

        cache_get_data( rows, fields, SQLConnection );

        if( rows == 1 )
        {
            // Account already exists!
            return 1;
        }
        else
        {
            // No account!
            return 0;
        }
    }
    return true;
}
How do I use this function in checking if a user exists?
- returning 1 at "if rows == 1" will result in 'should return a value', same goes with returning 0 at the else statment.
(as you can see, the function returns true in order to clear the chace and do other stuff, how can I use this function in returning true or false (as well clearning the chace)?
Reply
#10

Bump.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)