Gtagasje Posted January 12, 2014 Share Posted January 12, 2014 Hello there, Once again, something is bugging me. And once again, it's mysql. I have made a function which adds something to the table, and then right after that checks for a value in that table, since 1 of the columns is auto increment. I guess my function would explain it better: function createHouse(x, y, z, interior, intx, inty, intz, price) local handler = dbQuery(connection, "INSERT INTO Houses(X, Y, Z, Interior, IntX, IntY, IntZ, Locked, Passworded, Password, Price, Sale, Owner) VALUES(?,?,?,?,?,?,?,'No','No','',?,'No','')", x, y, z, interior, intx, inty, intz, price) local res = dbPoll(handler, -1) if res then local resid = dbPoll(dbQuery(connection, "SELECT * FROM Houses WHERE X=? AND Y=? AND Z=? AND Interior=? AND IntX=? AND IntY=? AND IntZ=? AND Price=?", x, y, z, interior, intx, inty, intz, price), -1) outputChatBox("House "..(resid.ID).." has been created successfully!", source, 0, 255, 0) -- Error line buildHouse(id, x, y, z, interior, intx, inty, intz, price) else outputChatBox("An error occured while creating the house!", source, 255, 0, 0) end end addEvent("createHouse", true) addEventHandler("createHouse", getRootElement(), createHouse) Now the error I'm getting is as following: attempt to concatenate field 'ID' (a nil value) This is getting caused at the line of the outputChatBox(). I have tried delaying the selecting with 1 second, but that gave the same error. So I do not think the database being slow is the problem. So, I really have no clue what is causing this error, and as you can maybe tell I am yet to be an expert at mysql. Thanks in advance, Gtagasje. Link to comment
Gtagasje Posted January 12, 2014 Author Share Posted January 12, 2014 I'm not sure if it's the same, but I tried using resid[1]["ID"]. I think I got the same error, but again, I'm not sure if it's the same, and I'm not sure if I got exactly the same error. I'll test it tomorrow, posting this via phone. Link to comment
Castillo Posted January 12, 2014 Share Posted January 12, 2014 Don't use dbQuery for insert queries, use dbExec. Link to comment
Gtagasje Posted January 12, 2014 Author Share Posted January 12, 2014 Hmm, not sure why I did it. I guess I'll change that too then (too bad I'm still on my phone.) Also, on a side note, why is it better to use dbExec for insert queries? Because when I looked at the database, it inserted it perfectly fine, and I'm kinda curious now. Link to comment
Castillo Posted January 12, 2014 Share Posted January 12, 2014 Well, dbQuery is used if you need to get a result. Link to comment
Gtagasje Posted January 13, 2014 Author Share Posted January 13, 2014 Okay, so, now I've changed the things you pointed out, and I have this: function createHouse(x, y, z, interior, intx, inty, intz, price) local handler = dbExec(connection, "INSERT INTO Houses(X, Y, Z, Interior, IntX, IntY, IntZ, Locked, Passworded, Password, Price, Sale, Owner) VALUES(?,?,?,?,?,?,?,'No','No','',?,'No','')", x, y, z, interior, intx, inty, intz, price) if handler then local resid = dbPoll(dbQuery(connection, "SELECT * FROM Houses WHERE X=? AND Y=? AND Z=? AND Interior=? AND IntX=? AND IntY=? AND IntZ=? AND Price=?", x, y, z, interior, intx, inty, intz, price), -1) outputChatBox("House "..(resid[1].ID).." has been created successfully!", source, 0, 255, 0) buildHouse(id, x, y, z, interior, intx, inty, intz, price) else outputChatBox("An error occured while creating the house!", source, 255, 0, 0) dbFree(resid) end end addEvent("createHouse", true) addEventHandler("createHouse", getRootElement(), createHouse) Yet, now I get this error(on the outputChatBox() line again.): ERROR: Attempt to index field '?'(a nil value) Any ideas on what's the problem? Link to comment
Baseplate Posted January 13, 2014 Share Posted January 13, 2014 Because the "ID" column is empty, did you insert any data in it? Link to comment
Gtagasje Posted January 13, 2014 Author Share Posted January 13, 2014 Yup, the data was being inserted, but when I wanted to go and take a screenshot I saw what was wrong. Appearently the database rounded the x y and z to 0 decimals, so the check I did afterwards obviously didn't exist, because that had like 10 decimals. So thank you for making me check that. 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