SA-MP Forums Archive
Threaded query isn't being called. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Threaded query isn't being called. (/showthread.php?tid=379861)



Threaded query isn't being called. - ReneG - 23.09.2012

When loading some data with threaded queries, the loop won't go past the first iteration.
pawn Код:
public OnOriginQueryFinish(query[], resultid, extraid, connectionHandle)
{
    new rows, fields, content[128], field[20];
    cache_get_data(rows, fields, gConnection);
   
    switch(resultid) {
        case THREAD_LOAD_ORIGINS: {
            printf("Table ORIGINS returned %d rows", rows);
            for(new row=0; row<rows; row++) {
                printf("Loop call %d", row);
                cache_get_field_content(row, "id", field, gConnection);                     OriginInfo[row][oSQLid] = strval(content);
                cache_get_field_content(row, "Name", OriginInfo[row][oName], gConnection);
                cache_get_field_content(row, "X", content, gConnection);                    OriginInfo[row][oPos][0] = floatstr(content);
                cache_get_field_content(row, "Y", content, gConnection);                    OriginInfo[row][oPos][1] = floatstr(content);
                cache_get_field_content(row, "Z", content, gConnection);                    OriginInfo[row][oPos][2] = floatstr(content);
                cache_get_field_content(row, "rotZ", content, gConnection);                 OriginInfo[row][oPos][3] = floatstr(content);
                cache_get_field_content(row, "Interior", content, gConnection);             OriginInfo[row][oInt] = strval(content);
                cache_get_field_content(row, "VW", content, gConnection);                   OriginInfo[row][oVW] = strval(content);
                printf("Test");
               
                for(new f=0; f<4; f++) {
                    printf("Loop call %d for skins.", f);
                    format(field, sizeof(field), "male%d", f+1);
                    cache_get_field_content(row, field, content, gConnection);      OriginInfo[row][oMaleSkins][f] = strval(content);
                    format(field, sizeof(field), "female%d", f+1);
                    cache_get_field_content(row, field, content, gConnection);      OriginInfo[row][oFemaleSkins][f] = strval(content);
                }
               
                printf("ID %d, Name %s, X %f, Y %f, Z %f, RotZ %f, Interior %d, VW %d", OriginInfo[row][oSQLid], OriginInfo[row][oName], OriginInfo[row][oPos][0], OriginInfo[row][oPos][1], OriginInfo[row][oPos][2], OriginInfo[row][oPos][3], OriginInfo[row][oInt], OriginInfo[row][oVW]);
            }
        }
    }  
    return 1;
}
Server printed out
Код:
[13:53:12] Table ORIGINS returned 3 rows
[13:53:12] Loop call 0
[13:53:12] Test
[13:53:12] Loop call 0 for skins.
[13:53:12] Loop call 1 for skins.
[13:53:12] Loop call 2 for skins.
[13:53:12] Loop call 3 for skins.
I have no idea why the loop isn't reaching past the first iteration.


Re: Threaded query isn't being called. - IstuntmanI - 23.09.2012

Add more debugs between "returned %d rows" and "ID %d, Name %s, X %f, Y %f, Z %f, RotZ %f, Interior %d, VW %d" .


Re: Threaded query isn't being called. - ReneG - 23.09.2012

Everything seems fine in the logs, I'll try as an unthreaded query next.

@costel_nistor
Here is what I added
pawn Код:
public OnOriginQueryFinish(query[], resultid, extraid, connectionHandle)
{
    new rows, fields, content[128], field[20];
    cache_get_data(rows, fields, gConnection);
   
    switch(resultid) {
        case THREAD_LOAD_ORIGINS: {
            printf("Table ORIGINS returned %d rows", rows);
            for(new row=0; row<rows; row++) {
                printf("Loop call %d", row);
                cache_get_field_content(row, "id", field, gConnection);                     OriginInfo[row][oSQLid] = strval(content);
                cache_get_field_content(row, "Name", OriginInfo[row][oName], gConnection);
                cache_get_field_content(row, "X", content, gConnection);                    OriginInfo[row][oPos][0] = floatstr(content);
                cache_get_field_content(row, "Y", content, gConnection);                    OriginInfo[row][oPos][1] = floatstr(content);
                cache_get_field_content(row, "Z", content, gConnection);                    OriginInfo[row][oPos][2] = floatstr(content);
                cache_get_field_content(row, "rotZ", content, gConnection);                 OriginInfo[row][oPos][3] = floatstr(content);
                cache_get_field_content(row, "Interior", content, gConnection);             OriginInfo[row][oInt] = strval(content);
                cache_get_field_content(row, "VW", content, gConnection);                   OriginInfo[row][oVW] = strval(content);
                printf("Test");
               
                for(new f=0; f<4; f++) {
                    printf("Loop call %d for skins.", f);
                    format(field, sizeof(field), "male%d", f+1);
                    cache_get_field_content(row, field, content, gConnection);      OriginInfo[row][oMaleSkins][f] = strval(content);
                    format(field, sizeof(field), "female%d", f+1);
                    cache_get_field_content(row, field, content, gConnection);      OriginInfo[row][oFemaleSkins][f] = strval(content);
                }
               
                printf("ID %d, Name %s, X %f, Y %f, Z %f, RotZ %f, Interior %d, VW %d", OriginInfo[row][oSQLid], OriginInfo[row][oName], OriginInfo[row][oPos][0], OriginInfo[row][oPos][1], OriginInfo[row][oPos][2], OriginInfo[row][oPos][3], OriginInfo[row][oInt], OriginInfo[row][oVW]);
            }
        }
    }  
    return 1;
}
Server printed out
Код:
[13:53:12] Table ORIGINS returned 3 rows
[13:53:12] Loop call 0
[13:53:12] Test
[13:53:12] Loop call 0 for skins.
[13:53:12] Loop call 1 for skins.
[13:53:12] Loop call 2 for skins.
[13:53:12] Loop call 3 for skins.
I have no idea why the loop isn't reaching past the first iteration.


Re: Threaded query isn't being called. - ReneG - 27.09.2012




Re: Threaded query isn't being called. - ReneG - 01.10.2012

Bump


Re: Threaded query isn't being called. - Extremo - 01.10.2012

I don't see anything wrong in the code, literally.

Humour me and increase the buffer sizes and try again? (field and content).


Re: Threaded query isn't being called. - ReneG - 01.10.2012

EDIT:

Solved.

The second condition in the loop was supposed to be f<3 not f<4


Re: Threaded query isn't being called. - Extremo - 01.10.2012

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
I've finally narrowed it down to this block of code.
pawn Код:
for(new f=0; f<4; f++) {
    format(field, sizeof(field), "male%d", f+1); printf("%s", field);
    cache_get_field_content(row, field, content, gConnection);      OriginInfo[row][oMaleSkins][f] = strval(content);
    format(field, sizeof(field), "female%d", f+1); printf("%s", field);
    cache_get_field_content(row, field, content, gConnection);      OriginInfo[row][oFemaleSkins][f] = strval(content);
}
Would you have any idea why that is printing out
Код:
[02:39:34] male1
[02:39:34] female1
[02:39:34] male2
[02:39:34] female2
[02:39:34] male3
[02:39:34] female3
[02:39:34] male4
The last line ("male4") is not supposed to be there according to my code.
Well, here's your loop:

pawn Код:
for(new f=0; f<4; f++)
It iterates from 0 to 3 and since you do f+1, the loop will equal:

0 = 1
1 = 2
2 = 3
3 = 4

That's why there is a four.


Re: Threaded query isn't being called. - ReneG - 01.10.2012

I can now sleep tonight, thanks Extremo.


Re: Threaded query isn't being called. - Extremo - 01.10.2012

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
I can now sleep tonight, thanks Extremo.
I still don't grasp what the error was but I am glad I could help?