Using sscanf with SQLite
#1

Is it possible to load data from SQLite via sscanf? If so, could someone provide an example...?
Reply
#2

You cannot get a whole line at once using a SQLite function but you can make one. I'll give you a example

pawn Код:
#define MAX_RET_STR 500
stock db_get_row(query[])
{
    new DBResult:Result, retstr[MAX_RET_STR], FieldName[50], singleresult[100];
    Result = db_query(query);
    new numfields = db_num_fields(Result);
    for(new a;a<numfields;a++)
    {
        db_field_name(Result, a, FieldName, 50);
        db_get_field_assoc(Result, FieldName, singleresult, 100);
        format(retstr, sizeof(retstr), "%s|%s", retstr, singleresult);
    }
    return retstr[1];
}
pawn Код:
User|Pass|Kills|Deaths|etc..
//Will return
[HiC]TheKiller|MyPass|20|30|etc..
I really don't see why you would want to though.

You could do something like this

pawn Код:
new Line[750];
format(Line, 750, "%s", db_get_row("SELECT * FROM userdata WHERE username = '[HiC]TheKiller'"));
sscanf(Line, "....", .....);
Reply
#3

I don't believe so, as the DBResult variable will always be an integer (in my tests, at least). You can use BUD by Slice however, it allows fetching of multiple variables in one function (something not natively supported).
Reply
#4

Thanks for the responses gentlemen. I guess it would be kind of pointless to have my own function to do this because I'm sure it would slow the process down anyways. I already went ahead and used the "db_get_field_assoc" function to receive each field! Anyways, thanks again!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)