local skynet = require "skynet" local mysqlproxy = require "shared.mysqlproxy" require "utils.CommonFunc" 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) 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(?, ?, ?)") skynet.error(string.format("addFriend!!!!!!!!!,%s,%s,%s",roleId, friendId, skynet.timex())) logdump(stmt_csp, '') 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 end function delFriend(roleId, friendId) local stmt_csp = mysqlproxy:prepare("call del_friends(?, ?)") skynet.error(string.format("delFriend!!!!!!!!!,%s,%s",roleId, friendId)) logdump(stmt_csp, '') 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 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 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"] end