Using sscanf with SQLite - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Using sscanf with SQLite (
/showthread.php?tid=276506)
Using sscanf with SQLite -
Scenario - 14.08.2011
Is it possible to load data from SQLite via sscanf? If so, could someone provide an example...?
Re: Using sscanf with SQLite -
[HiC]TheKiller - 14.08.2011
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, "....", .....);
Re: Using sscanf with SQLite -
Grim_ - 14.08.2011
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).
Re: Using sscanf with SQLite -
Scenario - 14.08.2011
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!