sscanf + MySQL problem
#1

Hi there, I've a little problem loading some stuff from the MySQL database with sscanf. Here's the enum:

pawn Code:
enum fData
{
    fMySQLID,
    fID,
    fName[50],
    fMOTD[250],
    fLeader[40],
    fType,
    fRank1Name[50],
    fRank2Name[50],
    fRank3Name[50],
    fRank4Name[50],
    fRank5Name[50],
    fRank6Name[50],
    fRank7Name[50],
    fMaterials,
    fDrugs,
    fSafe,
    fHQLock,
    fMembers,
    fSlots,
    Float:fExteriorX,
    Float:fExteriorY,
    Float:fExteriorZ,
    Float:fExteriorF,
    Float:fInteriorX,
    Float:fInteriorY,
    Float:fInteriorZ,
    Float:fInteriorF,
    fInterior,
    fWorld,
};
new FactionData[MAX_FACTIONS][fData];
new Text3D:FactionLabel[MAX_FACTIONS];
And here's the loading function:

pawn Code:
public LoadFactions()
{
    new f = 0;
    mysql_query("SELECT * FROM `rp_factions`");
    mysql_store_result();
    factions = mysql_num_rows();
    for(new idx = 1; idx <= factions; idx++)
    {
        format(query, sizeof(query), "SELECT * FROM `rp_factions` WHERE `faction_id`='%d'", idx);
        mysql_query(query);
        mysql_store_result();
        if(mysql_num_rows())
        {
            while(mysql_fetch_row_format(query, "|"))
            {
                print("step 1 done"); // this appears
                sscanf(query, "p<|>e<dds[50]s[250]s[40]ds[50]s[50]s[50]s[50]s[50]s[50]s[50]ddddddffffffffdd>", FactionData[idx]);
                print("step 2 done"); // this doesn't, so there's some problem above step 2 and below step 1
                f++;
            }
        }
    }
    printf("- Factions: %d", f); // nor does this appear, so everything stops after the sscanf query
    return 1;
}
Here's what appears on the debug.txt too:

Quote:

[21:36:27] ---------------------------

[21:36:27] MySQL Debugging activated (10/06/13)

[21:36:27] ---------------------------

[21:36:27]

[21:36:27] >> mysql_ping( Connection handle: 1 )

[21:36:27] CMySQLHandler::Ping() - Connection is still alive.

[21:36:27] >> mysql_query( Connection handle: 1 )

[21:36:27] CMySQLHandler::Query(SELECT * FROM `rp_factions`) - Successfully executed.

[21:36:27] >> mysql_store_result( Connection handle: 1 )

[21:36:27] CMySQLHandler::StoreResult() - Result was stored.

[21:36:27] >> mysql_num_rows( Connection handle: 1 )

[21:36:27] CMySQLHandler::NumRows() - Returned 1 row(s)

[21:36:27] >> mysql_query( Connection handle: 1 )

[21:36:27] CMySQLHandler::Query(SELECT * FROM `rp_factions` WHERE `faction_id`='1') - Successfully executed.

[21:36:27] >> mysql_store_result( Connection handle: 1 )

[21:36:27] CMySQLHandler::StoreResult() - Result was stored.

[21:36:27] >> mysql_num_rows( Connection handle: 1 )

[21:36:27] CMySQLHandler::NumRows() - Returned 1 row(s)

[21:36:27] >> mysql_fetch_row_format( Connection handle: 1 )

[21:36:27] CMySQLHandler::FetchRow() - Return: 1|1|testname|test|testusername|1|test1|test2|test3 |test4|test5|test6|test7|0|0|0|1|1|20|187.8615|193 1.5109|17.6864|0|187.8615|187.8615|187.8615|187.86 15|0|0

That's all in the debug.txt, nothing else appears. If anyone could help me with this problem, that'd be good.
Reply
#2

Remove this code
pawn Code:
for(new idx = 1; idx <= factions; idx++)
Change the old code with this
pawn Code:
for(new idx; idx < MAX_FACTIONS; idx++)
Make sure you have the MAX_FACTIONS define
pawn Code:
#define MAX_FACTIONS value
Reply
#3

Try this maybe

pawn Code:
public LoadFactions()
{
    new idx = 0, f = 0;
    mysql_query("SELECT * FROM `rp_factions`");
    mysql_store_result();
   
    if(mysql_num_rows())
    {
        while(mysql_fetch_row_format(query, "|"))
        {
            if (idx >= MAX_FACTIONS) break;
            print("step 1 done"); // this appears
            sscanf(query, "p<|>e<dds[50]s[250]s[40]ds[50]s[50]s[50]s[50]s[50]s[50]s[50]ddddddffffffffdd>", FactionData[idx++])
            print("step 2 done"); // this doesn't, so there's some problem above step 2 and below step 1
            f++;
        }
    }
    mysql_free_result();
    printf("- Factions: %d", f); // nor does this appear, so everything stops after the sscanf query
    return 1;
}
Reply
#4

Facepalm, I had defined MAX_FACTIONS as 1, so it wasn't saving any of the variables whatsoever lol.

Thanks anyway pds and emmet, and I've free'd the results now too, forgot about that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)