Error on mysql_query

07/01/2013 08:29 Kzee#1
Hello, i've got an error on a query i placed in a quest.
I would like to receive some help if possible :P


Error on syserr:
Code:
SYSERR: Jul  1 06:23:23 :: RunState: LUA_ERROR: [string "pet_system"]:8: attempt to index field `duracao' (a nil value)
SYSERR: Jul  1 06:23:23 :: WriteRunningStateToSyserr: LUA_ERROR: quest pet_system.start click
Query on quest:
Code:
local tempo = get_time()
local query = mysql_query("SELECT duracao FROM pets WHERE nome='"..pc.get_name ().."' and pet=pet_info[1] ORDER BY duracao DESC LIMIT 1")
	if tempo > tonumber(query.duracao[1]) then
		notice("Text")
		notice("Text")
	else
MySQL function:
Code:
mysql_query = function(query)
    if not pre then
        local rt = io.open('CONFIG', 'r'):read('*all')
        pre = string.gsub(rt, '.+PLAYER_SQL:%s(%S+)%s(%S+)%s(%S+)%s(%S+).+', '-h%1 -u%2 -p%3 -D%4')
    end

    math.randomseed(os.time())

    local fi, t, out = 'mysql_data_'..math.random(10^9)+math.random(2^4,2^10),{},{}
	os.execute('mysql '..pre..' --execute='..string.format('%q',query)..' > '..fi) 

    for av in io.open(fi, 'r'):lines() do table.insert(t,split(av, '\t')) end; os.remove(fi);
    for i = 2, table.getn(t) do table.foreach(t[i],function(a, b)
        out[i-1]               = out[i-1] or {}
        out[i-1][a]            = tonumber(b) or b
        out[t[1][a]]           = out[t[1][a]] or {}
        out[t[1][a]][i-1]      = tonumber(b) or b
    end) end
    return out
end
MySQL version installed on server: 5.5.31

Thanks in advance :)
Kzee!
07/02/2013 17:39 Kzee#2
bump