This seems to works, I've changed the test condition on result by the one provided in the wiki:
executeSQLCreateTable ( "test", "username TEXT" )
function addInfoToSQL()
local sourcename = getPlayerName ( source )
local result = executeSQLSelect ( "test", "username", "username = '" .. getAccountName(getPlayerAccount(source)) .. "'" )
if ( type( result ) == "table" and #result == 0 ) or not result then
outputChatBox ( "This is your first time here! Welcome " .. sourcename .. "!", source )
executeSQLInsert ( "test","'" .. getAccountName(getPlayerAccount(source)) .. "'" )
else
outputChatBox ( "Welcome back " .. result[1]["username"] .. "!", source ) -- what should I put here to get player username ?
executeSQLUpdate ( "test", "username = '" .. sourcename .. "'" )
end
end
addEventHandler ( "onPlayerLogin", getRootElement(), addInfoToSQL)