help change to sqlite
#1

hi $:, someone explain to me how to change it please sqlite

pawn Код:
stock GetFreeHouseID()
{
    Loop(h, MAX_HOUSES, 0)
    {
        if(!fexist(HouseFile(h)))
        {
            return h;
        }
    }
    return -1;
}
Reply
#2

I recently switched from dini to SQLite and my CreateHouse command searches for house level that is equal to 0, and then it change it to some other. You need to use saving and loading only with SQLite, you don't need to do anything with it while you are creating/deleting houses or anything.
But if you want really want to it while you are creating a house, you should search for the first empty row in your database.
Here is the example:
pawn Код:
for(new i = 0; i< MAX_HOUSES, i++)
{
     format(string, sizeof(string), "SELECT ID FROM `houses` WHERE `ID`='%d'", i);
        dbresult = db_query(Database, string);
        if(!db_num_rows(dbresult))
        {
            // code for creating the house
            return 1;
        }
            db_free_result(dbresult);
}
Reply
#3

Thanks friend, I want to achieve is that if I have 100 houses and 80 delete the id I get to look again create an empty space in such a case would be 80. and not follow 101.

Sorry use translate
Reply
#4

so you want to check the first ID that is unused?
Reply
#5

If bone, Guide createhouse command:

id = GetFreeHouseID ();

so take some ID, this is not another home using
Reply
#6

small bump
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)