Getting name from SQL, returns inputtext?!
#1

pawn Код:
stock GetSQLName(playersqlid)
{
    new szQuery[256];
    format(szQuery, sizeof(szQuery), "SELECT `PlayerName` FROM `accounts` WHERE `id` = %d", playersqlid);
    mysql_tquery(dbHandle, szQuery, "SQLName", "");
    return 1;
}
forward SQLName();
public SQLName()
{
    new result[64];
    return cache_get_row(0, 0, result);
}
When I pickup a pickup it returns the command I typed or whatever?
Reply
#2

Can I see how the way you're using it?

pawn Код:
new szQuery[256];
That's way more than your needs though, up to you to reduce it.
Reply
#3

I know, I was testing it.
pawn Код:
OwnedString[x] = format(string, sizeof(string), "~g~Address:~w~ %s ~n~ ~g~Owner:~w~ %s", HouseName[x], GetSQLName(HouseOwner[x]));
Reply
#4

pawn Код:
forward SQLName();
public SQLName()
{
    new result[64];
    cache_get_row(0, 0, result);
        print(result);
        return result;
}
Try to use it in a command or where-ever. What does it print?
Reply
#5

It prints whatever I typed in chat.
Reply
#6

Use old mysql style xd

pawn Код:
stock GetSQLName(playersqlid)
{
    new Cache:result, string[128];
    format(string, sizeof(string), "SELECT `PlayerName` FROM `accounts` WHERE `id` = %d LIMIT 1", playersqlid);
    result = mysql_query(dbHandle, string);

    string = "N/A"; // if id doesnt exist
    if(cache_num_rows())
        cache_get_row(0, 0, string, dbHandle, MAX_PLAYER_NAME);

    cache_delete(result);
    return string;
}
Reply
#7

Facepalm. THANK YOU!
Reply
#8

I believe the whole idea of that stock is wrong. Since public functions can not return arrays, which you are doing in that case. Calling the stock, stock calling the public function which returns an array, which is impossible.

If you go ahead and try to compile these lines:
Код:
forward SQLName();
public SQLName()
{
	new result[64];
        return result;
}
Код:
error 090: public functions may not return arrays (symbol "SQLName")
But somehow that cache_get_row function is hiding the error.

Edit: Seems like you solved it, good luck.
Reply
#9

Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)