Get free mysql slot? Threaded -
Dokins - 07.04.2016
pawn Код:
new vehslotfree = GetFreeMySQLSlot("vehicles");
I'm trying to find the free slot so I don't have to insert a row if I have a inactive slot when I delete a vehicle.
pawn Код:
GetFreeMySQLSlot(tablename[])
{
new query[128], temp[12];
format(query, sizeof (query),"SELECT `id` FROM %s WHERE `inactive` = 1 ORDER BY id ASC LIMIT 1", tablename);
new Cache:result = mysql_query(dbHandle, query), value;
if (!cache_num_rows())
{
return 0;
}
cache_get_row(0,0,temp);
value = strval(temp);
cache_delete(result);
return value;
}
It deletes all the rows information (UPDATE...)
and replaces all the data to 0 in every row except 1.
pawn Код:
GetFreeMySQLSlot(tablename[])
{
new query[128], temp[12];
format(query, sizeof (query),"SELECT `id` FROM %s WHERE `inactive` = 1 ORDER BY id ASC LIMIT 1", tablename);
new Cache:result = mysql_query(dbHandle, query), value;
if (!cache_num_rows())
{
return 0;
}
cache_get_row(0,0,temp);
value = strval(temp);
cache_delete(result);
return value;
}
Re: Get free mysql slot? Threaded -
Konstantinos - 07.04.2016
https://sampforum.blast.hk/showthread.php?tid=302194
You can get an idea of how to do it (the query, ignore non-threaded).
Why don't you want to use it as dynamic though?
Re: Get free mysql slot? Threaded -
Dokins - 07.04.2016
What do you mean?
I'm basically trying to assign a vehicle to an inactive slot, it changes ALL of the inactive to 1. Actually....I might be looking in the wrong place.
EDIT:
EDIT 2:
RESOLVED, STRING SIZE WAS TOO SMALL AND WAS AFFECTING ALL ROWS.
The issue seems to be with delete vehicle.
It deletes ALL the vehicles (sets them to inactive.)
pawn Код:
format(query, sizeof(query), "UPDATE `vehicles` SET Inactive = 1, VehModel = 0, VehJob = -1,VehOwner = 0, VehColour1 = 0, VehColour2 = 0, VehPlate = '0', VehSpawnX = 0, VehSpawnY = 0, VehSpawnZ = 0, VehSpawnAngle = 0, VehFuel = 0, VehCash = 0, VehArmour = 0,VehFaction = 0,VehFRank = 0, VehOwned = 0, VehFactioned = 0, VehWeed = 0, VehCoke = 0, VehBizID = 0, VehForSale = 0, VehPrice = 0 WHERE `id` = %d LIMIT 1", VehicleSQLID[vehicleid]);
mysql_tquery(dbHandle, query, "DeletedVeh", "ii", playerid, vehicleid);