Querying in an existing cache; Daisy-chaining queries.
#1

Is it a good practice to query once more when i'm on a callback from where I was sent into by the main query? I just made this right now to show my point,
pawn Code:
public SampleCallback()
{
    mysql_format(mysql, query, sizeof(query), "SELECT blabla FROM blabla LIMIT 1");
    mysql_tquery(mysql, query, "AnotherCallback");
        return 1;
}

public AnotherCallback()
{
    cache_get_data(0, 0, SomeVar, mysql, sizeof(SomeVar));//grab the result set here
    mysql_format(mysql, query, sizeof(query), "SELECT somethingelse FROM sometable");
    mysql_tquery(mysql, query, "OnceMore", "i", SomeVar);
    return 1;
}

public OnceMore(SomeVar)
{
    cache_get_data(0, 0, SomeVar2);
    SomeGlobalVar = SomeVar + SomeVar2;
    return 1;
}
Note that the above was just a sample code.
Reply
#2

If it works and you need it to get data in a certain order, I don't see why you shouldn't be able to use it.

One example this could be useful:
- first loading all vehicle-data (maximum fuel per vehicle-model, fuel consumption per vehicle-model, ...)
- then loading all static vehicles that are created at certain locations (for missions for example)

You need to load the maximum fuel for every vehicle-model first, then load the vehicles themselves (model, spawn coordinates, ...).
Otherwise every created vehicle could end up with an empty fuel tank, unless your code loops over the unoccupied vehicles and refuels them anyway.

Just make sure you're not creating infinite loops with this (like your OnceMore callback executing a query that calls AnotherCallback or even OnceMore again).
Reply
#3

Quote:
Originally Posted by PowerPC603
View Post
If it works and you need it to get data in a certain order, I don't see why you shouldn't be able to use it.

One example this could be useful:
- first loading all vehicle-data (maximum fuel per vehicle-model, fuel consumption per vehicle-model, ...)
- then loading all static vehicles that are created at certain locations (for missions for example)

You need to load the maximum fuel for every vehicle-model first, then load the vehicles themselves (model, spawn coordinates, ...).
Otherwise every created vehicle could end up with an empty fuel tank, unless your code loops over the unoccupied vehicles and refuels them anyway.

Just make sure you're not creating infinite loops with this (like your OnceMore callback executing a query that calls AnotherCallback or even OnceMore again).
A very insightful proposition. The same example logic relates to what I did on my Company system.
Load all companies (From the company table) then grabbing all the Founders(From the main player table) per company (querying in an existing cache).
To avoid infinite loops, I have a print function in every callback(but primarily used for debugging). Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)