MySQL
#9

Quote:
Originally Posted by AndreT
Посмотреть сообщение
I cannot continue before I mention this. Things like this:
pawn Код:
format(szResult, 1100, "%s{FF0000}%d. {33AA33}%s ({FF0000}%d{33AA33})\n", szResult, i + 1, pName, strval(szField));
... are SLOW oh SLOW. Even something like this:
pawn Код:
new temp[128];
format(temp, sizeof(temp), "{FF0000}%d. {33AA33}%s ({FF0000}%d{33AA33})\n", i + 1, pName, strval(szField));
strcat(szResult, temp);
... are FASTER when your strings grow big!

Now please, examine closely what you are doing in your loop there.
pawn Код:
for (new i; i != 10; ++i)
{
    cache_get_data(iRows, iFields); // Get the amount of fields and rows returned by the query IN THE LOOP. WHY!?
    if (iRows) // Check the row count.
    {
        cache_get_row(0, 0, pName); // Extract the name from the FIRST row. In ALL caes, the first row.
        cache_get_row(0, 1, szField); // The same for this line. It would be a bit better if you used i instead of 0.
        if (toStrval)
        {
            format(szResult, 1100, "%s{FF0000}%d. {33AA33}%s ({FF0000}%d{33AA33})\n", szResult, i + 1, pName, strval(szField));
        }
        else
        {
            format(szResult, 1100, "%s{FF0000}%d. {33AA33}%s ({FF0000}%s{33AA33})\n", szResult, i + 1, pName, szField);
        }
        // Please optimize the lines above as I suggeste!
    }
    else
    {
        format(szResult, 1100, "%s{FF0000}%d. {33AA33}Nлra\n", szResult, i + 1);
    }
}
To simplify understanding, I wrote some comments.

Now lets look at what needs to be done.
1. Get the amount of rows returned by the query.
2. Iterate through the rows that the query returned and fill the szResult string accordingly.
3. If we did not get 10 rows from the query, fill the rest of the statistics table with "Account not registered" lines.

To achieve your wanted outcome, the code has to look something like this:
pawn Код:
PUB::GetServerStatistic(playerid, Field[], Command[], bool: toStrval)
{
    new rows, fields;
    cache_get_data(rows, fields);
    for(new i = 0; i != rows; i++)
    {
        cache_get_row(i, 0, pName);
        cache_get_row(i, 1, szField);
        // Formatting code here.
    }

    if(rows != 10)
    {
        // If the query did not return 10 rows, fill in the dialog with empty lines ("There is no registered player")
        for(new i = 0; i != (10 - rows); i++)
        {
            // append "There is no registered player\n"
        }
    }
    return 1;
}
I hope this helps you out a little bit. It does not give you the whole working code, but perhaps an idea on how to solve the logic of the code.
Thank you so much :> And thank you too Pizzy
Reply


Messages In This Thread
MySQL - by AnonymousUser - 29.06.2012, 17:52
Re: MySQL - by Vince - 29.06.2012, 18:25
Re: MySQL - by AnonymousUser - 29.06.2012, 18:38
Re: MySQL - by Vince - 29.06.2012, 19:15
Re: MySQL - by AnonymousUser - 29.06.2012, 21:01
Re: MySQL - by AnonymousUser - 30.06.2012, 20:11
Re: MySQL - by AndreT - 30.06.2012, 20:36
Re: MySQL - by Pizzy - 30.06.2012, 20:43
Re: MySQL - by BaubaS - 30.06.2012, 22:17
Re: MySQL - by AndreT - 30.06.2012, 23:57

Forum Jump:


Users browsing this thread: 1 Guest(s)