Jump to content

SQL problem


jokerjab

Recommended Posts

Hello guys, I'm having some problems with SQL. When I insert rows into columns and update it with new values so the old ones are replaced with the new ones, right?

Ok so the second question is that how do I loop through the rows? It still keep giving me the same 100 value.

  
function SQLTest() 
if executeSQLQuery("CREATE TABLE IF NOT EXISTS aa(Name TEXT, Cash NUMBER, Health NUMBER)") then 
if executeSQLQuery("INSERT INTO aa(Name, Cash, Health) VALUES(?,?,?)", "myName", 1554, 100 ) then -- 100 health 
local asa = 150 + getElementHealth(getPlayerFromName("What?")) -- should be 100 + now 
if executeSQLQuery("UPDATE aa SET Name = ?,Cash= ?,Health = ? WHERE Health = '"..asa.."'", "myName", 140, 100) then -- executed 
 local Health = executeSQLQuery("SELECT * FROM aa WHERE Health = ?", 100) -- selected 
 if #Health ~= 0 then 
 outputChatBox ( Health[1]["Health"] )  -- but still the same 100 
 end 
 end 
 end 
 end 
 end 
 SQLTest() 
  

This outputs 100? I think I'm updating it incorrectly any idea?

Link to comment

Your code doesn't make much sense but anyway it should look something like:

function SQLTest() 
if executeSQLQuery("CREATE TABLE IF NOT EXISTS aa(Name TEXT, Cash NUMBER, Health NUMBER)") then 
if executeSQLQuery("INSERT INTO aa(Name, Cash, Health) VALUES(?,?,?)", "myName", 1554, 100 ) then -- 100 health 
local asa = 150 + getElementHealth(getPlayerFromName("What?")) -- should be 100 + now 
if executeSQLQuery("UPDATE aa SET Name = ?,Cash= ?,Health = ? WHERE Health = 100", "myName", 140, asa) then -- executed 
 local Health = executeSQLQuery("SELECT * FROM aa WHERE Health = ?", asa) -- selected 
 if #Health ~= 0 then 
 outputChatBox ( Health[1]["Health"] )  -- but still the same 100 
 end 
 end 
 end 
 end 
 end 
 SQLTest() 

Link to comment
Your code doesn't make much sense but anyway it should look something like:
function SQLTest() 
if executeSQLQuery("CREATE TABLE IF NOT EXISTS aa(Name TEXT, Cash NUMBER, Health NUMBER)") then 
if executeSQLQuery("INSERT INTO aa(Name, Cash, Health) VALUES(?,?,?)", "myName", 1554, 100 ) then -- 100 health 
local asa = 150 + getElementHealth(getPlayerFromName("What?")) -- should be 100 + now 
if executeSQLQuery("UPDATE aa SET Name = ?,Cash= ?,Health = ? WHERE Health = 100", "myName", 140, asa) then -- executed 
 local Health = executeSQLQuery("SELECT * FROM aa WHERE Health = ?", asa) -- selected 
 if #Health ~= 0 then 
 outputChatBox ( Health[1]["Health"] )  -- but still the same 100 
 end 
 end 
 end 
 end 
 end 
 SQLTest() 

Thanks it works in this way. I was really going to do it in this way

local Health = executeSQLQuery("SELECT * FROM aa WHERE Health = ?", asa) 

but after reading this tutorial kinda confused me but anyway I learned my lesson and next time I will go with wiki examples. :lol:

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...