XiVirtue

Database Coroutine Return Value

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

Share this post


Link to post

@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

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.