Jump to content

Problem with "mysql_direct_query"


Recommended Posts

Hi all,

I have a problem with the new function "mysql_direct_query" of Lollo91, (for those not familiar) -> http://www.elitepvpers.com/forum/metin2-pserver-guides-strategies/3327940-release-mysql_direct_query-get_table_postfix-mysql_escape_string-written-c-lua.html

 

After implementing all in the source, I have this quest:

Spoiler

quest bantool begin
    state start begin
        when letter with pc.is_gm() begin
            send_letter("Ban-tool")
        end
        
        when button or info begin
            -- Tanto per sicurezza...
            if not pc.is_gm() then
                return
            end
            local menu = {"Ban player", "Remove ban", "Close"}
            say_title("Ban-tool")
            say("Select the function:[ENTER]")
            local s = select_table(menu)
            if s == table.getn(menu) then
                return
            end
            -- 
            local name
            repeat
                say_title(menu)
                say("Insert name of player:[ENTER]")
                name = input()
                if name == "" then
                    say("The name you entered is invalid.[ENTER]")
                    return
                end
                say_title(menu)
                say_reward("You have entered: "..name)
                say("Are you sure you want to continue?[ENTER]")
                local a = select("Yes", "No, repeat", "Cancel")
                if a == 3 then
                    return
                elseif a == 1 then
                    break
                end
            until false
            say_title(menu)
            -- 
            local result, query_result = mysql_direct_query("SELECT player.account_id FROM player.player WHERE player.name='"..name.."' limit 1;")
            -- Controllo errori
            if result != 0 then
                say("There was an error.")
                say("Description of error:")
                say_reward(query_result)
                return            
            end
            local AccStatus = {"BLOCK","OK"}
            -- 
            local AccID = tonumber(query_result[1][1])
            --
            if AccID == nil then
                say("The player does not exist.[ENTER]")
                return
            end            
            -- Ban/sban player
            result, query_result = mysql_direct_query("UPDATE account.account SET account.status='"..AccStatus.."' WHERE account.id='"..AccID.."' limit 1;")
            -- Controllo errori
            if result != 0 then
                say("There was an error.")
                say("Description of error:")
                say_reward(query_result)
                return
            end    
            say("Successfully completed operation![ENTER]")
        end
    end
end

 

The problem is this:

                say("There was an error.")
                say("Description of error:")
Why the query does not work?


Thank you!

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Honorable Member
5 hours ago, Suainzettello said:

Fai un esempio con la quest per favore :)

local query = string.format("SELECT account_id FROM player%s WHERE name='%s' limit 1;", get_table_postfix(), mysql_escape_string(pc.get_name()))
syschat(query)
local aff_result, query_result = mysql_direct_query(query)
syschat(aff_result)
syschat(aff_result==1 and query_result[1].account_id or "NONE")

This example should suffice

5BQu983.png

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.