Skip to content

Commit

Permalink
Fixed transactions not working in mysqloolib
Browse files Browse the repository at this point in the history
  • Loading branch information
FredyH committed Nov 18, 2021
1 parent 6916f87 commit c0547be
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lua/mysqloolib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ local dbMetatable = {__index = function(tbl, key)
return (db[key] or baseMeta[key])
end}

//This converts an already existing database instance to be able to make use
//of the easier functionality provided by mysqloo.CreateDatabase
--This converts an already existing database instance to be able to make use
--of the easier functionality provided by mysqloo.CreateDatabase
function mysqloo.ConvertDatabase(database)
return setmetatable(database, dbMetatable)
end

//The same as mysqloo.connect() but adds easier functionality
--The same as mysqloo.connect() but adds easier functionality
function mysqloo.CreateDatabase(...)
local db = mysqloo.connect(...)
db:connect()
Expand Down Expand Up @@ -158,8 +158,8 @@ local function setPreparedQueryArguments(query, values)
["number"] = function(query, index, value) query:setNumber(index, value) end,
["boolean"] = function(query, index, value) query:setBoolean(index, value) end,
}
//This has to be pairs instead of ipairs
//because nil is allowed as value
--This has to be pairs instead of ipairs
--because nil is allowed as value
for k, v in pairs(values) do
local varType = type(v)
if (typeFunctions[varType]) then
Expand All @@ -180,10 +180,13 @@ function db:PrepareQuery(str, values, callback, ...)
end

local transaction = {}
local transactionMT = {__index = transaction}
local baseTransactionMeta = FindMetaTable("MySQLOO Transaction") or {} -- this ensures backwards compatibility to <=9.6
local transactionMT = {__index = function(tbl, key)
return (transaction[key] or baseTransactionMeta[key])
end}

function transaction:Prepare(str, values)
//TODO: Cache queries
--TODO: Cache queries
local preparedQuery = self._db:prepare(str)
setPreparedQueryArguments(preparedQuery, values)
self:addQuery(preparedQuery)
Expand Down Expand Up @@ -223,4 +226,4 @@ function db:CreateTransaction()
transaction._db = self
setmetatable(transaction, transactionMT)
return transaction
end
end

0 comments on commit c0547be

Please sign in to comment.