Skip to content

Commit

Permalink
Merge pull request #70 from solareon/fix-sql-2
Browse files Browse the repository at this point in the history
  • Loading branch information
FjamZoo authored Aug 29, 2024
2 parents a4ae67d + 39d0566 commit 859ebba
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ CreateThread(function()
end
end
local jobs, gangs = GetFrameworkGroups()
local query = {}
local function addCachedAccount(group)
cachedAccounts[group] = {
id = group,
Expand All @@ -41,9 +42,8 @@ CreateThread(function()
auth = {},
creator = nil
}
MySQL.insert("INSERT INTO bank_accounts_new (id, amount, transactions, auth, isFrozen, creator) VALUES (?, ?, ?, ?, ?, NULL) ",{
group, cachedAccounts[group].amount, json.encode(cachedAccounts[group].transactions), json.encode({}), cachedAccounts[group].frozen
})
query[#query + 1] = {"INSERT INTO bank_accounts_new (id, amount, transactions, auth, isFrozen, creator) VALUES (?, ?, ?, ?, ?, NULL) ",
{ group, cachedAccounts[group].amount, json.encode(cachedAccounts[group].transactions), json.encode({}), cachedAccounts[group].frozen }}
end
for job in pairs(jobs) do
if not cachedAccounts[job] then
Expand All @@ -55,6 +55,9 @@ CreateThread(function()
addCachedAccount(gang)
end
end
if #query >= 1 then
MySQL.transaction.await(query)
end
end)

function UpdatePlayerAccount(cid)
Expand Down Expand Up @@ -660,21 +663,9 @@ function ExportHandler(resource, name, cb)
end)
end

MySQL.query.await([=[
CREATE TABLE IF NOT EXISTS `bank_accounts_new` (
`id` varchar(50) NOT NULL,
`amount` int(11) DEFAULT 0,
`transactions` longtext DEFAULT '[]',
`auth` longtext DEFAULT '[]',
`isFrozen` int(11) DEFAULT 0,
`creator` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE IF NOT EXISTS `player_transactions` (
`id` varchar(50) NOT NULL,
`isFrozen` int(11) DEFAULT 0,
`transactions` longtext DEFAULT '[]',
PRIMARY KEY (`id`)
);
]=])
local createTables = {
{ query = "CREATE TABLE IF NOT EXISTS `bank_accounts_new` (`id` varchar(50) NOT NULL, `amount` int(11) DEFAULT 0, `transactions` longtext DEFAULT '[]', `auth` longtext DEFAULT '[]', `isFrozen` int(11) DEFAULT 0, `creator` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`));", values = nil },
{ query = "CREATE TABLE IF NOT EXISTS `player_transactions` (`id` varchar(50) NOT NULL, `isFrozen` int(11) DEFAULT 0, `transactions` longtext DEFAULT '[]', PRIMARY KEY (`id`));", values = nil }
}

assert(MySQL.transaction.await(createTables), "Failed to create tables")

0 comments on commit 859ebba

Please sign in to comment.