Skip to content

Instantly share code, notes, and snippets.

Created January 18, 2017 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/863806a7968924630f54ee5999d284af to your computer and use it in GitHub Desktop.
Save anonymous/863806a7968924630f54ee5999d284af to your computer and use it in GitHub Desktop.
-- The point of this script is to block the main thread until a query has finished.
-- It does not work and will crash your server.
local co = coroutine.create(function ()
require("mysqloo")
local db = mysqloo.connect("hostname", "database", "password", "table")
function db:onConnectionFailed(err)
print("Database connection error: ", err)
end
function db:onConnected()
print("Database connection established.")
end
print("Connecting to database...")
db:connect()
db:wait() -- halt until connected
local query = db:query("SELECT version()")
query:start()
while query:status() ~= mysqloo.QUERY_COMPLETE do
coroutine.yield()
end
coroutine.yield(query:getData())
end)
while coroutine.status(co) ~= "dead" do
local err, data = coroutine.resume(co)
if arg ~= nil then PrintTable(data) end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment