Jump to content

dbPoll?


GTX

Recommended Posts

Hello, I'm making a 'custom' poll function. I have problem with return thingy...

So, code looks like:

  
function poll(resultid) 
    local result, num_affected_rows, errmsg = dbPoll(resultPool[resultid], -1) 
    if not result then 
        outputDebugString("Error: "..errmsg) 
        return false 
    end 
    local resulta = {} 
    for result, row in pairs(result) do 
        for column, value in pairs(row) do 
            resulta[column] = value 
        end 
    end 
    return resulta, num_affected_rows 
end 
  

Everything is fine. But now, here comes the problem. It returns only 1 row. So, my query looks like that:

  
local query = exports.mysql:query("SELECT * FROM characters WHERE account='"..accID.."'") 
  

This query selects 2 rows. But when I use dbPoll, it returns only 1! I want it to return ALL selected rows.

Thanks in advance.

Link to comment
    local resulta = {} 
    for result, row in pairs(result) do 
        for column, value in pairs(row) do 
            resulta[column] = value 
        end 
    end 

What is that for? "result" already returns a table like this:

column: value

function poll(resultid) 
    local result, num_affected_rows, errmsg = dbPoll(resultPool[resultid], -1) 
    if ( not result ) then 
        outputDebugString("Error: "..errmsg) 
        return false 
    end 
  
    return result, num_affected_rows 
end 

Try that.

Link to comment

I don't want to send it directly. Currently, I am getting values like:

  
local result, affected = exports.mysql:poll(query) 
outputChatBox(result["id"]) 
  

I don't want to change the whole gamemode for that...

Link to comment

And this is the query?

local query = exports.mysql:query("SELECT * FROM characters WHERE account='"..accID.."'") 

If so, then try this:

local query = exports.mysql:query("SELECT * FROM characters WHERE account='"..accID.."'") 
local result, affected = exports.mysql:poll(query) 
for _, char in ipairs ( result ) do 
outputChatBox ( char [ "id" ] ) 
end 

Link to comment

No... Look, I've got a problem in returning a table... For example: I've got 2 rows and I select them with query. Then when I want to use exports.mysql:poll, this returns only 1 row, but it must return 2 rows.

Row #1: abc

Row #2: def

outputChatBox(result["id"]) --> def

Is it possible to return 2 times?...

Link to comment

You can use this:

function poll(resultid) 
    local result, num_affected_rows, errmsg = dbPoll(resultPool[resultid], -1) 
    if ( not result ) then 
        outputDebugString("Error: "..errmsg) 
        return false 
    end 
  
    return result, num_affected_rows 
end 

Then on your script:

local query = exports.mysql:query("SELECT * FROM characters WHERE account='"..accID.."'") 
local result, affected = exports.mysql:poll(query) 
outputChatBox ( result [ 1 ] [ "id" ] ) 
outputChatBox ( result [ 2 ] [ "id" ] ) 

Link to comment

It doesn't work. No errors. No outputs;

  
local query = mysql:query("SELECT * FROM characters WHERE account='"..accID.."'") 
if query then 
    local result, num_affected_rows = mysql:poll(query) 
    if num_affected_rows > 0 then 
        outputChatBox(result[1]["charactername"]) 
    end 
end 
  

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