/// <summary> /// 获取数据 /// </summary> /// <param name="tabName"></param> /// <param name="uid"></param> /// <param name="key"></param> /// <returns></returns> public string Get(string tabName, string uid, string key) { string strKey = tabName + "_" + uid + "_" + key; if (RedisUtility.KeyExist(strKey)) { return(RedisUtility.StringGet(strKey)); } var sqlParams = new MySqlParameter[] { new MySqlParameter("@openid", MySqlDbType.VarChar) { Value = uid }, }; var strsql = "select " + key + " from " + tabName + " where uid=@uid limit 1"; var dataset = MysqlUtility.ExecuteQuery(strsql, sqlParams); var obj = dataset.Tables[0].Rows[0][key].ToString(); if (obj != null) { logger.Warn("strKey: " + strKey + " obj: " + obj); RedisUtility.StringSet(strKey, obj, expireTime); } return(obj); }
/// <summary> /// 组合查询 Key:Type:Value nick:str:jarjin /// </summary> /// <returns></returns> public DataSet Query(string tabName, List <string> values = null, int rowCount = 0) { MySqlParameter[] sqlParams = null; var limitStr = string.Empty; if (rowCount > 0) { limitStr = " limit " + rowCount; } var strsql = "select * from " + tabName; if (values != null) { string valuestr = string.Empty; sqlParams = new MySqlParameter[values.Count]; for (int i = 0; i < values.Count; i++) { var strs = values[i].Split(':'); var valKey = "@value" + i; var dateType = GetDbType(strs[0]); var keyValues = strs[1].Split('='); sqlParams[i] = new MySqlParameter(valKey, dateType) { Value = keyValues[1] }; if (!string.IsNullOrEmpty(valuestr)) { valuestr += " and "; } valuestr += keyValues[0] + "=" + valKey; } strsql += " where " + valuestr; } strsql += limitStr; DataSet dataset = null; try { dataset = MysqlUtility.ExecuteQuery(strsql, sqlParams); } finally { logger.Info("strsql:" + strsql); } return(dataset); }
/// <summary> /// 存在一条记录 /// </summary> /// <param name="tabName"></param> /// <param name="uid"></param> /// <returns></returns> public DataSet Exist(string tabName, string uid) { var sqlParams = new MySqlParameter[] { new MySqlParameter("@uid", MySqlDbType.VarChar) { Value = uid }, }; var strsql = "select * from " + tabName + " where uid=@uid"; DataSet dataset = null; try { dataset = MysqlUtility.ExecuteQuery(strsql, sqlParams); } finally { logger.Info("strsql:" + strsql); } return(dataset); }