Advertisement
Evers

Untitled

Dec 14th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. SCRIPT ERROR: @gcphone/server/addons.lua:121: attempt to index a nil value (local 'identity')
  2. > ref (@gcphone/server/addons.lua:121)
  3. > finish (@vrp/lib/utils.lua:43)
  4. > task (@vrp/lib/utils.lua:47)
  5. > cb (@vrp/modules/identity.lua:44)
  6. > handler (- begin MySQL module
  7. local MySQL = {}
  8.  
  9. MySQL.debug = false
  10. local dpaths = {}
  11.  
  12. local tasks = {}
  13.  
  14. --[[
  15. local function tick()
  16. SetTimeout(1, function() -- protect errors from breaking the loop
  17. SetTimeout(1000, tick)
  18.  
  19. local rmtasks = {}
  20. for id,cb in pairs(tasks) do
  21. local r = exports.vrp_mysql:checkTask(id)
  22. if r.status == 1 then
  23. cb(r.rows,r.affected) -- rows, affected
  24. table.insert(rmtasks, id)
  25. elseif r.status == -1 then
  26. print("[vRP] task "..id.." failed.")
  27. table.insert(rmtasks, id)
  28. end
  29. end
  30.  
  31. -- remove done tasks
  32. for k,v in pairs(rmtasks) do
  33. tasks[v] = nil
  34. end
  35. end)
  36. end
  37. tick()
  38. --]]
  39.  
  40. AddEventHandler("vRP:MySQL_task", function(task_id, data)
  41. -- print("vRP:MySQL_task "..task_id)
  42. local cb = tasks[task_id]
  43. if data.status == 1 then
  44. if cb then
  45. if data.mode == 0 then
  46. cb(data.affected or 0)
  47. elseif data.mode == 1 then
  48. cb(data.scalar or 0)
  49. elseif data.mode == 2 then
  50. cb(data.rows or {}, data.affected or 0) -- rows, affected
  51. end
  52. end
  53. elseif data.status == -1 then
  54. print("[vRP] task "..task_id.." failed.")
  55. end
  56.  
  57. tasks[task_id] = nil
  58.  
  59. if MySQL.debug and dpaths[task_id] then
  60. print("[vRP] MySQL end query "..dpaths[task_id].." ("..task_id..")")
  61. dpaths[task_id] = nil
  62. end
  63. end)
  64.  
  65. local task_id = -1
  66. AddEventHandler("vRP:MySQL_taskid", function(_task_id)
  67. -- print("vRP:MySQL_taskid ".._task_id)
  68. task_id = _task_id
  69. end)
  70.  
  71. -- host can be "host" or "host:port"
  72. function MySQL.createConnection(name,host,user,password,db,debug)
  73. -- print("[vRP] try to create connection "..name)
  74. -- parse port in host as "ip:port"
  75. local host_parts = splitString(host,":")
  76. if #host_parts >= 2 then
  77. host = host_parts[1]..";port="..host_parts[2]
  78. end
  79.  
  80. local config = "server="..host..";uid="..user..";pwd="..password..";database="..db..";"
  81.  
  82. -- TriggerEvent("vRP:MySQL:createConnection", name, config)
  83. exports.vrp_mysql:createConnection(name, config)
  84. end
  85.  
  86. function MySQL.createCommand(path, query)
  87. -- print("[vRP] try to create command "..path)
  88. -- TriggerEvent("vRP:MySQL:createCommand", path, query)
  89. exports.vrp_mysql:createCommand(path, query)
  90. end
  91.  
  92. -- generic query
  93. function MySQL._query(path, args, mode, cb)
  94. -- TriggerEvent("vRP:MySQL:query", path, args)
  95. if not (type(args) == "table") then
  96. args = {}
  97. end
  98.  
  99. -- force args to be a C# dictionary
  100. args._none = " "
  101.  
  102. -- exports.vrp_mysql:query(path, args)
  103. -- print("[vRP] try to query "..path.." id "..task_id)
  104. TriggerEvent("vRP:MySQL_query", path, args, mode)
  105. if MySQL.debug then
  106. print("[vRP] MySQL begin query (m"..mode..") "..path.." ("..task_id..")")
  107. dpaths[task_id] = path
  108. end
  109.  
  110. tasks[task_id] = cb
  111. end
  112.  
  113. -- do a query (multiple rows)
  114. --- cb(rows, affected)
  115. function MySQL.query(path, args, cb)
  116. MySQL._query(path, args, 2, cb)
  117. end
  118.  
  119. -- do a scalar query (one row, one column)
  120. --- cb(scalar)
  121. function MySQL.scalar(path, args, cb)
  122. MySQL._query(path, args, 1, cb)
  123. end
  124.  
  125. -- do a execute query (no results)
  126. --- cb(affected)
  127. function MySQL.execute(path, args, cb)
  128. MySQL._query(path, args, 0, cb)
  129. end
  130.  
  131. -- return module
  132. return MySQL
  133. :45)
  134. > void vRP.MySQL.e_tick() (@vrp_mysql/mysql.net.dll:0)
  135. > fn (@vrp_mysql/init.lua:3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement