Vehicles ID's

Started by kennedyarz, Sep 06, 2017, 02:24 AM

Previous topic - Next topic

kennedyarz

I have a doubt. good and is a problem that is happening in my script and I do not know or better said. I do not remember how to solve it. I happen to have a database with this structure.


Suppose you create 100 Vehicles. then delete the first 30. But these vehicles as seen have an ID in the database. then I would start counting from 31 onwards. but with this function "+ Vehicle.ID +" will not start reading from 31 if not from the first, then when the player gets into a car it reads in the "+ Vehicle.ID +" but as we know it is different from the ID that exits in the database, so when the player enters the vehicle the Owner appears "NULL". how to avoid this ???

KAKAN

update the IDs. Simple.
oh no

kennedyarz

Quote from: KAKAN on Sep 06, 2017, 02:47 AMupdate the IDs. Simple.

already knew. but how should be the function? to update ids?

DizzasTeR

Either don't have a PRIMERY ID like you have now, or just re-alter the table so they get re-counted from 1. This ofcourse affects every ID on server which means you have to destroy all the vehicles and re-create them with the new reference IDs of the database for proper updating.

kennedyarz

Quote from: Doom_Kill3R on Sep 06, 2017, 11:19 AMEither don't have a PRIMERY ID like you have now, or just re-alter the table so they get re-counted from 1. This ofcourse affects every ID on server which means you have to destroy all the vehicles and re-create them with the new reference IDs of the database for proper updating.

all right. but do you know the method to count from vehicle 1 and change your id in the database? is that I will always be removing vehicles from the server, which means that I must compile IDs as it is a great job to delete the database and create it again every time a vehicle is deleted. any idea how to do it?

kennedyarz

#5
Does this work well? or cause some error? and what mistakes?
   function ResetIDs()
    {
        local q = QuerySQL(db,"SELECT ID FROM Vehicles");
        for(local i = 1; i < 2500; i++)
        {
            local veh = FindVehicle( i );
            if (veh)
{
                QuerySQL(db"UPDATE Vehicles SET ID='"+veh.ID+"' WHERE ID='"+GetSQLColumnData(q,0)+"'");
                GetSQLNextRow( q );
print("Vehicles Loaded - "+i);
            }
        }
    }

retarded

Anik

Execute this on "Execute SQL" on the DB Browser.
UPDATE Vehicles SET ID = rowid

kennedyarz

Quote from: Anik on Sep 06, 2017, 03:19 PMExecute this on "Execute SQL" on the DB Browser.
UPDATE Vehicles SET ID = rowid

the command does not work well, says that it runs without problems but does not change its ID's to the same value as rowid, probe with other commands and worked, but with that not.

!

#8
Use this function and then restart your server
function ResetIDs()
    {
    local q = QuerySQL(db,"SELECT ID FROM Vehicles"), i = 1;
    while( GetSQLColumnData( q, 0 ) != null )
       {
       QuerySQL(db"UPDATE Vehicles SET ID='"+i+"' WHERE ID='"+GetSQLColumnData(q,0)+"'");
       i++;
       GetSQLNextRow( q );
       }
    FreeQuery( q );
    print("Vehicles Loaded - "+i);
    }

 :edit:
P.S: After using above function don't use this
UPDATE Vehicles SET ID = rowid
Cause it will change the ids to the one used upon INSERT

Discord: zeus#5155

Sandisk

Quote from: ! on Sep 18, 2017, 05:19 AMUse this function and then restart your server
function ResetIDs()
    {
    local q = QuerySQL(db,"SELECT ID FROM Vehicles"), i = 1;
    while( GetSQLColumnData( q, 0 ) != null )
      {
      QuerySQL(db"UPDATE Vehicles SET ID='"+i+"' WHERE ID='"+GetSQLColumnData(q,0)+"'");
      i++;
      GetSQLNextRow( q );
      }
    FreeQuery( q );
    print("Vehicles Loaded - "+i);
    }

 :edit:
P.S: After using above function don't use this
UPDATE Vehicles SET ID = rowid
Cause it will change the ids to the one used upon INSERT

myproblem: when i create a vehicle in the server it spawns with 243 id when i restart the server it changes into 68 id
so the id 68 is not in the database so i got errors

this function doesn't work and doesn't change the ids in the database

console : "[SCRIPT] Vehicles Count (69)
           [SCRIPT] Vehicles Loaded - 1"