Exemplo n.º 1
0
        public void Dictionary2Where()
        {
            Dictionary2Where             dict2where = new Dictionary2Where();
            IDictionary <string, object> dict       = new Dictionary <string, object>();

            dict.Add("col1$>=", 1);
            dict.Add("col2", new List <object>()
            {
                2, 3
            });

            dict2where.parse(dict);

            Assert.AreEqual(" where 1=1 and col1>=@col1 and col2 in(@col2_0, @col2_1)", dict2where.AsSql(), "sql assert");
            Assert.AreEqual(2, dict2where.GetSqlParameterValues()[1], "id assert");
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pDic"></param>
        /// <returns></returns>
        public DataTable GetGsMessage(IDictionary <string, object> pDic, int wxType)
        {
            if (pDic == null || pDic.Count == 0)
            {
                return(GetGsMessage(string.Empty, wxType));
            }
            var tableN = wxType == 1 ? TABLE_NAME_MP : TABLE_NAME_QY;
            //生成where条件字句
            Dictionary2Where pOper = new Dictionary2Where();

            pOper.parse(pDic);
            string strFilter = pOper.AsSql();

            string[] pPara  = pOper.ParameterNames.Select(p => "@" + p).ToArray();
            object[] pValue = pOper.ParameterValues.ToArray();
            //查询SQL
            string strSql = string.Format("select * from {0} {1} order by {2} desc", tableN, strFilter, FIELD_NAME_MTIME);

            return(template.Query(strSql, pPara, pValue, null));
        }