Garage not created
#1

Can someone tell me why this CMD doesn't insert the new created garage in database? (I'm using SQLITEI).

I don't even get the message "garage created successfully etc.", but ingame mapicon label and pickup is created.

pawn Код:
CMD:cgarage(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return 0;

    new id = Garage_FindFreeID();

    if(id == -1) return SCM(playerid, COLOR_ERROR, "» Server garages limit reached.");

    new price, size;

    if(sscanf(params, "dd(0)", price, size))
    {
        SCM(playerid, COLOR_BELGREEN, "» [USAGE]: /cgarage [price] [size(default 0)]");
        return SCM(playerid, COLOR_BELGREEN, "» Size: 0 - Small Garage , 1 - Medium Garage, 2 - Big Garage.");
    }

    if((size < 0) || (size > 2)) return SCM(playerid, COLOR_ERROR, "» Size must be from 0 to 2.");
    if((price < 1) || (price > 999999)) return SCM(playerid, COLOR_ERROR, "» Invalid price.");

    GetPlayerPos(playerid, GarageData[id][garageX], GarageData[id][garageY], GarageData[id][garageZ]);
    GetPlayerFacingAngle(playerid, GarageData[id][garageA]);

    GarageData[id][garageX] += (1.25 * floatsin(-GarageData[id][garageA], degrees));
    GarageData[id][garageY] += (1.25 * floatcos(-GarageData[id][garageA], degrees));

    GarageData[id][garageA] += 180.0;

    GarageData[id][garageInterior] = GetPlayerInterior(playerid);
    GarageData[id][garageVW] = GetPlayerVirtualWorld(playerid);

    GarageData[id][garageOwnerID] = 0;
    GarageData[id][garageOwned] = 0;

    GarageData[id][garagePrice] = price;
    GarageData[id][garagePlayerSellPrice] = 0;

    GarageData[id][garageSize] = size;

    format(GarageData[id][garageName], MAX_GARAGE_NAME, "-");
   
    format(GarageData[id][garageOwnerName], MAX_PLAYER_NAME, "-");
   
    GarageData[id][garageVaultMoney] = 0;
   
    GarageData[id][garageLockMode] = LOCK_MODE_NOLOCK;
   
    format(GarageData[id][garagePassword], MAX_GARAGE_PASSWORD, "-");

    UpdateGarageLabel(id);

    GarageData[id][garageExists] = true;

    stmt_bind_value(AddGarage, 0, DB::TYPE_INTEGER, id);

    stmt_bind_value(AddGarage, 1, DB::TYPE_FLOAT, GarageData[id][garageX]);
    stmt_bind_value(AddGarage, 2, DB::TYPE_FLOAT, GarageData[id][garageY]);
    stmt_bind_value(AddGarage, 3, DB::TYPE_FLOAT, GarageData[id][garageZ]);
    stmt_bind_value(AddGarage, 4, DB::TYPE_FLOAT, GarageData[id][garageA]);

    stmt_bind_value(AddGarage, 5, DB::TYPE_INTEGER, GarageData[id][garageInterior]);
    stmt_bind_value(AddGarage, 6, DB::TYPE_INTEGER, GarageData[id][garageVW]);

    stmt_bind_value(AddGarage, 7, DB::TYPE_INTEGER, GarageData[id][garageOwnerID]);
    stmt_bind_value(AddGarage, 8, DB::TYPE_INTEGER, GarageData[id][garageOwned]);

    stmt_bind_value(AddGarage, 9, DB::TYPE_INTEGER, GarageData[id][garagePrice]);
    stmt_bind_value(AddGarage, 10, DB::TYPE_INTEGER, GarageData[id][garagePlayerSellPrice]);

    stmt_bind_value(AddGarage, 11, DB::TYPE_INTEGER, GarageData[id][garageSize]);
   
    stmt_bind_value(AddGarage, 12, DB::TYPE_STRING, GarageData[id][garageName]);
   
    stmt_bind_value(AddGarage, 13, DB::TYPE_STRING, GarageData[id][garageOwnerName]);
   
    stmt_bind_value(AddGarage, 14, DB::TYPE_INTEGER, GarageData[id][garageVaultMoney]);
   
    stmt_bind_value(AddGarage, 15, DB::TYPE_INTEGER, GarageData[id][garageLockMode]);
   
    stmt_bind_value(AddGarage, 16, DB::TYPE_STRING, GarageData[id][garagePassword]);

    if(stmt_execute(AddGarage)) SCM(playerid, COLOR_YELLOW, "» Garage created successfully at your position!");
    return 1;
}
AddGarage:

pawn Код:
AddGarage = db_prepare(GarageDB, "INSERT INTO garages (ID, garageX, garageY, garageZ, garageA, garageInterior, garageVW, garageOwnerID, garageOwned, garagePrice, garagePlayerSellPrice, garageSize, garageName, garageOnwerName, garageVaultMoney, garageLockMode, garagePassword) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
Reply
#2

Bump.
Reply
#3

Crash detect doesn't show any error.

This is what the debug prints:

Quote:

[14:55:54] ID: 0
[14:55:54] Garage X: -2347.253173 - Y: -1605.773193 - Z: 483.641113 - A: 521.176025
[14:55:54] Interior: 0 - VW: 0
[14:55:54] OnwerID: 0 - Owned: 0
[14:55:54] Price: 2500 - PSellPrice: 0
[14:55:54] Size: 2
[14:55:54] Name: -
[14:55:54] Owner Name: -
[14:55:54] Vault Money: 0
[14:55:54] Lock Mode: 0
[14:55:54] Password: -

Variables are correctly passed. Strange because i tried even with:

pawn Код:
new Query[1000];
    format(Query, sizeof(Query), "INSERT INTO garages (ID, garageX, garageY, garageZ, garageA, garageInterior, garageVW, garageOwnerID, garageOwned, garagePrice, garagePlayerSellPrice, garageSize, garageName, garageOnwerName, garageVaultMoney, garageLockMode, garagePassword) VALUES (%d, %f, %f, %f, %f, %d, %d, %d, %d, %d, %d, %d, '%e', '%e', %d, %d, '%e')",
    id, GarageData[id][garageX], GarageData[id][garageY], GarageData[id][garageZ], GarageData[id][garageA], GarageData[id][garageInterior], GarageData[id][garageVW], GarageData[id][garageOwnerID], GarageData[id][garageOwned], GarageData[id][garagePrice], GarageData[id][garagePlayerSellPrice], GarageData[id][garageSize], GarageData[id][garageName], GarageData[id][garageOwnerName], GarageData[id][garageVaultMoney], GarageData[id][garageLockMode], GarageData[id][garagePassword]);
    db_query(GarageDB, Query);
And it doesn't work too.
Reply
#4

Bump.
Reply
#5

Bump.
Reply
#6

Still needing help. Possible nobody knows how to fix?
Reply
#7

pawn Код:
VALUES (%d, %f, %f, %f, %f, %d, %d, %d, %d, %d, %d, %d, //...
You forgot apostrophes.
Reply
#8

Emh, where?
Reply
#9

pawn Код:
VALUES ('%d', '%f', '%f', '%f', '%f', '%d', '%d', '%d', '%d', '%d', //...
Reply
#10

Nothing, doesn't work. Garage is created ingame but nothing is shown on the .db file.
Reply
#11

Bump. I'm going crazy on this.
Reply
#12

For the "manual" insert, you use %e in format which isn't a valid specifier. I don't think this will cause it to fail though as it will just pass "e" instead of the string, however it will mess up the other specifiers because of the order. Just saying.

For the prepared statement, isn't it required to prepare it for everytime you want to use it?
So basically prepare, bind, execute and close it locally? Though I'm not sure about that but worth a try (but fix the following error first).

You misspelled garageOwnerName when preparing the statement and the other query (garageOnwerName).
Reply
#13

You got it, the problem was the mispelling of garageOwnerName. Now it works but there is a problem.

garageOwnerName is saved as "e"
garageVaultMoney as 45

Why? It should be null for both.
Reply
#14

Read my first sentence. %e is not a valid specifier in format() and the % sign is ignored (so just 'e'). Use %s or mysql_format.
As a result the following specifiers are mixed up and the 45 is probably the result of a string passed to an integer specifier.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)