Jump to content

database query failed


Derpy

Recommended Posts

hi umm i was trying to practice sql and i got an error which makes no sense to me as table exists

local PLAYER_DATABASE = dbConnect("sqlite","database/trexarex.db") 
  
setTimer(function() 
if PLAYER_DATABASE then 
   sendResult("successfully loaded player database! (trexarex.db)",root) 
   onDatabaseStart() 
else 
   errorMessage("failed to load player database! (trexarex.db)",root) 
end 
end,50,1) 
  
  
function onDatabaseStart() 
dbExec(PLAYER_DATABASE, "CREATE TABLE IF NOT EXISTS data_system ( serial TEXT, ip TEXT, account TEXT, country TEXT)") 
outputDebugString("onDatabaseStart; data_system SQL Table created!") 
validatePlayerData() 
end 
  
function validatePlayerData() 
   for i,v in pairs(getElementsByType("player")) do 
      local result = executeSQLQuery("SELECT * FROM data_system WHERE serial=?",getPlayerSerial(v)) 
      if #result == 0 then 
         dbExec( "INSERT INTO data_system ( serial, ip, account, country ) VALUES ( ?, ?, ?, ? )", 
            getPlayerSerial(v),getPlayerIP(v),getAccountName(getPlayerAccount(v)),getElementData(v,"country") or "Unknown") 
            sendResult("successfully executed data into data_system",root) 
      else 
         --nothing? 
         errorMessage("already found the data :O",root) 
      end 
   end 
end 

custom and built in debug methods show that table was created, and it says dbExec: no such table data_system at line 23

please help

Link to comment

Okay thank you very much!

Though since im still pretty new to sql, is there a way to prevent having 100 things on e.g same name?

i have added additional data in sql; name

so i would want that if nick isnt in sql database that it writes all data as usual(even if serial is already in sql database) ,otherwise it writes nothing in it

can you please show me an example how to do this?

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