Exemple #1
0
        /// <summary>
        /// 判断是否存在
        /// </summary>
        public static bool Has(this MySqlConnection conn, ZinSQL sql)
        {
            var fields = sql.GetFields();
            var count  = conn.ExecuteScalar(string.Format("select COUNT({1}) from {0} where {2} = {3}", sql.TableName, fields, fields, sql.GetValues()));

            return(Convert.ToInt32(count) > 0);
        }
Exemple #2
0
        /// <summary>
        /// 计数
        /// </summary>
        public static int Count(this MySqlConnection conn, ZinSQL sql, List <MySqlParameter> paramList)
        {
            var sqlStr = string.Empty;

            if (string.IsNullOrEmpty(sql.Where))
            {
                sqlStr = string.Format("select count({1}) from {0}", sql.TableName, sql.GetFields());
            }
            else
            {
                sqlStr = string.Format("select count({1}) from {0} where {2}", sql.TableName, sql.GetFields(), sql.Where);
            }

            return(conn.ExecuteScalar(sqlStr, paramList).ToInt());
        }
Exemple #3
0
        /// <summary>
        /// 获取
        /// </summary>
        public static List <object[]> Get(this MySqlConnection conn, ZinSQL sql, List <MySqlParameter> paramList)
        {
            var sqlStr = string.Empty;

            if (string.IsNullOrEmpty(sql.Where))
            {
                sqlStr = string.Format("select {1} from {0}", sql.TableName, sql.GetFields());
            }
            else
            {
                sqlStr = string.Format("select {1} from {0} where {2}", sql.TableName, sql.GetFields(), sql.Where);
            }

            return(conn.ExecuteQuery(sqlStr, paramList));
        }
Exemple #4
0
 /// <summary>
 /// 插入信息
 /// </summary>
 public static void Insert(this MySqlConnection conn, ZinSQL sql, List <MySqlParameter> paramList)
 {
     conn.ExecuteNonQuery(string.Format("insert into {0}({1}) values({2})", sql.TableName, sql.GetFields(), sql.GetValues()), paramList);
 }
Exemple #5
0
 public static object GetScalarResult(this MySqlConnection conn, ZinSQL sql, List <MySqlParameter> paramList)
 {
     if (string.IsNullOrEmpty(sql.Where))
     {
         return(conn.ExecuteScalar(string.Format("select {1} from {0}", sql.TableName, sql.GetFields()), paramList));
     }
     else
     {
         return(conn.ExecuteScalar(string.Format("select {1} from {0} where {2}", sql.TableName, sql.GetFields(), sql.Where), paramList));
     }
 }