Jump to content

No such column


tosfera

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...