Sscanf not splitting string according to Variables
#1

Code:
pawn Код:
for(new i=0;i<5;i++)
    {
        Toys[playerid][i][IsUsed] = 1;
        format(Toys[playerid][i][utoyname],30,"None");
        format(Query,sizeof(Query),"SELECT `Code` FROM `Toys` WHERE `Username` = '%s' AND `Slot` = %d LIMIT 1",PlayerName(playerid),i);
        mysql_query(Query);
        mysql_store_result();
        if(mysql_num_rows())
        {
            mysql_fetch_row(Query);
            sscanf(Query,"p<,>dffffffds",
            Toys[playerid][i][utObjectID],
            Toys[playerid][i][utx],
            Toys[playerid][i][uty],
            Toys[playerid][i][utz],
            Toys[playerid][i][utrx],
            Toys[playerid][i][utry],
            Toys[playerid][i][utrz],
            Toys[playerid][i][utbone],
            Toys[playerid][i][utoyname]);
            Toys[playerid][i][IsUsed] = 1;
           
            //DEBUG
            printf("Slot: %d | Obj: %d | Pos: %f %f %f | Rotation: %f %f %f | Bone: %d | Name: %s",i,Toys[playerid][i][utObjectID],
            Toys[playerid][i][utx],
            Toys[playerid][i][uty],
            Toys[playerid][i][utz],
            Toys[playerid][i][utrx],
            Toys[playerid][i][utry],
            Toys[playerid][i][utrz],
            Toys[playerid][i][utbone],
            Toys[playerid][i][utoyname]);
        }
        mysql_free_result();
    }
Data sent from MySQL.
Код:
[21:16:56] CMySQLHandler::Query(SELECT `Code` FROM `Toys` WHERE `Username` = '[MG]Dimi' AND `Slot` = 0 LIMIT 1) - Successfully executed.
[21:16:56] >> mysql_store_result( Connection handle: 1 )
[21:16:56] CMySQLHandler::StoreResult() - Result was stored.
[21:16:56] >> mysql_num_rows( Connection handle: 1 )
[21:16:56] CMySQLHandler::NumRows() - Returned 1 row(s)
[21:16:56] >> mysql_fetch_row_format( Connection handle: 1 )
[21:16:56] CMySQLHandler::FetchRow() - Return: 18636,0.000,0.000,0.000,0.000,0.000,0.000,2,PoliceCap1
[21:16:56] >> mysql_free_result( Connection handle: 1 )
[21:16:56] CMySQLHandler::FreeResult() - Result was successfully free'd.
[21:16:56] >> mysql_query( Connection handle: 1 )
[21:16:56] CMySQLHandler::Query(SELECT `Code` FROM `Toys` WHERE `Username` = '[MG]Dimi' AND `Slot` = 1 LIMIT 1) - Successfully executed.
[21:16:56] >> mysql_store_result( Connection handle: 1 )
[21:16:56] CMySQLHandler::StoreResult() - Result was stored.
[21:16:56] >> mysql_num_rows( Connection handle: 1 )
[21:16:56] CMySQLHandler::NumRows() - Returned 1 row(s)
[21:16:56] >> mysql_fetch_row_format( Connection handle: 1 )
[21:16:56] CMySQLHandler::FetchRow() - Return: 346,0.000,0.000,0.000,0.000,0.000,0.000,8,9mm
[21:16:56] >> mysql_free_result( Connection handle: 1 )
[21:16:56] CMySQLHandler::FreeResult() - Result was successfully free'd.
[21:16:56] >> mysql_query( Connection handle: 1 )
[21:16:56] CMySQLHandler::Query(SELECT `Code` FROM `Toys` WHERE `Username` = '[MG]Dimi' AND `Slot` = 2 LIMIT 1) - Successfully executed.
[21:16:56] >> mysql_store_result( Connection handle: 1 )
[21:16:56] CMySQLHandler::StoreResult() - Result was stored.
[21:16:56] >> mysql_num_rows( Connection handle: 1 )
[21:16:56] CMySQLHandler::NumRows() - Returned 1 row(s)
[21:16:56] >> mysql_fetch_row_format( Connection handle: 1 )
[21:16:56] CMySQLHandler::FetchRow() - Return: 355,0.000,0.000,0.000,0.000,0.000,0.000,1,AK47
[21:16:56] >> mysql_free_result( Connection handle: 1 )
[21:16:56] CMySQLHandler::FreeResult() - Result was successfully free'd.
[21:16:56] >> mysql_query( Connection handle: 1 )
[21:16:56] CMySQLHandler::Query(SELECT `Code` FROM `Toys` WHERE `Username` = '[MG]Dimi' AND `Slot` = 3 LIMIT 1) - Successfully executed.
[21:16:56] >> mysql_store_result( Connection handle: 1 )
[21:16:56] CMySQLHandler::StoreResult() - Result was stored.
[21:16:56] >> mysql_num_rows( Connection handle: 1 )
[21:16:56] CMySQLHandler::NumRows() - Returned 0 row(s)
[21:16:56] >> mysql_free_result( Connection handle: 1 )
[21:16:56] CMySQLHandler::FreeResult() - Result was successfully free'd.
[21:16:56] >> mysql_query( Connection handle: 1 )
[21:16:56] CMySQLHandler::Query(SELECT `Code` FROM `Toys` WHERE `Username` = '[MG]Dimi' AND `Slot` = 4 LIMIT 1) - Successfully executed.
[21:16:56] >> mysql_store_result( Connection handle: 1 )
[21:16:56] CMySQLHandler::StoreResult() - Result was stored.
[21:16:56] >> mysql_num_rows( Connection handle: 1 )
[21:16:56] CMySQLHandler::NumRows() - Returned 0 row(s)
[21:16:56] >> mysql_free_result( Connection handle: 1 )
[21:16:56] CMySQLHandler::FreeResult() - Result was successfully free'd.
Debug:
Код:
[21:16:56] Slot: 0 | Obj: 0 | Pos: 0.000000 0.000000 0.000000 | Rotation: 0.000000 0.000000 0.000000 | Bone: 0 | Name: None
[21:16:56] Slot: 1 | Obj: 0 | Pos: 0.000000 0.000000 0.000000 | Rotation: 0.000000 0.000000 0.000000 | Bone: 0 | Name: None
[21:16:56] Slot: 2 | Obj: 0 | Pos: 0.000000 0.000000 0.000000 | Rotation: 0.000000 0.000000 0.000000 | Bone: 0 | Name: None
From Log and Debug I can determine sscanf is problem. Any solutions?
Reply
#2

Not 100% sure, don't use MySQL much, but the 'mysql_fetch_row(Query);', would I be right in saying you don't need the 'Query' part?

Just mysql_fetch_row(); and continue with the rest?
Reply
#3

Query is wrong. You're only selecting one field.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
Query is wrong. You're only selecting one field.
That one field is a varchar, storing all the values inside it, and using "," as a delimiter.
Reply
#5

Maybe not my first comment, but it seems that maybe it's not storing to the variable 'Query', if it fetches it correctly, then sscanf might not be liking something, I dunno.
Reply
#6

Quote:
Originally Posted by king_hual
Посмотреть сообщение
That one field is a varchar, storing all the values inside it, and using "," as a delimiter.
Oh? Well that attests a very poor table design.
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
Oh? Well that attests a very poor table design.
Why? Like this I store 8 Values into one and just split later. It's easier for me instead of adding 8 new columns.

@******, what else to print. Only left is to print Query after mysql_fetch_row

EDIT:
Код:
[21:51:33] Query for slot 1: 346,0.000,0.000,0.000,0.000,0.000,0.000,8,9mm
[21:51:33] Slot: 1 | Obj: 0 | Pos: 0.000000 0.000000 0.000000 | Rotation: 0.000000 0.000000 0.000000 | Bone: 0 | Name: None
[21:51:33] Query for slot 2: 355,0.000,0.000,0.000,0.000,0.000,0.000,1,AK47
[21:51:33] Slot: 2 | Obj: 0 | Pos: 0.000000 0.000000 0.000000 | Rotation: 0.000000 0.000000 0.000000 | Bone: 0 | Name: None
mysql_fetch_row() is good. Query (as string that holds result) is what it should be as seen from log above.
Reply
#8

Quote:
Originally Posted by [MG]Dimi
Посмотреть сообщение
Why? Like this I store 8 Values into one and just split later. It's easier for me instead of adding 8 new columns.
Firstly, you're wasting memory. Secondly, the query response is processed more slowly. Thirdly, issues such as the one you are having now occur.
Reply
#9

Printf the Query string before using sscanf and after using sscanf, see what it gives.
Reply
#10

What gives before sscanf is 3 posts above.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)