SQLite: Saving Code Run Two Times?
#1

I've made a dynamic family system with SQLite that is supposed to work like the Godfather one's did.

When I save:
  1. I first delete all the rows.
  2. Next, I insert a new row as a 'blank' family.
  3. I then check if the family is taken, if it is, then it is updated.
  4. If it's not then the slot just stays as a blank family.
But, for some reason the amount of rows doubles each time this saving function is called.
pawn Код:
public SaveFamilies()
{
    new
        id=0,
        query[256]
    ;
    db_free_result(db_query(Database, "DELETE * FROM `Families`"));
    while(id < MAX_FAMILIES)
    {
        format(query, sizeof(query), "INSERT INTO `Families` (`Slot`, `Taken`, `Name`, `Leader`, `MOTD`, `Count`, `Rank1`, `Rank2`, `Rank3`, `Rank4`, `Rank5`, `Rank6`) \
                                                                VALUES ('%d', '0', 'None', 'None', 'None', '0', 'Rank1', 'Rank2', 'Rank3', 'Rank4', 'Rank5', 'Rank5')"
, id);
        db_free_result(db_query(Database, query));
       
        if(FamilyInfo[id][fTaken] == 1)
        {
            format(query, sizeof(query), "UPDATE `Families` SET Name = '%s', Leader = '%s', MOTD = '%s', Count = '%d', Taken = '%d' WHERE Slot = '%d'",
            FamilyInfo[id][fName],
            FamilyInfo[id][fLeader],
            FamilyInfo[id][fMOTD],
            FamilyInfo[id][fCount],
            FamilyInfo[id][fTaken],
            id);
            db_free_result(db_query(Database, query));
            format(query, sizeof(query), "UPDATE `Families` SET Rank1 = '%s', Rank2 = '%s', Rank3 = '%s', Rank4 = '%s', Rank5 = '%s', Rank6 = '%s' WHERE Slot = '%d'",
            FamilyRank[id][0],
            FamilyRank[id][1],
            FamilyRank[id][2],
            FamilyRank[id][3],
            FamilyRank[id][4],
            FamilyRank[id][5],
            id);
            db_free_result(db_query(Database, query));
        }
        id++;
    }
    return 1;
}
Any help would be appreciated.
Reply


Messages In This Thread
SQLite: Saving Code Run Two Times? - by ReneG - 13.06.2012, 00:57
Re: SQLite: Saving Code Run Two Times? - by Lorenc_ - 13.06.2012, 05:58
Re: SQLite: Saving Code Run Two Times? - by ReneG - 13.06.2012, 06:15
Re: SQLite: Saving Code Run Two Times? - by Lorenc_ - 13.06.2012, 06:26
Re: SQLite: Saving Code Run Two Times? - by ReneG - 13.06.2012, 07:03
Re: SQLite: Saving Code Run Two Times? - by PrawkC - 13.06.2012, 07:24
Re: SQLite: Saving Code Run Two Times? - by ReneG - 13.06.2012, 07:45

Forum Jump:


Users browsing this thread: 1 Guest(s)