• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[SQL/Lua] Return storeQuery

Otfan125

Well-Known Member
Joined
Mar 1, 2008
Messages
169
Solutions
1
Reaction score
55
Location
Thais
TFS VERSION: 1.3

Hey guys,
so this question is related to the previous two which I have posted and has to do with the function "storeQuery"... Check this out:

Lua:
function onLogin(player)
    local res = db.storeQuery("SELECT `blademaster` FROM `players` WHERE `name` = \"Angel\";")
    print(res)
    if res == 1 then
        print("test")
        local condition = Condition(CONDITION_BLADEMASTER)
        condition:setParameter(CONDITION_PARAM_TICKS, -1)
        player:addCondition(condition)
    end
    return true
end

I have here a small piece of code that executes the function "storeQuery", which is suppose to retrieve the value found in column 'blademaster' in 'players' for player=Angel. Note that this works fine the first time Angel logs in the game (i.e., res=1, verified with the print statement). Now, if Angel logs out of the game and back in, res actually returns plus one more than the previous log in (i.e., second time res=2, third time res=3, etc.) I've tried the following:


Lua:
    if db.storeQuery("SELECT `blademaster` FROM `players` WHERE `name` = \"Angel\";") == 1 then
        print("test")
        local condition = Condition(CONDITION_BLADEMASTER)
        condition:setParameter(CONDITION_PARAM_TICKS, -1)
        player:addCondition(condition)
    end

which simply avoids using "local res", though this doesn't work for the same reason (I think).
It seems that every time storeQuery is called, it adds to some global variable that is hidden somewhere... Is there perhaps a "delete" or "free" function that resets the storeQuery global variable (if any)?
 
Solution
E
Is there perhaps a "delete" or "free" function that resets the storeQuery global variable (if any)?
yes there is, example (line 8):
Lua:
function getGuildId(guildName)
    local resultId = db.storeQuery("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(guildName))
    if resultId == false then
        return false
    end

    local guildId = result.getNumber(resultId, "id")
    result.free(resultId)
    return guildId
end
Is there perhaps a "delete" or "free" function that resets the storeQuery global variable (if any)?
yes there is, example (line 8):
Lua:
function getGuildId(guildName)
    local resultId = db.storeQuery("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(guildName))
    if resultId == false then
        return false
    end

    local guildId = result.getNumber(resultId, "id")
    result.free(resultId)
    return guildId
end
 
Solution
yes there is, example (line 8):
Lua:
function getGuildId(guildName)
    local resultId = db.storeQuery("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(guildName))
    if resultId == false then
        return false
    end

    local guildId = result.getNumber(resultId, "id")
    result.free(resultId)
    return guildId
end
Works perfectly, thanks!
 
Back
Top