Fix shared DataStore bug

This commit is contained in:
Jérémie N'gadi
2017-08-08 19:13:58 +02:00
parent 8a2715535a
commit 4e9b529b4c
2 changed files with 19 additions and 7 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ CREATE TABLE `datastore` (
CREATE TABLE `datastore_data` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`owner` varchar(255) NOT NULL,
`owner` varchar(255),
`data` longtext,
PRIMARY KEY (`id`)
);
+18 -6
View File
@@ -2,7 +2,7 @@ ESX = nil
Items = {}
local DataStoresIndex = {}
local DataStores = {}
local SharedDatastores = {}
local SharedDataStores = {}
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
@@ -44,13 +44,25 @@ AddEventHandler('onMySQLReady', function()
else
local items = {}
local data = nil
local storeName = result2[1].name
local storeData = (result2[1].data == nil and {} or json.decode(result2[1].data))
if #result2 == 0 then
local dataStore = CreateDataStore(storeName, nil, storeData)
SharedDatastores[name] = dataStore
MySQL.Sync.execute(
'INSERT INTO datastore_data (name, owner, data) VALUES (@name, NULL, \'{}\')',
{
['@name'] = name,
}
)
data = {}
else
data = json.decode(result2[1].data)
end
local dataStore = CreateDataStore(name, nil, data)
SharedDataStores[name] = dataStore
end