Blame view

src/utils/MysqlUtil.lua 2.54 KB
913e070e   liuzujun   添加订单表,全局id定时回写数据库
1
2
  local skynet = require "skynet"
  local mysqlproxy = require "shared.mysqlproxy"
0d2111f2   liuzujun   好友添加排错日志
3
  require "utils.CommonFunc"
913e070e   liuzujun   添加订单表,全局id定时回写数据库
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  
  
  function getDbCfgVal(tbName, keyName, fieldName)
      local sql = string.format("SELECT * FROM `%s` WHERE `key` = '%s';", tbName, keyName)
      local res = mysqlproxy:query(sql)
      if not next(res) or res.errno then
          return
      end
  
      return res[1][fieldName]
  end
  
  function setDbCfgVal(tbName, keyName, fieldName, fieldVal)
      if type(fieldVal) == "string" then fieldVal = string.format("'%s'", fieldVal) end
      local sql = string.format("UPDATE `%s` SET `%s` = %s WHERE `key` = '%s';", tbName, fieldName, fieldVal, keyName)
      mysqlproxy:query(sql)
6136eaca   liuzujun   添加好友表
20
21
22
23
24
25
26
27
28
29
30
31
32
  end
  
  function getFriendCount(roleId)
      local res = mysqlproxy:query(string.format("SELECT `id` FROM `Friend` WHERE `roleid` = %s", roleId))
      if res["errno"] then
          return globalCsv.friendListLimit
      end
  
      return #res
  end
  
  function addFriend(roleId, friendId)
  	local stmt_csp = mysqlproxy:prepare("call add_friends(?, ?, ?)")
3a0c3140   liuzujun   关闭prepare stmt
33
      --logdump(stmt_csp, '')
6136eaca   liuzujun   添加好友表
34
35
36
37
38
      local r = mysqlproxy:execute(stmt_csp, roleId, friendId, skynet.timex())
      if r[1][1]["t_error"] == 0 then
  		rpcRole(roleId, "addFriend", friendId)
  		rpcRole(friendId, "addFriend", roleId)
      end
3a0c3140   liuzujun   关闭prepare stmt
39
      mysqlproxy:stmt_close(stmt_csp)
6136eaca   liuzujun   添加好友表
40
41
42
43
  end
  
  function delFriend(roleId, friendId)
  	local stmt_csp = mysqlproxy:prepare("call del_friends(?, ?)")
3a0c3140   liuzujun   关闭prepare stmt
44
      --logdump(stmt_csp, '')
6136eaca   liuzujun   添加好友表
45
46
47
48
49
      local r = mysqlproxy:execute(stmt_csp, roleId, friendId)
      if r[1][1]["t_error"] == 0 then
  		rpcRole(roleId, "delFriend", friendId)
  		rpcRole(friendId, "delFriend", roleId)
      end
3a0c3140   liuzujun   关闭prepare stmt
50
      mysqlproxy:stmt_close(stmt_csp)
6136eaca   liuzujun   添加好友表
51
52
53
  end
  
  function roleExists(roleId)
7356e583   zhangqijia   feat: 增加角色注销协议
54
      local res = mysqlproxy:query(string.format("SELECT `id` FROM `Role` WHERE `del` = 0 and `id` = %s", roleId))
6136eaca   liuzujun   添加好友表
55
56
57
58
59
      if res["errno"] or not next(res) then
          return false
      end
  
      return true
01be2d78   liuzujun   修改mysql链接断开重连的bug
60
61
62
  end
  
  function roleUidExists(uid)
7356e583   zhangqijia   feat: 增加角色注销协议
63
      local res = mysqlproxy:query(string.format("SELECT `name` FROM `Role` WHERE `del` = 0 and `uid` = '%s'", uid))
01be2d78   liuzujun   修改mysql链接断开重连的bug
64
65
66
67
68
      if res["errno"] or not next(res) then
          return false
      end
  
      return true, res[1]["name"]
7356e583   zhangqijia   feat: 增加角色注销协议
69
70
71
72
73
74
75
76
  end
  
  function roleUnRegister(roleId)
      local res = mysqlproxy:query(string.format("UPDATE`Role` SET `del` = 1 WHERE `id` = %s", roleId))
      if res["errno"] or not next(res) then
          return false
      end
      return true
ae3753b1   zhangqijia   feat: 增加 role_by_...
77
78
79
  end
  
  function roleByUid(uid)
60793192   zhangqijia   fix: roleByUid 多了`,`
80
      local res = mysqlproxy:query(string.format("SELECT id, name, level FROM `Role` WHERE `del` = 0 and `uid` = '%s'", uid))
ae3753b1   zhangqijia   feat: 增加 role_by_...
81
82
83
84
      if res["errno"] or not next(res) then
          return false
      end
      return true, res[1]
913e070e   liuzujun   添加订单表,全局id定时回写数据库
85
  end