Jump to content

Database Coroutine Return Value


XiVirtue

Recommended Posts

function verileriAktar(sorgu, id)
    local cevap = dbPoll(sorgu, 0) -- since it's ready to poll, timeout is irrelevant and can be 0
    queries[id] = cevap
    print("poll")
    --return coroutine.resume(co[id], cevap)
end

function querydb(str,c)
    if str:find("DROP TABLE") then return end
  
    local id = getFreeID()
    co[id] = coroutine.create(function()

        cevap = dbQuery(verileriAktar,{id}, connection, str)
        coroutine.yield()
    end)    
    coroutine.resume(co[id])
    if coroutine.status(co[id]) ~= "dead" then
         if not coroutine.running() then
    return id
end
end
end



local id = querydb("SELECT * FROM `kayitlar` WHERE `KullaniciAdi`='mahlukat'")

print("querydb: "..tostring(id))
local result = getQueryResult(id)
print("queryresult: "..tostring(result))

Occurred

Debug Monitor ;

print("querydb: "..tostring(id))
print("queryresult: "..tostring(result))

print("poll")

 

I want

Debug Monitor ;

print("poll")

print("querydb: "..tostring(id))
print("queryresult: "..tostring(result))

I want the pool value before the return, So the pool is on top.

 

Edited by XiVirtue
fixs
Link to comment
  • Moderators

@XiVirtue

Every step of the query process have to be done inside of the coroutine function. And you cannot use two coroutines for one execution process.

 

 

Tip:

Functions blocks that are outside of the coroutine, but called from within the coroutine function block, are considered to be part of the coroutine.

It sound complicated, but it means that you can yield a coroutine from a different function, as long as it is part of the coroutine process.

 

 

Edited by IIYAMA
Link to comment
45 minutes ago, IIYAMA said:

@XiVirtue

Every step of the query process have to be done inside of the coroutine function. And you cannot use two coroutines for one execution process.

 

 

Tip:

Functions blocks that are outside of the coroutine, but called from within the coroutine function block, are considered to be part of the coroutine.

It sound complicated, but it means that you can yield a coroutine from a different function, as long as it is part of the coroutine process.

 

 

I'm a little confused. Can you help? So how do I do it?

Link to comment
  • Moderators
25 minutes ago, XiVirtue said:

I'm a little confused. Can you help? So how do I do it?

 



--
--
--
--
--
-- This block cannot be frozen!
--
--
--
--
--
co[id] = coroutine.create(function()
	
	-- This block can be frozen!!!!!!!!!!!!!!!!!!!!!!
    
	local id = querydb("SELECT * FROM `kayitlar` WHERE `KullaniciAdi`='mahlukat'")
	print("querydb: "..tostring(id))
    
	local result = getQueryResult(id)
	print("queryresult: "..tostring(result))

end)    
--
--
--
--
--
function querydb ()
	-- This block can be frozen!!!!!!!!!!!!!!!!!!!!!!
	coroutine.yield()
end

function getQueryResult ()
  	-- This block can be frozen!!!!!!!!!!!!!!!!!!!!!!
	coroutine.yield()
end

 

That way.

Link to comment
17 hours ago, IIYAMA said:

 



--
--
--
--
--
-- This block cannot be frozen!
--
--
--
--
--
co[id] = coroutine.create(function()
	
	-- This block can be frozen!!!!!!!!!!!!!!!!!!!!!!
    
	local id = querydb("SELECT * FROM `kayitlar` WHERE `KullaniciAdi`='mahlukat'")
	print("querydb: "..tostring(id))
    
	local result = getQueryResult(id)
	print("queryresult: "..tostring(result))

end)    
--
--
--
--
--
function querydb ()
	-- This block can be frozen!!!!!!!!!!!!!!!!!!!!!!
	coroutine.yield()
end

function getQueryResult ()
  	-- This block can be frozen!!!!!!!!!!!!!!!!!!!!!!
	coroutine.yield()
end

 

That way.

I'm doing this because the pool performs more than other functions, but I'm having trouble returning early

How do I use it when I export it and want to get it as a return value?

Example : exports.sql:querydb("SELECT * FROM `kayitlar` WHERE `KullaniciAdi`='mahlukat'")

 

Edited by XiVirtue
fix
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...