tosfera Posted February 20, 2013 Share Posted February 20, 2013 hey I'm trying to save some data into my db but it keeps saying that the colum: ID doens't exist. but I am creating it, I already dropped the database and remade it but it isn't working. addEventHandler("onResourceStart", root, function () db = dbConnect( "sqlite", "players.db" ) executeSQLQuery("CREATE TABLE IF NOT EXISTS player_vehicle (ID int, modelID int, color1 int, color2 int, color3 int, color4 int, vehicleOwner TEXT, upgrades TEXT, saveX TEXT, saveY TEXT, saveZ TEXT, vehicleHealth TEXT)") end ) function insertData_buyVehicle(vehiclecreated) local modelID = getElementModel(vehiclecreated) local accName = getAccountName ( getPlayerAccount ( source ) ) local color_1, color_2, color3, color4 = getVehicleColor(vehiclecreated) local owner = setElementData(vehiclecreated, "vehicle-owner", accName) insert = executeSQLQuery("INSERT INTO player_vehicle(ID, modelID,color1,color2,color3,color4,vehicleOwner, vehicleHealth, saveX, saveY, saveZ) VALUES(MAX(ID)+1,?,?,?,?,?,?,?,?,?,?)", modelID, color1, color2, color3,color4, accName, "1000", 2138.6918945313, -1120.3012695313, 26 ) if ( insert ) then outputChatBox("You're the new owner of this car!", source) else outputChatBox("Something went wrong!", source) end end Link to comment
csiguusz Posted February 20, 2013 Share Posted February 20, 2013 You cant get a value when doing INSERT (as far as I know), it's only possible with SELECT: function insertData_buyVehicle(vehiclecreated) local modelID = getElementModel(vehiclecreated) local accName = getAccountName ( getPlayerAccount ( source ) ) local color_1, color_2, color3, color4 = getVehicleColor(vehiclecreated) local owner = setElementData(vehiclecreated, "vehicle-owner", accName) local id = executeSQLQuery("SELECT COUNT(ID) as 'id_' FROM player_vehicle") insert = executeSQLQuery("INSERT INTO player_vehicle(ID, modelID,color1,color2,color3,color4,vehicleOwner, vehicleHealth, saveX, saveY, saveZ) VALUES(?,?,?,?,?,?,?,?,?,?,?)", id[1].id_ , modelID, color1, color2, color3,color4, accName, "1000", 2138.6918945313, -1120.3012695313, 26 ) if ( insert ) then outputChatBox("You're the new owner of this car!", source) else outputChatBox("Something went wrong!", source) end end Link to comment
tosfera Posted February 20, 2013 Author Share Posted February 20, 2013 woow, would have never tought about that, thanks mate! 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