Recursion Problem with unlimited args
#1

okay im trying to make a function for sqlite that will allow me to update
more than 1 field at a time


so this is the function

pawn Код:
forward UpDateDbTableRow(DB:db, tbl_name[],...);
public UpDateDbTableRow(DB:db, tbl_name[],...)
{
    new
        str_Query[1024],
        str[24],
        a_args[MAX_DB_UPDATE_ARGS][128],
        na=numargs()-1;

    for (new i = 2; i < (na+1) ; ++i)       //start loop threw the arguments
    {
        //credits to Meta for the code to get a string from the argument.
        //https://sampforum.blast.hk/showthread.php?pid=1426694#pid1426694
        for(new _argcount, _temparg[2], _fullarg[256]; ; _argcount++)       //arg count refurs to the string array index
        {
            format(_temparg, sizeof(_temparg), "%c", getarg(i, _argcount)); //get char from string index
           
            if(!strlen(_temparg)) //end of string format full arg and break out of loop
            {
                format(str, sizeof(str), "'%s' ", _fullarg);
                break;
            }
           
            format(_fullarg, sizeof(_fullarg), "%s%s", _fullarg, getarg(i, _argcount));
        }
       
        strcat(a_args[i],str);
    }
   
   
    strcat(str_Query,"UPDATE `");
    strcat(str_Query,tbl_name);
    strcat(str_Query,"` ");
    for(new iargs = 3; iargs<(na+1); )
    {
        strcat(str_Query,"SET `");
        strcat(str_Query,a_args[iargs]);
        strcat(str_Query,"` = '");
        iargs++;
        strcat(str_Query,a_args[iargs]);
        strcat(str_Query,"' ");
        if ((na - iargs)>0)
        {
            strcat(str_Query,", ");
        }
        iargs++;
    }
    //db_query(db,str_Query);
    dprint("\n------------------------------");
    dprint("UpDateDbTableRow TEST 1.2");
    dprint(str_Query);
    dprint("------------------------------\n");
    return 1;
}
its not calling itself so im not sure how i have made a recursion
dprint is just a debug print function i made for when in debug mode.

I know the function wont work like this as there is no where clause
but i can work that out, im just not sure how/why there is a recursion warning.
The function wont print nothing which seams that it fails somewhere in the code above the print statements..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)