Blame view

src/utils/MysqlUtil.lua 1.92 KB
913e070e   liuzujun   添加订单表,全局id定时回写数据库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  local skynet = require "skynet"
  local mysqlproxy = require "shared.mysqlproxy"
  
  
  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   添加好友表
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
52
53
54
55
56
  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(?, ?, ?)")
      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
      dump(r)
  end
  
  function delFriend(roleId, friendId)
  	local stmt_csp = mysqlproxy:prepare("call del_friends(?, ?)")
      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
      dump(r)
  end
  
  function roleExists(roleId)
      local res = mysqlproxy:query(string.format("SELECT `id` FROM `Role` WHERE `id` = %s", roleId))
      if res["errno"] or not next(res) then
          return false
      end
  
      return true
01be2d78   liuzujun   修改mysql链接断开重连的bug
57
58
59
60
61
62
63
64
65
  end
  
  function roleUidExists(uid)
      local res = mysqlproxy:query(string.format("SELECT `name` FROM `Role` WHERE `uid` = %s", uid))
      if res["errno"] or not next(res) then
          return false
      end
  
      return true, res[1]["name"]
913e070e   liuzujun   添加订单表,全局id定时回写数据库
66
  end