-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdatabase.lua
51 lines (39 loc) · 1.58 KB
/
database.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--[[
Copyright (C) 2019 Blue Mountains GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the Onset
Open Source License as published by Blue Mountains GmbH.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the Onset Open Source License for more details.
You should have received a copy of the Onset Open Source License along with this program. If not,
see https://bluemountains.io/Onset_OpenSourceSoftware_License.txt
]]--
sql = false
local SQL_HOST = "localhost"
local SQL_PORT = 3306
local SQL_USER = "root"
local SQL_PASS = ""
local SQL_DATA = "basic"
local SQL_CHAR = "utf8mb4"
local SQL_LOGL = "error"
-- Setup a MariaDB connection when the package/server starts
local function OnPackageStart()
mariadb_log(SQL_LOGL)
sql = mariadb_connect(SQL_HOST .. ':' .. SQL_PORT, SQL_USER, SQL_PASS, SQL_DATA)
if (sql ~= false) then
print("MariaDB: Connected to " .. SQL_HOST)
mariadb_set_charset(sql, SQL_CHAR)
else
print("MariaDB: Connection failed to " .. SQL_HOST .. ", see mariadb_log file")
-- Immediately stop the server if we cannot connect
ServerExit()
end
CallEvent("database:connected")
end
AddEvent("OnPackageStart", OnPackageStart)
-- Cleanup the MariaDB connection when the package/server stops
local function OnPackageStop()
mariadb_close(sql)
end
AddEvent("OnPackageStop", OnPackageStop)
-- ALTER TABLE log_chat ADD FOREIGN KEY (id) REFERENCES accounts (id) ON UPDATE CASCADE ON DELETE CASCADE;