xXMADEXx Posted March 10, 2013 Share Posted March 10, 2013 Hey guys, im making a vehicle save system based on sqlite. I don't know how to make a vehicle only save once, because how i have it, the vehicles are saving a new row each time, so each car will create a new row every second, and i only want 1 vehicle in the sqlite once... I don't think that makes since, but lets just say every car is creating a new row every second, and i what the rows to update... and if there isnt a row for that vehicle, then create one.. connectToDb = dbConnect( "sqlite", "sql/saves.db" ) addEventHandler('onResourceStart',getResourceRootElement(), function () if (not connectToDb) then outputChatBox("ERROR: saves.db has failed to load!",255,0,0) else dbExec ( connectToDb, "CREATE TABLE IF NOT EXISTS 'vehciles' ( rowID INT PRIMARY KEY, id TEXT, x INT, y INT, z INT, int INT, dim INT )" ) dbQuery(dbLoadVehiclesOnResourceStart, connectToDb, "SELECT * FROM vehciles") end end ) function dbLoadVehiclesOnResourceStart(queryHandle) local sql = dbPoll(queryHandle, 0) if sql and #sql > 0 then for index, sqlRow in ipairs(sql) do local id = sqlRow['id'] local x = sqlRow["x"] local y = sqlRow['y'] local z = sqlRow['z'] local int = sqlRow['int'] local dim = sqlRow['dim'] vehicle = createVehicle(id,x,y,z) setElementInterior(vehicle,int) setElementDimension(vehicle,dim) end end end setTimer( function () for _,car in ipairs (getElementsByType('vehicle')) do if (getElementData(car,'vehOwner')=="spawners") then else local id = getVehicleModelFromName(getVehicleName(car)) local x,y,z = getElementPosition(car) local int = getElementInterior(car) local dim = getElementDimension(car) dbExec ( connectToDb, "INSERT INTO vehciles ( id, x, y, z, int, dim ) VALUES ( ?, ?, ?, ?, ?, ? )", id, x, y, z, int, dim) --dbExec ( connectToDb, "INSERT INTO houses ( city, zone, owner, x, y, z, int, dim ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ? )", city, zone, none, x, y, z, int, dim ) end end end, 1000, 0 ) So, basicly its this is what is doing: and, i only want 1 row per car... not 500000000 rows a car. Link to comment
Castillo Posted March 10, 2013 Share Posted March 10, 2013 Well, for that you'll have to define an ID, so if that ID is on database, don't add it, but update it. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now