Multiple update
#1

Hello. Usually when people want to save all players or something, they do it like this:

pawn Код:
foreach(new pid : Player) {
    new q[128];
    mysql_format(dbhandle, q, "UPDATE `users` SET wafflez = %d, pancakes = "%e" WHERE id = %d", PInfo[pid][wafflez] + 1, PInfo[pid][pancakes], PInfo[pid][dbID]);
    mysql_function_query(dbhandle, q, false, "", "");
}
Ok, this might work, but damn, that sure is a lot of queries, and as we know: the less queries, the better.

There is nice syntax for multiple updates (in pseudocode form)
Код:
UPDATE `users`
    SET wafflez = CASE id
        WHEN PInfo[1][dbID] THEN PInfo[1][wafflez]
        WHEN PInfo[2][dbID] THEN PInfo[2][wafflez]
        WHEN PInfo[3][dbID] THEN PInfo[3][wafflez]
    END,
    title = CASE id
        WHEN PInfo[1][dbID] THEN "PInfo[1][pancakes]"
        WHEN PInfo[2][dbID] THEN "PInfo[2][pancakes]"
        WHEN PInfo[3][dbID] THEN "PInfo[3][pancakes]"
    END
WHERE id IN (1,2,3)
Is there some snippet/include available for building this kind of query? I will write this, but I don't want to reinvent the wheel
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)