[++Rep] SQLlite code question
#1

Hi

Still have troubles with the sqllite codes.. the problem is : it wont save houses when a player has bought them (with the players values).

Here is a piece of the code that the issue is in:

pawn Code:
new string[256];
        format(string, sizeof(string), "Failstep 1 : House owner : %s and house owned %d", AHouseData[HouseID][Owner], AHouseData[HouseID][Owned]);
        print(string);

        strcat(HouseStrCat, "UPDATE `Houses` SET `HouseAddress` = '%s', `HouseName` = '%s', `HouseX` = '%f', `HouseY` = '%f', `HouseZ` = '%f', `HouseInterior` = '%d', `HouseMaxSlots` = '%d', `HouseNewMaxSlots` = '%d', `HousePrice` = '%d', `Owned` = '%d', `HouseOpened` = '%d', ", sizeof(HouseStrCat)); // 11
        strcat(HouseStrCat, "`PlayerIsTycoon` = '%d', `Owner` = '%s', `Insurance` = '%d' WHERE `HouseID` = '%d'", sizeof(HouseStrCat)); // 15
        format(Query, sizeof(Query), HouseStrCat, AHouseData[HouseID][HouseAddress], AHouseData[HouseID][HouseName], AHouseData[HouseID][HouseX], AHouseData[HouseID][HouseY], AHouseData[HouseID][HouseZ], AHouseData[HouseID][HouseInterior], AHouseData[HouseID][HouseMaxSlots], AHouseData[HouseID][HouseNewMaxSlots], AHouseData[HouseID][HousePrice], AHouseData[HouseID][Owned],
        AHouseData[HouseID][HouseOpened], AHouseData[HouseID][PlayerIsTycoon], AHouseData[HouseID][Owner], AHouseData[HouseID][Insurance], HouseID); // 15

        db_free_result(db_query(Database, Query));
        strdel(HouseStrCat, 0, 800);

        format(Query, sizeof(Query), "SELECT * FROM `Houses` WHERE `HouseID` = '%d'", HouseID);
        Result2 = db_query(Database,Query);

        new ParameterValue[50], ParameterValue2[50];
        db_get_field_assoc(Result2, "Owned", ParameterValue, 50);
        db_get_field_assoc(Result2, "Owner", ParameterValue, 50);

        format(string, sizeof(string), "Failstep 1 : House owned : %d and house owner %s", ParameterValue, ParameterValue2);
        print(string);
Let me explain: the first failstep shows values : Owner : "Hessu" and owned : 1 as it should, but
the second failstep looks like : owned : 0 and owner :

It somehow is not saving the new values in properly!
The strings, integers and floats are all at the right place in the update query.

If you find the issue or something, +rep for you.

Thanks.
Reply
#2

Why are you freeing the result as you run the query? Wouldn't this mean you immediately erase all the data which the query pulls from the DB?

Or am I mis-understanding this?

Code:
db_free_result(db_query(Database, Query));
edit:

nvm, that is from the update query...

but also noticed the string is wrong in:

Code:
db_get_field_assoc(Result2, "Owner", ParameterValue, 50); // change parameterValue to parametervalue2
Reply
#3

Is the issue the saving or the loading?

If you connect to the MySQL DATABASE, can you see if the values are updating?
Reply
#4

Thanks for the replies, Mowgli.

This : "db_get_field_assoc(Result2, "Owner", ParameterValue, 50); // change parameterValue to parametervalue2"
Yes there was one issue.

Well i dont know if its the saving or loading really, but it seems like that when i save it, it doesnt really save it in the sql database.

This is wierd since i got the savings and loadings for player starts (+40 tables) working fine.

I am using SQLite, not mySQL, so i dont know about that.

And the really wierd thing is that the not owned houses (just created) save with their values and if a player buys a house, it just becomes "for sale" after server restart, so this again would mean its an issue with loading the database...

If you want, i can send you the whole code to your email, if you pm it to me.
Reply
#5

With this code :

pawn Code:
else if(db_num_rows(Result)) // The house ID is in the database. Update the values
    {
   
        for(new i = 0; i <= MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                SendClientMessage(i, -1, "The house was found in database! Updating..");
            }
        }
        new string[256];
        format(string, sizeof(string), "Failstep 1 : House owner : %s and house owned %d", AHouseData[HouseID][Owner], AHouseData[HouseID][Owned]);
        print(string);

        strcat(HouseStrCat, "UPDATE `Houses` SET `HouseAddress` = '%s', `HouseName` = '%s', `HouseX` = '%f', `HouseY` = '%f', `HouseZ` = '%f', `HouseInterior` = '%d', `HouseMaxSlots` = '%d', `HouseNewMaxSlots` = '%d', `HousePrice` = '%d', `Owned` = '%d', `HouseOpened` = '%d', ", sizeof(HouseStrCat)); // 11
        strcat(HouseStrCat, "`PlayerIsTycoon` = '%d', `Owner` = '%s', `Insurance` = '%d' WHERE `HouseID` = '%d'", sizeof(HouseStrCat)); // 15
        format(Query, sizeof(Query), HouseStrCat, AHouseData[HouseID][HouseAddress], AHouseData[HouseID][HouseName], AHouseData[HouseID][HouseX], AHouseData[HouseID][HouseY], AHouseData[HouseID][HouseZ], AHouseData[HouseID][HouseInterior], AHouseData[HouseID][HouseMaxSlots], AHouseData[HouseID][HouseNewMaxSlots], AHouseData[HouseID][HousePrice], AHouseData[HouseID][Owned],
        AHouseData[HouseID][HouseOpened], AHouseData[HouseID][PlayerIsTycoon], AHouseData[HouseID][Owner], AHouseData[HouseID][Insurance], HouseID); // 15
        db_query(Database, Query);
       
        strdel(HouseStrCat, 0, 800);

        format(Query, sizeof(Query), "SELECT * FROM `Houses` WHERE `HouseID` = '%d'", HouseID);
        Result2 = db_query(Database,Query);

        new ParameterValue[50], ParameterValue2[50];
        db_get_field_assoc(Result2, "Owned", ParameterValue, 50);
        db_get_field_assoc(Result2, "Owner", ParameterValue2, 50);

        format(string, sizeof(string), "Failstep 1 : House owner : %s and house owned %d", ParameterValue2, ParameterValue);
        print(string);





        for(new i = 0; i <= MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                SendClientMessage(i, -1, "Updated!");
            }
        }

    }
The failsteps return these messages:

Code:
[17:07:46] Kulottaja used: /buyhouse 
[17:07:46] Failstep 1 : House owner : Kulottaja and house owned 1
[17:07:46] Failstep 1 : House owner :  and house owned 48
The first failstep message (format(string, sizeof(string), "Failstep 1 : House owner : %s and house owned %d", AHouseData[HouseID][Owner], AHouseData[HouseID][Owned])

Returned the correct values as you could see (Kulottaja and house owned returned 1)

But then then it was saved, i load the 2 values from the database just to check if they are correct, and there is still the problem. The owner of house is not "" and it returns value 48 at house owned...


I got no idea anymore, but maybe a db_free_result issue?
Reply
#6

You need to get sqlitei and enable error checking it will show any bad queries.
https://sampforum.blast.hk/showthread.php?tid=303682
Reply
#7

Thanks. I took a look at it, but it didnt print any errors, of the code, exept one db_free_result.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)